diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-01-03 01:02:00 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-02-08 21:41:27 +0100 |
commit | 3b7d52abb0e7de00bdf92ee3482a4cae1f6b7d64 (patch) | |
tree | 7122ef45a1fd42c7ab835ab2f2685050de2c45b2 /packages/main/src/controllers/initConfig.ts | |
parent | chore(deps): update electron to version 17.0.0 (diff) | |
download | sophie-3b7d52abb0e7de00bdf92ee3482a4cae1f6b7d64.tar.gz sophie-3b7d52abb0e7de00bdf92ee3482a4cae1f6b7d64.tar.zst sophie-3b7d52abb0e7de00bdf92ee3482a4cae1f6b7d64.zip |
feat: Add Profile and Service stores
In the main process, it is optional to specify the ID of a Profile or a
Service. The missing ID will be filled in with a randomly generated one.
Moreover, services without a profile will get a profile generated with
the same name.
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/controllers/initConfig.ts')
-rw-r--r-- | packages/main/src/controllers/initConfig.ts | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/packages/main/src/controllers/initConfig.ts b/packages/main/src/controllers/initConfig.ts index 915f451..93be978 100644 --- a/packages/main/src/controllers/initConfig.ts +++ b/packages/main/src/controllers/initConfig.ts | |||
@@ -19,11 +19,11 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { debounce } from 'lodash-es'; | 21 | import { debounce } from 'lodash-es'; |
22 | import { applySnapshot, getSnapshot, onSnapshot } from 'mobx-state-tree'; | 22 | import { getSnapshot, onSnapshot } from 'mobx-state-tree'; |
23 | import ms from 'ms'; | 23 | import ms from 'ms'; |
24 | 24 | ||
25 | import type ConfigPersistenceService from '../services/ConfigPersistenceService'; | 25 | import type ConfigPersistenceService from '../services/ConfigPersistenceService.js'; |
26 | import type { Config, ConfigSnapshotOut } from '../stores/Config'; | 26 | import { Config, ConfigFileIn, ConfigSnapshotOut } from '../stores/Config.js'; |
27 | import type Disposer from '../utils/Disposer'; | 27 | import type Disposer from '../utils/Disposer'; |
28 | import { getLogger } from '../utils/log'; | 28 | import { getLogger } from '../utils/log'; |
29 | 29 | ||
@@ -44,12 +44,14 @@ export default async function initConfig( | |||
44 | const result = await persistenceService.readConfig(); | 44 | const result = await persistenceService.readConfig(); |
45 | if (result.found) { | 45 | if (result.found) { |
46 | try { | 46 | try { |
47 | applySnapshot(config, result.data); | 47 | // This cast is unsound if the config file is invalid, |
48 | lastSnapshotOnDisk = getSnapshot(config); | 48 | // but we'll throw an error in the end anyways. |
49 | config.loadFromConfigFile(result.data as ConfigFileIn); | ||
49 | } catch (error) { | 50 | } catch (error) { |
50 | log.error('Failed to apply config snapshot', result.data, error); | 51 | log.error('Failed to apply config snapshot', result.data, error); |
51 | } | 52 | } |
52 | } | 53 | } |
54 | lastSnapshotOnDisk = getSnapshot(config); | ||
53 | return result.found; | 55 | return result.found; |
54 | } | 56 | } |
55 | 57 | ||