diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-01-25 17:26:32 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-02-08 21:43:17 +0100 |
commit | 038b35cc43d38d53c3a7f2c90479bb16a18084a6 (patch) | |
tree | 72f205b4d79de71b2a60f44c1461d5a1f2237f70 /packages/main/src/stores/Service.ts | |
parent | refactor: Move runtime state into shared models (diff) | |
download | sophie-038b35cc43d38d53c3a7f2c90479bb16a18084a6.tar.gz sophie-038b35cc43d38d53c3a7f2c90479bb16a18084a6.tar.zst sophie-038b35cc43d38d53c3a7f2c90479bb16a18084a6.zip |
refactor: Store services in a map
Makes the synchronization of references across the main/renderer process
boundary more robust.
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/stores/Service.ts')
-rw-r--r-- | packages/main/src/stores/Service.ts | 21 |
1 files changed, 8 insertions, 13 deletions
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 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | import type { UnreadCount } from '@sophie/service-shared'; | 21 | import type { UnreadCount } from '@sophie/service-shared'; |
22 | import { | 22 | import { service as originalService } from '@sophie/shared'; |
23 | service as originalService, | ||
24 | ServiceSettingsSnapshotIn, | ||
25 | } from '@sophie/shared'; | ||
26 | import { Instance, getSnapshot, ReferenceIdentifier } from 'mobx-state-tree'; | 23 | import { Instance, getSnapshot, ReferenceIdentifier } from 'mobx-state-tree'; |
27 | 24 | ||
28 | import SettingsWithId from '../utils/SettingsWithId'; | ||
29 | import generateId from '../utils/generateId'; | 25 | import generateId from '../utils/generateId'; |
30 | import overrideProps from '../utils/overrideProps'; | 26 | import overrideProps from '../utils/overrideProps'; |
31 | 27 | ||
32 | import { ProfileSettingsSnapshotWithId } from './Profile'; | 28 | import { ProfileSettingsSnapshotWithId } from './Profile'; |
33 | import { serviceSettings } from './ServiceSettings'; | 29 | import { serviceSettings, ServiceSettingsSnapshotIn } from './ServiceSettings'; |
34 | 30 | ||
35 | export interface ServiceConfig | 31 | export interface ServiceConfig |
36 | extends Omit<ServiceSettingsSnapshotIn, 'profile'> { | 32 | extends Omit<ServiceSettingsSnapshotIn, 'profile'> { |
@@ -89,8 +85,7 @@ export const service = overrideProps(originalService, { | |||
89 | 85 | ||
90 | export interface Service extends Instance<typeof service> {} | 86 | export interface Service extends Instance<typeof service> {} |
91 | 87 | ||
92 | export type ServiceSettingsSnapshotWithId = | 88 | export type ServiceSettingsSnapshotWithId = [string, ServiceSettingsSnapshotIn]; |
93 | SettingsWithId<ServiceSettingsSnapshotIn>; | ||
94 | 89 | ||
95 | export function addMissingServiceIdsAndProfiles( | 90 | export function addMissingServiceIdsAndProfiles( |
96 | serviceConfigs: ServiceConfig[] | undefined, | 91 | serviceConfigs: ServiceConfig[] | undefined, |
@@ -102,11 +97,11 @@ export function addMissingServiceIdsAndProfiles( | |||
102 | let { profile: profileId } = settings; | 97 | let { profile: profileId } = settings; |
103 | if (profileId === undefined) { | 98 | if (profileId === undefined) { |
104 | profileId = generateId(name); | 99 | profileId = generateId(name); |
105 | profiles.push({ id: profileId, settings: { name } }); | 100 | profiles.push([profileId, { name }]); |
106 | } | 101 | } |
107 | return { | 102 | return [ |
108 | id: id === undefined ? generateId(name) : id, | 103 | id === undefined ? generateId(name) : id, |
109 | settings: { ...settings, profile: profileId }, | 104 | { ...settings, profile: profileId }, |
110 | }; | 105 | ]; |
111 | }); | 106 | }); |
112 | } | 107 | } |