diff options
Diffstat (limited to 'packages/main/src/index.ts')
-rw-r--r-- | packages/main/src/index.ts | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index 0978cd9..bcdc3d7 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts | |||
@@ -36,7 +36,7 @@ import { | |||
36 | import { app, BrowserView, BrowserWindow, ipcMain } from 'electron'; | 36 | import { app, BrowserView, BrowserWindow, ipcMain } from 'electron'; |
37 | import { ensureDirSync, readFile, readFileSync } from 'fs-extra'; | 37 | import { ensureDirSync, readFile, readFileSync } from 'fs-extra'; |
38 | import { autorun } from 'mobx'; | 38 | import { autorun } from 'mobx'; |
39 | import { getSnapshot, onPatch } from 'mobx-state-tree'; | 39 | import { getSnapshot, onAction, onPatch } from 'mobx-state-tree'; |
40 | import osName from 'os-name'; | 40 | import osName from 'os-name'; |
41 | 41 | ||
42 | import { | 42 | import { |
@@ -292,9 +292,23 @@ async function createWindow(): Promise<unknown> { | |||
292 | } | 292 | } |
293 | }); | 293 | }); |
294 | 294 | ||
295 | const batchedPatches: unknown[] = []; | ||
295 | onPatch(store.shared, (patch) => { | 296 | onPatch(store.shared, (patch) => { |
296 | webContents.send(MainToRendererIpcMessage.SharedStorePatch, patch); | 297 | batchedPatches.push(patch); |
297 | }); | 298 | }); |
299 | onAction( | ||
300 | store, | ||
301 | () => { | ||
302 | if (batchedPatches.length > 0) { | ||
303 | webContents.send( | ||
304 | MainToRendererIpcMessage.SharedStorePatch, | ||
305 | batchedPatches, | ||
306 | ); | ||
307 | batchedPatches.splice(0); | ||
308 | } | ||
309 | }, | ||
310 | true, | ||
311 | ); | ||
298 | 312 | ||
299 | ipcMain.handle(ServiceToMainIpcMessage.ApiExposedInMainWorld, (event) => { | 313 | ipcMain.handle(ServiceToMainIpcMessage.ApiExposedInMainWorld, (event) => { |
300 | if (event.sender.id !== browserView.webContents.id) { | 314 | if (event.sender.id !== browserView.webContents.id) { |