diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-01-20 19:13:45 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-02-08 21:43:16 +0100 |
commit | cef1c2fd221e81424195026645386370662ef398 (patch) | |
tree | 77fc9d044adef735adb2c2acc0ba3e74858aa1f8 /packages/main | |
parent | refactor: Rename main services to infrastructure (diff) | |
download | sophie-cef1c2fd221e81424195026645386370662ef398.tar.gz sophie-cef1c2fd221e81424195026645386370662ef398.tar.zst sophie-cef1c2fd221e81424195026645386370662ef398.zip |
feat: Add selected service field to SharedStore
Lets the main process see which service is currently selected.
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main')
-rw-r--r-- | packages/main/src/index.ts | 3 | ||||
-rw-r--r-- | packages/main/src/stores/MainStore.ts | 22 |
2 files changed, 23 insertions, 2 deletions
diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index ee89f49..66405ea 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts | |||
@@ -269,6 +269,9 @@ async function createWindow(): Promise<unknown> { | |||
269 | try { | 269 | try { |
270 | const actionToDispatch = action.parse(rawAction); | 270 | const actionToDispatch = action.parse(rawAction); |
271 | switch (actionToDispatch.action) { | 271 | switch (actionToDispatch.action) { |
272 | case 'set-selected-service-id': | ||
273 | store.setSelectedServiceId(actionToDispatch.serviceId); | ||
274 | break; | ||
272 | case 'set-browser-view-bounds': | 275 | case 'set-browser-view-bounds': |
273 | store.setBrowserViewBounds(actionToDispatch.browserViewBounds); | 276 | store.setBrowserViewBounds(actionToDispatch.browserViewBounds); |
274 | break; | 277 | break; |
diff --git a/packages/main/src/stores/MainStore.ts b/packages/main/src/stores/MainStore.ts index eaf5b3c..f0d6472 100644 --- a/packages/main/src/stores/MainStore.ts +++ b/packages/main/src/stores/MainStore.ts | |||
@@ -18,12 +18,21 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { BrowserViewBounds } from '@sophie/shared'; | 21 | import { BrowserViewBounds, service } from '@sophie/shared'; |
22 | import { applySnapshot, Instance, types } from 'mobx-state-tree'; | 22 | import { |
23 | applySnapshot, | ||
24 | Instance, | ||
25 | resolveIdentifier, | ||
26 | types, | ||
27 | } from 'mobx-state-tree'; | ||
28 | |||
29 | import { getLogger } from '../utils/log'; | ||
23 | 30 | ||
24 | import type { Config } from './Config.js'; | 31 | import type { Config } from './Config.js'; |
25 | import { sharedStore } from './SharedStore'; | 32 | import { sharedStore } from './SharedStore'; |
26 | 33 | ||
34 | const log = getLogger('mainStore'); | ||
35 | |||
27 | export const mainStore = types | 36 | export const mainStore = types |
28 | .model('MainStore', { | 37 | .model('MainStore', { |
29 | browserViewBounds: types.optional( | 38 | browserViewBounds: types.optional( |
@@ -43,6 +52,15 @@ export const mainStore = types | |||
43 | }, | 52 | }, |
44 | })) | 53 | })) |
45 | .actions((self) => ({ | 54 | .actions((self) => ({ |
55 | setSelectedServiceId(serviceId: string): void { | ||
56 | const serviceInstance = resolveIdentifier(service, self, serviceId); | ||
57 | if (serviceInstance === undefined) { | ||
58 | log.warn('Trying to select unknown service', serviceId); | ||
59 | return; | ||
60 | } | ||
61 | self.shared.selectedService = serviceInstance; | ||
62 | log.debug('Selected service', serviceId); | ||
63 | }, | ||
46 | setBrowserViewBounds(bounds: BrowserViewBounds): void { | 64 | setBrowserViewBounds(bounds: BrowserViewBounds): void { |
47 | applySnapshot(self.browserViewBounds, bounds); | 65 | applySnapshot(self.browserViewBounds, bounds); |
48 | }, | 66 | }, |