From cce40ab1d2ad8cc1b60fabb4cc8281ea0490a123 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sun, 26 Dec 2021 01:59:17 +0100 Subject: feat: Set nativeTheme theme source on dark mode --- .../shared/src/contextBridge/SophieRenderer.ts | 4 +-- packages/shared/src/index.ts | 7 ++-- packages/shared/src/ipc.ts | 2 +- packages/shared/src/schemas.ts | 4 +-- packages/shared/src/stores/Config.ts | 42 ++++++++++++++++++++++ packages/shared/src/stores/SharedStore.ts | 4 +++ 6 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 packages/shared/src/stores/Config.ts (limited to 'packages/shared') 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 @@ import { SharedStoreListener } from '../stores/SharedStore'; -import { BrowserViewBounds, PaletteMode } from '../schemas'; +import { BrowserViewBounds, ThemeSource } from '../schemas'; export interface SophieRenderer { setSharedStoreListener(listener: SharedStoreListener): void; setBrowserViewBounds(bounds: BrowserViewBounds): void; - setPaletteMode(mode: PaletteMode): void; + setThemeSource(mode: ThemeSource): void; reloadAllServices(): void; } 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 { export type { BrowserViewBounds, - PaletteMode, + ThemeSource, } from './schemas'; export { browserViewBounds, - paletteMode + themeSource, } from './schemas'; +export type { Config, ConfigSnapshotIn, ConfigSnapshotOut } from './stores/Config'; +export { config, defaultConfig } from './stores/Config'; + export type { SharedStore, 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 { export enum RendererToMainIpcMessage { SharedStoreSnapshotRequest = 'sophie-renderer-to-main:shared-store-snapshot-request', SetBrowserViewBounds = 'sophie-renderer-to-main:set-browser-view-bounds', - SetPaletteMode = 'sophie-renderer-to-main:set-palette-mode', + SetThemeSource = 'sophie-renderer-to-main:set-theme-source', ReloadAllServices = 'sophie-renderer-to-main:reload-all-services', } 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({ export type BrowserViewBounds = z.infer; -export const paletteMode = z.enum(['light', 'dark']); +export const themeSource = z.enum(['system', 'light', 'dark']); -export type PaletteMode = z.infer; +export type ThemeSource = z.infer; 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 @@ +/* + * Copyright (C) 2021-2022 Kristóf Marussy + * + * This file is part of Sophie. + * + * Sophie is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { + Instance, + types, + SnapshotIn, + SnapshotOut, +} from 'mobx-state-tree'; + +import { themeSource } from '../schemas'; + +export const config = types.model("Config", { + themeSource: types.enumeration(themeSource.options), +}); + +export const defaultConfig: ConfigSnapshotIn = { + themeSource: 'system', +}; + +export interface Config extends Instance {} + +export interface ConfigSnapshotIn extends SnapshotIn {} + +export interface ConfigSnapshotOut extends SnapshotOut {} 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 { SnapshotOut, } from 'mobx-state-tree'; +import { config, defaultConfig } from './Config'; + export const sharedStore = types.model("SharedStore", { + config, shouldUseDarkColors: true, }); export const emptySharedStore: SharedStoreSnapshotIn = { + config: defaultConfig, }; export interface SharedStore extends Instance {} -- cgit v1.2.3-54-g00ecf