aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-26 01:59:17 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-26 01:59:17 +0100
commitcce40ab1d2ad8cc1b60fabb4cc8281ea0490a123 (patch)
treebb96df2676934a9cd4ef2bc5a48957e8b32fb646 /packages/shared
parentrefactor: Simplify browserViewBounds handling (diff)
downloadsophie-cce40ab1d2ad8cc1b60fabb4cc8281ea0490a123.tar.gz
sophie-cce40ab1d2ad8cc1b60fabb4cc8281ea0490a123.tar.zst
sophie-cce40ab1d2ad8cc1b60fabb4cc8281ea0490a123.zip
feat: Set nativeTheme theme source on dark mode
Diffstat (limited to 'packages/shared')
-rw-r--r--packages/shared/src/contextBridge/SophieRenderer.ts4
-rw-r--r--packages/shared/src/index.ts7
-rw-r--r--packages/shared/src/ipc.ts2
-rw-r--r--packages/shared/src/schemas.ts4
-rw-r--r--packages/shared/src/stores/Config.ts42
-rw-r--r--packages/shared/src/stores/SharedStore.ts4
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
21import { SharedStoreListener } from '../stores/SharedStore'; 21import { SharedStoreListener } from '../stores/SharedStore';
22 22
23import { BrowserViewBounds, PaletteMode } from '../schemas'; 23import { BrowserViewBounds, ThemeSource } from '../schemas';
24 24
25export interface SophieRenderer { 25export 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
28export type { 28export type {
29 BrowserViewBounds, 29 BrowserViewBounds,
30 PaletteMode, 30 ThemeSource,
31} from './schemas'; 31} from './schemas';
32export { 32export {
33 browserViewBounds, 33 browserViewBounds,
34 paletteMode 34 themeSource,
35} from './schemas'; 35} from './schemas';
36 36
37export type { Config, ConfigSnapshotIn, ConfigSnapshotOut } from './stores/Config';
38export { config, defaultConfig } from './stores/Config';
39
37export type { 40export 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 {
26export enum RendererToMainIpcMessage { 26export 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
30export type BrowserViewBounds = z.infer<typeof browserViewBounds>; 30export type BrowserViewBounds = z.infer<typeof browserViewBounds>;
31 31
32export const paletteMode = z.enum(['light', 'dark']); 32export const themeSource = z.enum(['system', 'light', 'dark']);
33 33
34export type PaletteMode = z.infer<typeof paletteMode>; 34export 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
21import {
22 Instance,
23 types,
24 SnapshotIn,
25 SnapshotOut,
26} from 'mobx-state-tree';
27
28import { themeSource } from '../schemas';
29
30export const config = types.model("Config", {
31 themeSource: types.enumeration(themeSource.options),
32});
33
34export const defaultConfig: ConfigSnapshotIn = {
35 themeSource: 'system',
36};
37
38export interface Config extends Instance<typeof config> {}
39
40export interface ConfigSnapshotIn extends SnapshotIn<typeof config> {}
41
42export 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
29import { config, defaultConfig } from './Config';
30
29export const sharedStore = types.model("SharedStore", { 31export const sharedStore = types.model("SharedStore", {
32 config,
30 shouldUseDarkColors: true, 33 shouldUseDarkColors: true,
31}); 34});
32 35
33export const emptySharedStore: SharedStoreSnapshotIn = { 36export const emptySharedStore: SharedStoreSnapshotIn = {
37 config: defaultConfig,
34}; 38};
35 39
36export interface SharedStore extends Instance<typeof sharedStore> {} 40export interface SharedStore extends Instance<typeof sharedStore> {}