diff options
Diffstat (limited to 'packages/main/src/stores/SharedStore.ts')
-rw-r--r-- | packages/main/src/stores/SharedStore.ts | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/packages/main/src/stores/SharedStore.ts b/packages/main/src/stores/SharedStore.ts index 499d1ee..c34af75 100644 --- a/packages/main/src/stores/SharedStore.ts +++ b/packages/main/src/stores/SharedStore.ts | |||
@@ -18,7 +18,7 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { sharedStore as originalSharedStore } from '@sophie/shared'; | 21 | import { SharedStore as SharedStoreBase } from '@sophie/shared'; |
22 | import { | 22 | import { |
23 | applySnapshot, | 23 | applySnapshot, |
24 | getSnapshot, | 24 | getSnapshot, |
@@ -28,18 +28,16 @@ import { | |||
28 | IReferenceType, | 28 | IReferenceType, |
29 | IStateTreeNode, | 29 | IStateTreeNode, |
30 | IType, | 30 | IType, |
31 | resolveIdentifier, | ||
32 | types, | 31 | types, |
33 | } from 'mobx-state-tree'; | 32 | } from 'mobx-state-tree'; |
34 | 33 | ||
35 | import { getLogger } from '../utils/log'; | 34 | import { getLogger } from '../utils/log'; |
36 | import overrideProps from '../utils/overrideProps'; | 35 | import overrideProps from '../utils/overrideProps'; |
37 | 36 | ||
38 | import { globalSettings, GlobalSettingsSnapshotIn } from './GlobalSettings'; | 37 | import GlobalSettings, { GlobalSettingsSnapshotIn } from './GlobalSettings'; |
39 | import { addMissingProfileIds, profile, ProfileConfig } from './Profile'; | 38 | import Profile, { addMissingProfileIds, ProfileConfig } from './Profile'; |
40 | import { | 39 | import Service, { |
41 | addMissingServiceIdsAndProfiles, | 40 | addMissingServiceIdsAndProfiles, |
42 | service, | ||
43 | ServiceConfig, | 41 | ServiceConfig, |
44 | } from './Service'; | 42 | } from './Service'; |
45 | 43 | ||
@@ -86,13 +84,13 @@ function applySettings< | |||
86 | current.push(...toApply.map(([id]) => id)); | 84 | current.push(...toApply.map(([id]) => id)); |
87 | } | 85 | } |
88 | 86 | ||
89 | export const sharedStore = overrideProps(originalSharedStore, { | 87 | const SharedStore = overrideProps(SharedStoreBase, { |
90 | settings: types.optional(globalSettings, {}), | 88 | settings: types.optional(GlobalSettings, {}), |
91 | profilesById: types.map(profile), | 89 | profilesById: types.map(Profile), |
92 | profiles: types.array(types.reference(profile)), | 90 | profiles: types.array(types.reference(Profile)), |
93 | servicesById: types.map(service), | 91 | servicesById: types.map(Service), |
94 | services: types.array(types.reference(service)), | 92 | services: types.array(types.reference(Service)), |
95 | selectedService: types.safeReference(service), | 93 | selectedService: types.safeReference(Service), |
96 | }) | 94 | }) |
97 | .views((self) => ({ | 95 | .views((self) => ({ |
98 | get config(): Config { | 96 | get config(): Config { |
@@ -142,7 +140,7 @@ export const sharedStore = overrideProps(originalSharedStore, { | |||
142 | self.shouldUseDarkColors = shouldUseDarkColors; | 140 | self.shouldUseDarkColors = shouldUseDarkColors; |
143 | }, | 141 | }, |
144 | setSelectedServiceId(serviceId: string): void { | 142 | setSelectedServiceId(serviceId: string): void { |
145 | const serviceInstance = resolveIdentifier(service, self, serviceId); | 143 | const serviceInstance = self.servicesById.get(serviceId); |
146 | if (serviceInstance === undefined) { | 144 | if (serviceInstance === undefined) { |
147 | log.warn('Trying to select unknown service', serviceId); | 145 | log.warn('Trying to select unknown service', serviceId); |
148 | return; | 146 | return; |
@@ -152,7 +150,13 @@ export const sharedStore = overrideProps(originalSharedStore, { | |||
152 | }, | 150 | }, |
153 | })); | 151 | })); |
154 | 152 | ||
155 | export interface SharedStore extends Instance<typeof sharedStore> {} | 153 | /* |
154 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | ||
155 | Intentionally naming the type the same as the store definition. | ||
156 | */ | ||
157 | interface SharedStore extends Instance<typeof SharedStore> {} | ||
158 | |||
159 | export default SharedStore; | ||
156 | 160 | ||
157 | export type { | 161 | export type { |
158 | SharedStoreSnapshotIn, | 162 | SharedStoreSnapshotIn, |