diff options
Diffstat (limited to 'packages/main/src/stores/MainStore.ts')
-rw-r--r-- | packages/main/src/stores/MainStore.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/packages/main/src/stores/MainStore.ts b/packages/main/src/stores/MainStore.ts new file mode 100644 index 0000000..ee215a7 --- /dev/null +++ b/packages/main/src/stores/MainStore.ts | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2021-2022 Kristóf Marussy <kristof@marussy.com> | ||
3 | * | ||
4 | * This file is part of Sophie. | ||
5 | * | ||
6 | * Sophie is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU Affero General Public License as | ||
8 | * published by the Free Software Foundation, version 3. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * SPDX-License-Identifier: AGPL-3.0-only | ||
19 | */ | ||
20 | |||
21 | import { applySnapshot, Instance, types } from 'mobx-state-tree'; | ||
22 | import { BrowserViewBounds, emptySharedStore } from '@sophie/shared'; | ||
23 | |||
24 | import type { Config } from './Config'; | ||
25 | import { MainEnv } from '../services/MainEnv'; | ||
26 | import { sharedStore } from './SharedStore'; | ||
27 | |||
28 | export const mainStore = types.model('MainStore', { | ||
29 | browserViewBounds: types.model('BrowserViewBounds', { | ||
30 | x: 0, | ||
31 | y: 0, | ||
32 | width: 0, | ||
33 | height: 0, | ||
34 | }), | ||
35 | shared: sharedStore, | ||
36 | }).views((self) => ({ | ||
37 | get config(): Config { | ||
38 | return self.shared.config; | ||
39 | }, | ||
40 | })).actions((self) => ({ | ||
41 | setBrowserViewBounds(bounds: BrowserViewBounds): void { | ||
42 | applySnapshot(self.browserViewBounds, bounds); | ||
43 | }, | ||
44 | setShouldUseDarkColors(shouldUseDarkColors: boolean): void { | ||
45 | self.shared.shouldUseDarkColors = shouldUseDarkColors; | ||
46 | } | ||
47 | })); | ||
48 | |||
49 | export interface RootStore extends Instance<typeof mainStore> {} | ||
50 | |||
51 | export function createMainStore(env: MainEnv): RootStore { | ||
52 | return mainStore.create( | ||
53 | { | ||
54 | browserViewBounds: {}, | ||
55 | shared: emptySharedStore, | ||
56 | }, | ||
57 | env, | ||
58 | ); | ||
59 | } | ||