aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/stores/MainStore.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-02-08 21:40:40 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-02-14 12:13:22 +0100
commitcc214bb1afd37068c2bbc93f33990ca93f9a900f (patch)
tree7707415d5c4e42b2542d3f482060d4935c892fe1 /packages/main/src/stores/MainStore.ts
parentfeat: Unread message badges (diff)
downloadsophie-cc214bb1afd37068c2bbc93f33990ca93f9a900f.tar.gz
sophie-cc214bb1afd37068c2bbc93f33990ca93f9a900f.tar.zst
sophie-cc214bb1afd37068c2bbc93f33990ca93f9a900f.zip
feat: Load and switch services
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/stores/MainStore.ts')
-rw-r--r--packages/main/src/stores/MainStore.ts45
1 files changed, 44 insertions, 1 deletions
diff --git a/packages/main/src/stores/MainStore.ts b/packages/main/src/stores/MainStore.ts
index ff014c9..9ac56f4 100644
--- a/packages/main/src/stores/MainStore.ts
+++ b/packages/main/src/stores/MainStore.ts
@@ -18,14 +18,19 @@
18 * SPDX-License-Identifier: AGPL-3.0-only 18 * SPDX-License-Identifier: AGPL-3.0-only
19 */ 19 */
20 20
21import type { BrowserViewBounds } from '@sophie/shared'; 21import type { Action, BrowserViewBounds } from '@sophie/shared';
22import { applySnapshot, Instance, types } from 'mobx-state-tree'; 22import { applySnapshot, Instance, types } from 'mobx-state-tree';
23 23
24import type { MainWindow } from '../infrastructure/electron/types';
25import { getLogger } from '../utils/log';
26
24import GlobalSettings from './GlobalSettings'; 27import GlobalSettings from './GlobalSettings';
25import Profile from './Profile'; 28import Profile from './Profile';
26import Service from './Service'; 29import Service from './Service';
27import SharedStore from './SharedStore'; 30import SharedStore from './SharedStore';
28 31
32const log = getLogger('MainStore');
33
29const MainStore = types 34const MainStore = types
30 .model('MainStore', { 35 .model('MainStore', {
31 browserViewBounds: types.optional( 36 browserViewBounds: types.optional(
@@ -49,11 +54,49 @@ const MainStore = types
49 get services(): Service[] { 54 get services(): Service[] {
50 return self.shared.services; 55 return self.shared.services;
51 }, 56 },
57 get visibleService(): Service | undefined {
58 const { selectedService } = this.settings;
59 return selectedService !== undefined && selectedService.shouldBeLoaded
60 ? selectedService
61 : undefined;
62 },
52 })) 63 }))
64 .volatile(
65 (): {
66 mainWindow: MainWindow | undefined;
67 } => ({
68 mainWindow: undefined,
69 }),
70 )
53 .actions((self) => ({ 71 .actions((self) => ({
54 setBrowserViewBounds(bounds: BrowserViewBounds): void { 72 setBrowserViewBounds(bounds: BrowserViewBounds): void {
55 applySnapshot(self.browserViewBounds, bounds); 73 applySnapshot(self.browserViewBounds, bounds);
56 }, 74 },
75 dispatch(action: Action): void {
76 switch (action.action) {
77 case 'reload-all-services':
78 // TODO
79 break;
80 case 'set-browser-view-bounds':
81 this.setBrowserViewBounds(action.browserViewBounds);
82 break;
83 case 'set-selected-service-id':
84 self.settings.setSelectedServiceId(action.serviceId);
85 break;
86 case 'set-theme-source':
87 self.settings.setThemeSource(action.themeSource);
88 break;
89 default:
90 log.error('Unknown action to dispatch', action);
91 break;
92 }
93 },
94 setMainWindow(mainWindow: MainWindow | undefined): void {
95 self.mainWindow = mainWindow;
96 },
97 beforeDestroy(): void {
98 self.mainWindow?.dispose();
99 },
57 })); 100 }));
58 101
59/* 102/*