diff options
Diffstat (limited to 'packages/main/src/stores/Config.ts')
-rw-r--r-- | packages/main/src/stores/Config.ts | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/packages/main/src/stores/Config.ts b/packages/main/src/stores/Config.ts index ca90c0c..e7fc360 100644 --- a/packages/main/src/stores/Config.ts +++ b/packages/main/src/stores/Config.ts | |||
@@ -19,14 +19,40 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { config as originalConfig, ThemeSource } from '@sophie/shared'; | 21 | import { config as originalConfig, ThemeSource } from '@sophie/shared'; |
22 | import { Instance } from 'mobx-state-tree'; | 22 | import { applySnapshot, Instance, SnapshotIn } from 'mobx-state-tree'; |
23 | |||
24 | import { addMissingProfileIds, PartialProfileSnapshotIn } from './Profile'; | ||
25 | import { | ||
26 | addMissingServiceIdsAndProfiles, | ||
27 | PartialServiceSnapshotIn, | ||
28 | } from './Service'; | ||
23 | 29 | ||
24 | export const config = originalConfig.actions((self) => ({ | 30 | export const config = originalConfig.actions((self) => ({ |
25 | setThemeSource(mode: ThemeSource) { | 31 | loadFromConfigFile(snapshot: ConfigFileIn): void { |
32 | const profiles = addMissingProfileIds(snapshot.profiles); | ||
33 | const services = addMissingServiceIdsAndProfiles( | ||
34 | snapshot.services, | ||
35 | profiles, | ||
36 | ); | ||
37 | applySnapshot(self, { | ||
38 | ...snapshot, | ||
39 | profiles, | ||
40 | services, | ||
41 | }); | ||
42 | }, | ||
43 | setThemeSource(mode: ThemeSource): void { | ||
26 | self.themeSource = mode; | 44 | self.themeSource = mode; |
27 | }, | 45 | }, |
28 | })); | 46 | })); |
29 | 47 | ||
30 | export interface Config extends Instance<typeof config> {} | 48 | export interface Config extends Instance<typeof config> {} |
31 | 49 | ||
32 | export type { ConfigSnapshotIn, ConfigSnapshotOut } from '@sophie/shared'; | 50 | export interface ConfigSnapshotIn extends SnapshotIn<typeof config> {} |
51 | |||
52 | export interface ConfigFileIn | ||
53 | extends Omit<ConfigSnapshotIn, 'profiles' | 'services'> { | ||
54 | profiles?: PartialProfileSnapshotIn[] | undefined; | ||
55 | services?: PartialServiceSnapshotIn[] | undefined; | ||
56 | } | ||
57 | |||
58 | export type { ConfigSnapshotOut } from '@sophie/shared'; | ||