diff options
Diffstat (limited to 'packages/renderer/src/stores')
-rw-r--r-- | packages/renderer/src/stores/RendererEnv.ts | 4 | ||||
-rw-r--r-- | packages/renderer/src/stores/RendererStore.ts | 25 |
2 files changed, 18 insertions, 11 deletions
diff --git a/packages/renderer/src/stores/RendererEnv.ts b/packages/renderer/src/stores/RendererEnv.ts index f2ec519..d687738 100644 --- a/packages/renderer/src/stores/RendererEnv.ts +++ b/packages/renderer/src/stores/RendererEnv.ts | |||
@@ -19,10 +19,10 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { getEnv as getAnyEnv, IAnyStateTreeNode } from 'mobx-state-tree'; | 21 | import { getEnv as getAnyEnv, IAnyStateTreeNode } from 'mobx-state-tree'; |
22 | import type { SophieRenderer } from '@sophie/shared'; | 22 | import type { Action } from '@sophie/shared'; |
23 | 23 | ||
24 | export interface RendererEnv { | 24 | export interface RendererEnv { |
25 | ipc: Omit<SophieRenderer, 'setSharedStoreListener'>; | 25 | dispatchMainAction(action: Action): void; |
26 | } | 26 | } |
27 | 27 | ||
28 | /** | 28 | /** |
diff --git a/packages/renderer/src/stores/RendererStore.ts b/packages/renderer/src/stores/RendererStore.ts index 001f23a..3de82ac 100644 --- a/packages/renderer/src/stores/RendererStore.ts +++ b/packages/renderer/src/stores/RendererStore.ts | |||
@@ -31,16 +31,22 @@ import { | |||
31 | ThemeSource, | 31 | ThemeSource, |
32 | } from '@sophie/shared'; | 32 | } from '@sophie/shared'; |
33 | 33 | ||
34 | import { getEnv } from './RendererEnv'; | 34 | import { getEnv, RendererEnv } from './RendererEnv'; |
35 | 35 | ||
36 | export const rendererStore = types.model('RendererStore', { | 36 | export const rendererStore = types.model('RendererStore', { |
37 | shared: types.optional(sharedStore, {}), | 37 | shared: types.optional(sharedStore, {}), |
38 | }).actions((self) => ({ | 38 | }).actions((self) => ({ |
39 | setBrowserViewBounds(bounds: BrowserViewBounds) { | 39 | setBrowserViewBounds(browserViewBounds: BrowserViewBounds) { |
40 | getEnv(self).ipc.setBrowserViewBounds(bounds); | 40 | getEnv(self).dispatchMainAction({ |
41 | action: 'set-browser-view-bounds', | ||
42 | browserViewBounds, | ||
43 | }); | ||
41 | }, | 44 | }, |
42 | setThemeSource(mode: ThemeSource) { | 45 | setThemeSource(themeSource: ThemeSource) { |
43 | getEnv(self).ipc.setThemeSource(mode); | 46 | getEnv(self).dispatchMainAction({ |
47 | action: 'set-theme-source', | ||
48 | themeSource, | ||
49 | }); | ||
44 | }, | 50 | }, |
45 | toggleDarkMode() { | 51 | toggleDarkMode() { |
46 | if (self.shared.shouldUseDarkColors) { | 52 | if (self.shared.shouldUseDarkColors) { |
@@ -62,11 +68,12 @@ export interface RendererStore extends Instance<typeof rendererStore> {} | |||
62 | * @param ipc The `sophieRenderer` context bridge. | 68 | * @param ipc The `sophieRenderer` context bridge. |
63 | */ | 69 | */ |
64 | export function createAndConnectRendererStore(ipc: SophieRenderer): RendererStore { | 70 | export function createAndConnectRendererStore(ipc: SophieRenderer): RendererStore { |
65 | const store = rendererStore.create({}, { | 71 | const env: RendererEnv = { |
66 | ipc, | 72 | dispatchMainAction: ipc.dispatchAction, |
67 | }); | 73 | } |
74 | const store = rendererStore.create({}, env); | ||
68 | 75 | ||
69 | ipc.setSharedStoreListener({ | 76 | ipc.onSharedStoreChange({ |
70 | onSnapshot(snapshot) { | 77 | onSnapshot(snapshot) { |
71 | applySnapshot(store.shared, snapshot); | 78 | applySnapshot(store.shared, snapshot); |
72 | }, | 79 | }, |