From 038b35cc43d38d53c3a7f2c90479bb16a18084a6 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 25 Jan 2022 17:26:32 +0100 Subject: refactor: Store services in a map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes the synchronization of references across the main/renderer process boundary more robust. Signed-off-by: Kristóf Marussy --- packages/main/src/stores/Service.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'packages/main/src/stores/Service.ts') diff --git a/packages/main/src/stores/Service.ts b/packages/main/src/stores/Service.ts index 78c57cb..331805b 100644 --- a/packages/main/src/stores/Service.ts +++ b/packages/main/src/stores/Service.ts @@ -19,18 +19,14 @@ */ import type { UnreadCount } from '@sophie/service-shared'; -import { - service as originalService, - ServiceSettingsSnapshotIn, -} from '@sophie/shared'; +import { service as originalService } from '@sophie/shared'; import { Instance, getSnapshot, ReferenceIdentifier } from 'mobx-state-tree'; -import SettingsWithId from '../utils/SettingsWithId'; import generateId from '../utils/generateId'; import overrideProps from '../utils/overrideProps'; import { ProfileSettingsSnapshotWithId } from './Profile'; -import { serviceSettings } from './ServiceSettings'; +import { serviceSettings, ServiceSettingsSnapshotIn } from './ServiceSettings'; export interface ServiceConfig extends Omit { @@ -89,8 +85,7 @@ export const service = overrideProps(originalService, { export interface Service extends Instance {} -export type ServiceSettingsSnapshotWithId = - SettingsWithId; +export type ServiceSettingsSnapshotWithId = [string, ServiceSettingsSnapshotIn]; export function addMissingServiceIdsAndProfiles( serviceConfigs: ServiceConfig[] | undefined, @@ -102,11 +97,11 @@ export function addMissingServiceIdsAndProfiles( let { profile: profileId } = settings; if (profileId === undefined) { profileId = generateId(name); - profiles.push({ id: profileId, settings: { name } }); + profiles.push([profileId, { name }]); } - return { - id: id === undefined ? generateId(name) : id, - settings: { ...settings, profile: profileId }, - }; + return [ + id === undefined ? generateId(name) : id, + { ...settings, profile: profileId }, + ]; }); } -- cgit v1.2.3-70-g09d2