diff options
Diffstat (limited to 'packages/shared/src')
-rw-r--r-- | packages/shared/src/contextBridge/SophieRenderer.ts | 4 | ||||
-rw-r--r-- | packages/shared/src/index.ts | 7 | ||||
-rw-r--r-- | packages/shared/src/ipc.ts | 2 | ||||
-rw-r--r-- | packages/shared/src/schemas.ts | 4 | ||||
-rw-r--r-- | packages/shared/src/stores/Config.ts | 42 | ||||
-rw-r--r-- | packages/shared/src/stores/SharedStore.ts | 4 |
6 files changed, 56 insertions, 7 deletions
diff --git a/packages/shared/src/contextBridge/SophieRenderer.ts b/packages/shared/src/contextBridge/SophieRenderer.ts index e310829..6a2e432 100644 --- a/packages/shared/src/contextBridge/SophieRenderer.ts +++ b/packages/shared/src/contextBridge/SophieRenderer.ts | |||
@@ -20,14 +20,14 @@ | |||
20 | 20 | ||
21 | import { SharedStoreListener } from '../stores/SharedStore'; | 21 | import { SharedStoreListener } from '../stores/SharedStore'; |
22 | 22 | ||
23 | import { BrowserViewBounds, PaletteMode } from '../schemas'; | 23 | import { BrowserViewBounds, ThemeSource } from '../schemas'; |
24 | 24 | ||
25 | export interface SophieRenderer { | 25 | export interface SophieRenderer { |
26 | setSharedStoreListener(listener: SharedStoreListener): void; | 26 | setSharedStoreListener(listener: SharedStoreListener): void; |
27 | 27 | ||
28 | setBrowserViewBounds(bounds: BrowserViewBounds): void; | 28 | setBrowserViewBounds(bounds: BrowserViewBounds): void; |
29 | 29 | ||
30 | setPaletteMode(mode: PaletteMode): void; | 30 | setThemeSource(mode: ThemeSource): void; |
31 | 31 | ||
32 | reloadAllServices(): void; | 32 | reloadAllServices(): void; |
33 | } | 33 | } |
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index f054571..046d28d 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts | |||
@@ -27,13 +27,16 @@ export { | |||
27 | 27 | ||
28 | export type { | 28 | export type { |
29 | BrowserViewBounds, | 29 | BrowserViewBounds, |
30 | PaletteMode, | 30 | ThemeSource, |
31 | } from './schemas'; | 31 | } from './schemas'; |
32 | export { | 32 | export { |
33 | browserViewBounds, | 33 | browserViewBounds, |
34 | paletteMode | 34 | themeSource, |
35 | } from './schemas'; | 35 | } from './schemas'; |
36 | 36 | ||
37 | export type { Config, ConfigSnapshotIn, ConfigSnapshotOut } from './stores/Config'; | ||
38 | export { config, defaultConfig } from './stores/Config'; | ||
39 | |||
37 | export type { | 40 | export type { |
38 | SharedStore, | 41 | SharedStore, |
39 | SharedStoreListener, | 42 | SharedStoreListener, |
diff --git a/packages/shared/src/ipc.ts b/packages/shared/src/ipc.ts index 2e35d7a..d2f65f7 100644 --- a/packages/shared/src/ipc.ts +++ b/packages/shared/src/ipc.ts | |||
@@ -26,6 +26,6 @@ export enum MainToRendererIpcMessage { | |||
26 | export enum RendererToMainIpcMessage { | 26 | export enum RendererToMainIpcMessage { |
27 | SharedStoreSnapshotRequest = 'sophie-renderer-to-main:shared-store-snapshot-request', | 27 | SharedStoreSnapshotRequest = 'sophie-renderer-to-main:shared-store-snapshot-request', |
28 | SetBrowserViewBounds = 'sophie-renderer-to-main:set-browser-view-bounds', | 28 | SetBrowserViewBounds = 'sophie-renderer-to-main:set-browser-view-bounds', |
29 | SetPaletteMode = 'sophie-renderer-to-main:set-palette-mode', | 29 | SetThemeSource = 'sophie-renderer-to-main:set-theme-source', |
30 | ReloadAllServices = 'sophie-renderer-to-main:reload-all-services', | 30 | ReloadAllServices = 'sophie-renderer-to-main:reload-all-services', |
31 | } | 31 | } |
diff --git a/packages/shared/src/schemas.ts b/packages/shared/src/schemas.ts index 8827467..0eff581 100644 --- a/packages/shared/src/schemas.ts +++ b/packages/shared/src/schemas.ts | |||
@@ -29,6 +29,6 @@ export const browserViewBounds = z.object({ | |||
29 | 29 | ||
30 | export type BrowserViewBounds = z.infer<typeof browserViewBounds>; | 30 | export type BrowserViewBounds = z.infer<typeof browserViewBounds>; |
31 | 31 | ||
32 | export const paletteMode = z.enum(['light', 'dark']); | 32 | export const themeSource = z.enum(['system', 'light', 'dark']); |
33 | 33 | ||
34 | export type PaletteMode = z.infer<typeof paletteMode>; | 34 | export type ThemeSource = z.infer<typeof themeSource>; |
diff --git a/packages/shared/src/stores/Config.ts b/packages/shared/src/stores/Config.ts new file mode 100644 index 0000000..1a9f924 --- /dev/null +++ b/packages/shared/src/stores/Config.ts | |||
@@ -0,0 +1,42 @@ | |||
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 { | ||
22 | Instance, | ||
23 | types, | ||
24 | SnapshotIn, | ||
25 | SnapshotOut, | ||
26 | } from 'mobx-state-tree'; | ||
27 | |||
28 | import { themeSource } from '../schemas'; | ||
29 | |||
30 | export const config = types.model("Config", { | ||
31 | themeSource: types.enumeration(themeSource.options), | ||
32 | }); | ||
33 | |||
34 | export const defaultConfig: ConfigSnapshotIn = { | ||
35 | themeSource: 'system', | ||
36 | }; | ||
37 | |||
38 | export interface Config extends Instance<typeof config> {} | ||
39 | |||
40 | export interface ConfigSnapshotIn extends SnapshotIn<typeof config> {} | ||
41 | |||
42 | export interface ConfigSnapshotOut extends SnapshotOut<typeof config> {} | ||
diff --git a/packages/shared/src/stores/SharedStore.ts b/packages/shared/src/stores/SharedStore.ts index 9c7d5ad..9f0afb1 100644 --- a/packages/shared/src/stores/SharedStore.ts +++ b/packages/shared/src/stores/SharedStore.ts | |||
@@ -26,11 +26,15 @@ import { | |||
26 | SnapshotOut, | 26 | SnapshotOut, |
27 | } from 'mobx-state-tree'; | 27 | } from 'mobx-state-tree'; |
28 | 28 | ||
29 | import { config, defaultConfig } from './Config'; | ||
30 | |||
29 | export const sharedStore = types.model("SharedStore", { | 31 | export const sharedStore = types.model("SharedStore", { |
32 | config, | ||
30 | shouldUseDarkColors: true, | 33 | shouldUseDarkColors: true, |
31 | }); | 34 | }); |
32 | 35 | ||
33 | export const emptySharedStore: SharedStoreSnapshotIn = { | 36 | export const emptySharedStore: SharedStoreSnapshotIn = { |
37 | config: defaultConfig, | ||
34 | }; | 38 | }; |
35 | 39 | ||
36 | export interface SharedStore extends Instance<typeof sharedStore> {} | 40 | export interface SharedStore extends Instance<typeof sharedStore> {} |