aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/devTools.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-23 13:40:47 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-23 15:48:30 +0100
commit950fb9be8061e2a26e0536b98c6a3ee230618f54 (patch)
treeb136dcc9add0d268a2e7a6288ec934a86d03b652 /packages/main/src/devTools.ts
parentfeat: Add shared package for electron ipc (diff)
downloadsophie-950fb9be8061e2a26e0536b98c6a3ee230618f54.tar.gz
sophie-950fb9be8061e2a26e0536b98c6a3ee230618f54.tar.zst
sophie-950fb9be8061e2a26e0536b98c6a3ee230618f54.zip
feat: Main to renderer store synchronization
Patches are send in one direction only, from the main to the renderer, so all actions have to go through the context bridge and the renderer IPC to modify the store in the renderer. This makes the store in the main process a single source of truth, which simplifies debugging and state persistence. The store in the renderer is connected to redux devtools for inspection, but playing back the state in the devtools won't change the sotre in main process.
Diffstat (limited to 'packages/main/src/devTools.ts')
-rw-r--r--packages/main/src/devTools.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/packages/main/src/devTools.ts b/packages/main/src/devTools.ts
new file mode 100644
index 0000000..d02bfbf
--- /dev/null
+++ b/packages/main/src/devTools.ts
@@ -0,0 +1,49 @@
1import type { App, BrowserWindow } from 'electron';
2
3/**
4 * Installs the react and redux developer tools extensions.
5 *
6 * We use the redux devtools and connect the mobx store to it with `mst-middlewares`,
7 * because the mobx-state-tree devtools are currently unmaintained.
8 *
9 * @param app The electron application instance.
10 */
11export function installDevToolsExtensions(app: App): void {
12 app.whenReady().then(async () => {
13 const {
14 default: installExtension,
15 REACT_DEVELOPER_TOOLS,
16 REDUX_DEVTOOLS,
17 } = await import('electron-devtools-installer');
18 installExtension(
19 [
20 REACT_DEVELOPER_TOOLS,
21 REDUX_DEVTOOLS,
22 ],
23 {
24 forceDownload: false,
25 loadExtensionOptions: {
26 allowFileAccess: true,
27 },
28 },
29 );
30 }).catch((err) => {
31 console.error('Failed to install devtools extension', err);
32 });
33}
34
35/**
36 * Opens the developer tools while applying a workaround to enable the redux devtools.
37 *
38 * @param browserWindow The browser window to open the devtools in.
39 * @see https://github.com/MarshallOfSound/electron-devtools-installer/issues/195#issuecomment-998872878
40 */
41export function openDevToolsWhenReady(browserWindow: BrowserWindow): void {
42 const { webContents } = browserWindow;
43 webContents.once('dom-ready', () => {
44 webContents.once('devtools-opened', () => {
45 browserWindow?.focus();
46 });
47 webContents.openDevTools();
48 });
49}