From 3b7d52abb0e7de00bdf92ee3482a4cae1f6b7d64 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Mon, 3 Jan 2022 01:02:00 +0100 Subject: feat: Add Profile and Service stores MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- packages/main/src/controllers/initConfig.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'packages/main/src/controllers/initConfig.ts') 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 @@ */ import { debounce } from 'lodash-es'; -import { applySnapshot, getSnapshot, onSnapshot } from 'mobx-state-tree'; +import { getSnapshot, onSnapshot } from 'mobx-state-tree'; import ms from 'ms'; -import type ConfigPersistenceService from '../services/ConfigPersistenceService'; -import type { Config, ConfigSnapshotOut } from '../stores/Config'; +import type ConfigPersistenceService from '../services/ConfigPersistenceService.js'; +import { Config, ConfigFileIn, ConfigSnapshotOut } from '../stores/Config.js'; import type Disposer from '../utils/Disposer'; import { getLogger } from '../utils/log'; @@ -44,12 +44,14 @@ export default async function initConfig( const result = await persistenceService.readConfig(); if (result.found) { try { - applySnapshot(config, result.data); - lastSnapshotOnDisk = getSnapshot(config); + // This cast is unsound if the config file is invalid, + // but we'll throw an error in the end anyways. + config.loadFromConfigFile(result.data as ConfigFileIn); } catch (error) { log.error('Failed to apply config snapshot', result.data, error); } } + lastSnapshotOnDisk = getSnapshot(config); return result.found; } -- cgit v1.2.3-70-g09d2