aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/stores/SharedStore.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/stores/SharedStore.ts')
-rw-r--r--packages/main/src/stores/SharedStore.ts34
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
21import { sharedStore as originalSharedStore } from '@sophie/shared'; 21import { SharedStore as SharedStoreBase } from '@sophie/shared';
22import { 22import {
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
35import { getLogger } from '../utils/log'; 34import { getLogger } from '../utils/log';
36import overrideProps from '../utils/overrideProps'; 35import overrideProps from '../utils/overrideProps';
37 36
38import { globalSettings, GlobalSettingsSnapshotIn } from './GlobalSettings'; 37import GlobalSettings, { GlobalSettingsSnapshotIn } from './GlobalSettings';
39import { addMissingProfileIds, profile, ProfileConfig } from './Profile'; 38import Profile, { addMissingProfileIds, ProfileConfig } from './Profile';
40import { 39import 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
89export const sharedStore = overrideProps(originalSharedStore, { 87const 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
155export 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*/
157interface SharedStore extends Instance<typeof SharedStore> {}
158
159export default SharedStore;
156 160
157export type { 161export type {
158 SharedStoreSnapshotIn, 162 SharedStoreSnapshotIn,