diff options
-rw-r--r-- | packages/main/src/stores/MainStore.ts | 13 | ||||
-rw-r--r-- | packages/main/src/stores/SharedStore.ts | 4 | ||||
-rw-r--r-- | packages/renderer/src/stores/RootStore.ts | 7 | ||||
-rw-r--r-- | packages/shared/src/index.ts | 4 | ||||
-rw-r--r-- | packages/shared/src/stores/Config.ts | 8 | ||||
-rw-r--r-- | packages/shared/src/stores/SharedStore.ts | 10 |
6 files changed, 16 insertions, 30 deletions
diff --git a/packages/main/src/stores/MainStore.ts b/packages/main/src/stores/MainStore.ts index 4b85c22..bab03c2 100644 --- a/packages/main/src/stores/MainStore.ts +++ b/packages/main/src/stores/MainStore.ts | |||
@@ -19,19 +19,19 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { applySnapshot, Instance, types } from 'mobx-state-tree'; | 21 | import { applySnapshot, Instance, types } from 'mobx-state-tree'; |
22 | import { BrowserViewBounds, emptySharedStore } from '@sophie/shared'; | 22 | import { BrowserViewBounds } from '@sophie/shared'; |
23 | 23 | ||
24 | import type { Config } from './Config'; | 24 | import type { Config } from './Config'; |
25 | import { sharedStore } from './SharedStore'; | 25 | import { sharedStore } from './SharedStore'; |
26 | 26 | ||
27 | export const mainStore = types.model('MainStore', { | 27 | export const mainStore = types.model('MainStore', { |
28 | browserViewBounds: types.model('BrowserViewBounds', { | 28 | browserViewBounds: types.optional(types.model('BrowserViewBounds', { |
29 | x: 0, | 29 | x: 0, |
30 | y: 0, | 30 | y: 0, |
31 | width: 0, | 31 | width: 0, |
32 | height: 0, | 32 | height: 0, |
33 | }), | 33 | }), {}), |
34 | shared: sharedStore, | 34 | shared: types.optional(sharedStore, {}), |
35 | }).views((self) => ({ | 35 | }).views((self) => ({ |
36 | get config(): Config { | 36 | get config(): Config { |
37 | return self.shared.config; | 37 | return self.shared.config; |
@@ -48,8 +48,5 @@ export const mainStore = types.model('MainStore', { | |||
48 | export interface MainStore extends Instance<typeof mainStore> {} | 48 | export interface MainStore extends Instance<typeof mainStore> {} |
49 | 49 | ||
50 | export function createMainStore(): MainStore { | 50 | export function createMainStore(): MainStore { |
51 | return mainStore.create({ | 51 | return mainStore.create(); |
52 | browserViewBounds: {}, | ||
53 | shared: emptySharedStore, | ||
54 | }); | ||
55 | } | 52 | } |
diff --git a/packages/main/src/stores/SharedStore.ts b/packages/main/src/stores/SharedStore.ts index 04dda32..e20150d 100644 --- a/packages/main/src/stores/SharedStore.ts +++ b/packages/main/src/stores/SharedStore.ts | |||
@@ -18,7 +18,7 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { Instance } from 'mobx-state-tree'; | 21 | import { Instance, types } from 'mobx-state-tree'; |
22 | import { sharedStore as originalSharedStore } from '@sophie/shared'; | 22 | import { sharedStore as originalSharedStore } from '@sophie/shared'; |
23 | 23 | ||
24 | import { config } from './Config'; | 24 | import { config } from './Config'; |
@@ -26,7 +26,7 @@ import { config } from './Config'; | |||
26 | export type { SharedStoreSnapshotIn, SharedStoreSnapshotOut } from '@sophie/shared'; | 26 | export type { SharedStoreSnapshotIn, SharedStoreSnapshotOut } from '@sophie/shared'; |
27 | 27 | ||
28 | export const sharedStore = originalSharedStore.props({ | 28 | export const sharedStore = originalSharedStore.props({ |
29 | config, | 29 | config: types.optional(config, {}), |
30 | }); | 30 | }); |
31 | 31 | ||
32 | export interface SharedStore extends Instance<typeof sharedStore> {} | 32 | export interface SharedStore extends Instance<typeof sharedStore> {} |
diff --git a/packages/renderer/src/stores/RootStore.ts b/packages/renderer/src/stores/RootStore.ts index 20e0afa..f7f37f0 100644 --- a/packages/renderer/src/stores/RootStore.ts +++ b/packages/renderer/src/stores/RootStore.ts | |||
@@ -28,7 +28,6 @@ import { | |||
28 | } from 'mobx-state-tree'; | 28 | } from 'mobx-state-tree'; |
29 | import { | 29 | import { |
30 | BrowserViewBounds, | 30 | BrowserViewBounds, |
31 | emptySharedStore, | ||
32 | sharedStore, | 31 | sharedStore, |
33 | SophieRenderer, | 32 | SophieRenderer, |
34 | ThemeSource, | 33 | ThemeSource, |
@@ -50,7 +49,7 @@ export function getEnv(model: IAnyStateTreeNode): RootEnv { | |||
50 | } | 49 | } |
51 | 50 | ||
52 | export const rootStore = types.model('RootStore', { | 51 | export const rootStore = types.model('RootStore', { |
53 | shared: sharedStore, | 52 | shared: types.optional(sharedStore, {}), |
54 | }).actions((self) => ({ | 53 | }).actions((self) => ({ |
55 | setBrowserViewBounds(bounds: BrowserViewBounds) { | 54 | setBrowserViewBounds(bounds: BrowserViewBounds) { |
56 | getEnv(self).ipc.setBrowserViewBounds(bounds); | 55 | getEnv(self).ipc.setBrowserViewBounds(bounds); |
@@ -78,9 +77,7 @@ export interface RootStore extends Instance<typeof rootStore> {} | |||
78 | * @param ipc The `sophieRenderer` context bridge. | 77 | * @param ipc The `sophieRenderer` context bridge. |
79 | */ | 78 | */ |
80 | export function createAndConnectRootStore(ipc: SophieRenderer): RootStore { | 79 | export function createAndConnectRootStore(ipc: SophieRenderer): RootStore { |
81 | const store = rootStore.create({ | 80 | const store = rootStore.create({}, { |
82 | shared: emptySharedStore, | ||
83 | }, { | ||
84 | ipc, | 81 | ipc, |
85 | }); | 82 | }); |
86 | 83 | ||
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 046d28d..713984e 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts | |||
@@ -35,7 +35,7 @@ export { | |||
35 | } from './schemas'; | 35 | } from './schemas'; |
36 | 36 | ||
37 | export type { Config, ConfigSnapshotIn, ConfigSnapshotOut } from './stores/Config'; | 37 | export type { Config, ConfigSnapshotIn, ConfigSnapshotOut } from './stores/Config'; |
38 | export { config, defaultConfig } from './stores/Config'; | 38 | export { config } from './stores/Config'; |
39 | 39 | ||
40 | export type { | 40 | export type { |
41 | SharedStore, | 41 | SharedStore, |
@@ -43,4 +43,4 @@ export type { | |||
43 | SharedStoreSnapshotIn, | 43 | SharedStoreSnapshotIn, |
44 | SharedStoreSnapshotOut, | 44 | SharedStoreSnapshotOut, |
45 | } from './stores/SharedStore'; | 45 | } from './stores/SharedStore'; |
46 | export { emptySharedStore, sharedStore } from './stores/SharedStore'; | 46 | export { sharedStore } from './stores/SharedStore'; |
diff --git a/packages/shared/src/stores/Config.ts b/packages/shared/src/stores/Config.ts index 1a9f924..432945c 100644 --- a/packages/shared/src/stores/Config.ts +++ b/packages/shared/src/stores/Config.ts | |||
@@ -27,14 +27,10 @@ import { | |||
27 | 27 | ||
28 | import { themeSource } from '../schemas'; | 28 | import { themeSource } from '../schemas'; |
29 | 29 | ||
30 | export const config = types.model("Config", { | 30 | export const config = types.model('Config', { |
31 | themeSource: types.enumeration(themeSource.options), | 31 | themeSource: types.optional(types.enumeration(themeSource.options), 'system'), |
32 | }); | 32 | }); |
33 | 33 | ||
34 | export const defaultConfig: ConfigSnapshotIn = { | ||
35 | themeSource: 'system', | ||
36 | }; | ||
37 | |||
38 | export interface Config extends Instance<typeof config> {} | 34 | export interface Config extends Instance<typeof config> {} |
39 | 35 | ||
40 | export interface ConfigSnapshotIn extends SnapshotIn<typeof config> {} | 36 | export interface ConfigSnapshotIn extends SnapshotIn<typeof config> {} |
diff --git a/packages/shared/src/stores/SharedStore.ts b/packages/shared/src/stores/SharedStore.ts index 9f0afb1..cfff6d5 100644 --- a/packages/shared/src/stores/SharedStore.ts +++ b/packages/shared/src/stores/SharedStore.ts | |||
@@ -26,17 +26,13 @@ import { | |||
26 | SnapshotOut, | 26 | SnapshotOut, |
27 | } from 'mobx-state-tree'; | 27 | } from 'mobx-state-tree'; |
28 | 28 | ||
29 | import { config, defaultConfig } from './Config'; | 29 | import { config } from './Config'; |
30 | 30 | ||
31 | export const sharedStore = types.model("SharedStore", { | 31 | export const sharedStore = types.model('SharedStore', { |
32 | config, | 32 | config: types.optional(config, {}), |
33 | shouldUseDarkColors: true, | 33 | shouldUseDarkColors: true, |
34 | }); | 34 | }); |
35 | 35 | ||
36 | export const emptySharedStore: SharedStoreSnapshotIn = { | ||
37 | config: defaultConfig, | ||
38 | }; | ||
39 | |||
40 | export interface SharedStore extends Instance<typeof sharedStore> {} | 36 | export interface SharedStore extends Instance<typeof sharedStore> {} |
41 | 37 | ||
42 | export interface SharedStoreSnapshotIn extends SnapshotIn<typeof sharedStore> {} | 38 | export interface SharedStoreSnapshotIn extends SnapshotIn<typeof sharedStore> {} |