Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

feat: add Light / Dark / System appearance selector (#1599)

Erwann Mestd929a9468aad
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 0d81a421..31c0cae7 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -539,6 +539,7 @@ pub fn run(cli_args: CliArgs) {
shortcut::change_audio_feedback_setting,
shortcut::change_audio_feedback_volume_setting,
shortcut::change_sound_theme_setting,
+ shortcut::change_theme_setting,
shortcut::change_start_hidden_setting,
shortcut::change_autostart_setting,
shortcut::change_translate_to_english_setting,
@@ -816,6 +817,13 @@ pub fn run(cli_args: CliArgs) {
let mut settings = get_settings(app.handle());
+ // Apply the persisted appearance theme to the Windows title bar before
+ // the window is shown, so it matches the in-app palette without a flash
+ // of the wrong theme. On macOS/Linux, Tauri themes are app-wide and
+ // would also affect windows that intentionally keep the system theme.
+ #[cfg(target_os = "windows")]
+ shortcut::apply_window_theme(app.handle(), settings.theme);
+
// CLI --debug flag overrides debug_mode and log level (runtime-only, not persisted)
if cli_args.debug {
settings.debug_mode = true;
diff --git a/src-tauri/src/settings.rs b/src-tauri/src/settings.rs
index 0ad43562..5fa6279f 100644
--- a/src-tauri/src/settings.rs
+++ b/src-tauri/src/settings.rs
@@ -258,6 +258,16 @@ impl SoundTheme {
}
}
+/// UI appearance mode. `System` follows the OS `prefers-color-scheme`; `Light`
+/// and `Dark` force one of the two palettes Handy already ships.
+#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Type)]
+#[serde(rename_all = "snake_case")]
+pub enum Theme {
+ System,
+ Light,
+ Dark,
+}
+
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Type, Default)]
#[serde(rename_all = "snake_case")]
pub enum TypingTool {
@@ -419,6 +429,8 @@ pub struct AppSettings {
pub append_trailing_space: bool,
#[serde(default = "default_app_language")]
pub app_language: String,
+ #[serde(default = "default_theme")]
+ pub theme: Theme,
#[serde(default)]
pub experimental_enabled: bool,
#[serde(default)]
@@ -559,6 +571,10 @@ fn default_sound_theme() -> SoundTheme {
SoundTheme::Marimba
}
+fn default_theme() -> Theme {
+ Theme::System
+}
+
fn default_post_process_enabled() -> bool {
false
}
@@ -862,6 +878,7 @@ pub fn get_default_settings() -> AppSettings {
mute_while_recording: false,
append_trailing_space: false,
app_language: default_app_language(),
+ theme: default_theme(),
experimental_enabled: false,
lazy_stream_close: false,
keyboard_implementation: KeyboardImplementation::default(),
diff --git a/src-tauri/src/shortcut/mod.rs b/src-tauri/src/shortcut/mod.rs
index 18a615fc..e20edfc2 100644
--- a/src-tauri/src/shortcut/mod.rs
+++ b/src-tauri/src/shortcut/mod.rs
@@ -23,7 +23,7 @@ use tauri_plugin_autostart::ManagerExt;
use crate::settings::APPLE_INTELLIGENCE_DEFAULT_MODEL_ID;
use crate::settings::{
self, get_settings, AutoSubmitKey, ClipboardHandling, KeyboardImplementation, LLMPrompt,
- OverlayPosition, OverlayStyle, PasteMethod, ShortcutBinding, SoundTheme, TypingTool,
+ OverlayPosition, OverlayStyle, PasteMethod, ShortcutBinding, SoundTheme, Theme, TypingTool,
APPLE_INTELLIGENCE_PROVIDER_ID,
};
use crate::tray;
@@ -514,6 +514,44 @@ pub fn change_sound_theme_setting(app: AppHandle, theme: String) -> Result<(), S
Ok(())
}
+#[tauri::command]
+#[specta::specta]
+pub fn change_theme_setting(app: AppHandle, theme: String) -> Result<(), String> {
+ let mut settings = settings::get_settings(&app);
+ let parsed = match theme.as_str() {
+ "system" => Theme::System,
+ "light" => Theme::Light,
+ "dark" => Theme::Dark,
+ other => {
+ warn!("Invalid theme '{}', defaulting to system", other);
+ Theme::System
+ }
+ };
+ settings.theme = parsed;
+ settings::write_settings(&app, settings);
+ #[cfg(target_os = "windows")]
+ apply_window_theme(&app, parsed);
+ Ok(())
+}
+
+/// Applies the appearance setting to the Windows title bar, which CSS
+/// `data-theme` cannot reach. `System` clears the override so the window follows
+/// Windows. Call this on startup and whenever the setting changes to keep the
+/// title bar in sync with the in-app palette.
+#[cfg(target_os = "windows")]
+pub fn apply_window_theme(app: &AppHandle, theme: Theme) {
+ let window_theme = match theme {
+ Theme::System => None,
+ Theme::Light => Some(tauri::Theme::Light),
+ Theme::Dark => Some(tauri::Theme::Dark),
+ };
+ if let Some(window) = app.get_webview_window("main") {
+ if let Err(e) = window.set_theme(window_theme) {
+ warn!("Failed to apply window theme: {}", e);
+ }
+ }
+}
+
#[tauri::command]
#[specta::specta]
pub fn change_translate_to_english_setting(app: AppHandle, enabled: bool) -> Result<(), String> {
diff --git a/src/App.css b/src/App.css
index f0d79153..650b809b 100644
--- a/src/App.css
+++ b/src/App.css
@@ -59,6 +59,27 @@
}
}
+/*
+ * Explicit theme override, driven by the `theme` setting via
+ * `document.documentElement.dataset.theme`. When set, the higher-specificity
+ * attribute selectors win over the `prefers-color-scheme` media query above,
+ * so a user can keep Handy light or dark regardless of the OS setting.
+ * `system` (or no attribute) leaves the OS in charge.
+ */
+:root[data-theme="light"] {
+ --color-text: var(--light-color-text);
+ --color-background: var(--light-color-background);
+ --color-logo-primary: var(--light-color-logo-primary);
+ --color-logo-stroke: var(--light-color-logo-stroke);
+}
+
+:root[data-theme="dark"] {
+ --color-text: var(--dark-color-text);
+ --color-background: var(--dark-color-background);
+ --color-logo-primary: var(--dark-color-logo-primary);
+ --color-logo-stroke: var(--dark-color-logo-stroke);
+}
+
/* macOS - tint native overlay scrollbar thumb */
:root[data-platform="macos"] {
scrollbar-color: var(--scrollbar-thumb) transparent;
diff --git a/src/bindings.ts b/src/bindings.ts
index 0f78c3eb..f31c730a 100644
--- a/src/bindings.ts
+++ b/src/bindings.ts
@@ -53,6 +53,14 @@ async changeSoundThemeSetting(theme: string) : Promise<Result<null, string>> {
else return { status: "error", error: e as any };
}
},
+async changeThemeSetting(theme: string) : Promise<Result<null, string>> {
+ try {
+ return { status: "ok", data: await TAURI_INVOKE("change_theme_setting", { theme }) };
+} catch (e) {
+ if(e instanceof Error) throw e;
+ else return { status: "error", error: e as any };
+}
+},
async changeStartHiddenSetting(enabled: boolean) : Promise<Result<null, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("change_start_hidden_setting", { enabled }) };
@@ -897,7 +905,7 @@ bindings?: Partial<{ [key in string]: ShortcutBinding }>; push_to_talk?: boolean
* upgrading from before this key existed are blanked by the migration so they
* see the current release's notes — see `apply_settings_migrations`.
*/
-whats_new_last_seen_version?: string; selected_model?: string; onboarding_completed?: boolean; always_on_microphone?: boolean; selected_microphone?: string | null; clamshell_microphone?: string | null; selected_output_device?: string | null; translate_to_english?: boolean; selected_language?: string; overlay_position?: OverlayPosition; debug_mode?: boolean; log_level?: LogLevel; custom_words?: string[]; model_unload_timeout?: ModelUnloadTimeout; word_correction_threshold?: number; history_limit?: number; recording_retention_period?: RecordingRetentionPeriod; paste_method?: PasteMethod; clipboard_handling?: ClipboardHandling; auto_submit?: boolean; auto_submit_key?: AutoSubmitKey; post_process_enabled?: boolean; post_process_provider_id?: string; post_process_providers?: PostProcessProvider[]; post_process_api_keys?: SecretMap; post_process_models?: Partial<{ [key in string]: string }>; post_process_prompts?: LLMPrompt[]; post_process_selected_prompt_id?: string | null; mute_while_recording?: boolean; append_trailing_space?: boolean; app_language?: string; experimental_enabled?: boolean; lazy_stream_close?: boolean; keyboard_implementation?: KeyboardImplementation; show_tray_icon?: boolean; paste_delay_ms?: number; paste_delay_after_ms?: number; typing_tool?: TypingTool; external_script_path?: string | null; custom_filler_words?: string[] | null; transcribe_accelerator?: TranscribeAcceleratorSetting; ort_accelerator?: OrtAcceleratorSetting; transcribe_gpu_device?: number; extra_recording_buffer_ms?: number; vad_enabled?: boolean;
+whats_new_last_seen_version?: string; selected_model?: string; onboarding_completed?: boolean; always_on_microphone?: boolean; selected_microphone?: string | null; clamshell_microphone?: string | null; selected_output_device?: string | null; translate_to_english?: boolean; selected_language?: string; overlay_position?: OverlayPosition; debug_mode?: boolean; log_level?: LogLevel; custom_words?: string[]; model_unload_timeout?: ModelUnloadTimeout; word_correction_threshold?: number; history_limit?: number; recording_retention_period?: RecordingRetentionPeriod; paste_method?: PasteMethod; clipboard_handling?: ClipboardHandling; auto_submit?: boolean; auto_submit_key?: AutoSubmitKey; post_process_enabled?: boolean; post_process_provider_id?: string; post_process_providers?: PostProcessProvider[]; post_process_api_keys?: SecretMap; post_process_models?: Partial<{ [key in string]: string }>; post_process_prompts?: LLMPrompt[]; post_process_selected_prompt_id?: string | null; mute_while_recording?: boolean; append_trailing_space?: boolean; app_language?: string; theme?: Theme; experimental_enabled?: boolean; lazy_stream_close?: boolean; keyboard_implementation?: KeyboardImplementation; show_tray_icon?: boolean; paste_delay_ms?: number; paste_delay_after_ms?: number; typing_tool?: TypingTool; external_script_path?: string | null; custom_filler_words?: string[] | null; transcribe_accelerator?: TranscribeAcceleratorSetting; ort_accelerator?: OrtAcceleratorSetting; transcribe_gpu_device?: number; extra_recording_buffer_ms?: number; vad_enabled?: boolean;
/**
* Which recording overlay to show: None / Minimal / Live. Streaming mode is
* not gated on this — that follows model capability. Migrated from the old
@@ -1007,6 +1015,11 @@ export type StreamTextEvent = { committed: string; tentative: string }
* Semantic kind of "working" phase, used to localize the spinner label.
*/
export type StreamWorkKind = "transcribing" | "polishing"
+/**
+ * UI appearance mode. `System` follows the OS `prefers-color-scheme`; `Light`
+ * and `Dark` force one of the two palettes Handy already ships.
+ */
+export type Theme = "system" | "light" | "dark"
export type TranscribeAcceleratorSetting = "auto" | "cpu" | "gpu"
export type TypingTool = "auto" | "wtype" | "kwtype" | "dotool" | "ydotool" | "xdotool"
export type WindowsMicrophonePermissionStatus = { supported: boolean; overall_access: PermissionAccess; device_access: PermissionAccess; app_access: PermissionAccess; desktop_app_access: PermissionAccess }
diff --git a/src/components/settings/ThemeSelector.tsx b/src/components/settings/ThemeSelector.tsx
new file mode 100644
index 00000000..3757fc5b
--- /dev/null
+++ b/src/components/settings/ThemeSelector.tsx
@@ -0,0 +1,49 @@
+import React from "react";
+import { useTranslation } from "react-i18next";
+import { Dropdown } from "../ui/Dropdown";
+import { SettingContainer } from "../ui/SettingContainer";
+import { useSettings } from "@/hooks/useSettings";
+import { applyTheme, THEME_OPTIONS } from "@/lib/utils/theme";
+import type { Theme } from "@/bindings";
+
+interface ThemeSelectorProps {
+ descriptionMode?: "inline" | "tooltip";
+ grouped?: boolean;
+}
+
+export const ThemeSelector: React.FC<ThemeSelectorProps> = React.memo(
+ ({ descriptionMode = "tooltip", grouped = false }) => {
+ const { t } = useTranslation();
+ const { settings, updateSetting } = useSettings();
+
+ const currentTheme: Theme = settings?.theme ?? "system";
+
+ const themeOptions = THEME_OPTIONS.map((value) => ({
+ value,
+ label: t(`theme.options.${value}`),
+ }));
+
+ const handleThemeChange = (value: string) => {
+ const theme = value as Theme;
+ applyTheme(theme);
+ updateSetting("theme", theme);
+ };
+
+ return (
+ <SettingContainer
+ title={t("theme.title")}
+ description={t("theme.description")}
+ descriptionMode={descriptionMode}
+ grouped={grouped}
+ >
+ <Dropdown
+ options={themeOptions}
+ selectedValue={currentTheme}
+ onSelect={handleThemeChange}
+ />
+ </SettingContainer>
+ );
+ },
+);
+
+ThemeSelector.displayName = "ThemeSelector";
diff --git a/src/components/settings/about/AboutSettings.tsx b/src/components/settings/about/AboutSettings.tsx
index 8d31d33a..fdeb4df4 100644
--- a/src/components/settings/about/AboutSettings.tsx
+++ b/src/components/settings/about/AboutSettings.tsx
@@ -8,6 +8,7 @@ import { Button } from "../../ui/Button";
import { AppDataDirectory } from "../AppDataDirectory";
import { AppLanguageSelector } from "../AppLanguageSelector";
import { ShowWhatsNewOnUpdate } from "../ShowWhatsNewOnUpdate";
+import { ThemeSelector } from "../ThemeSelector";
import { LogDirectory } from "../debug";
export const AboutSettings: React.FC = () => {
@@ -40,6 +41,7 @@ export const AboutSettings: React.FC = () => {
<div className="max-w-3xl w-full mx-auto space-y-6">
<SettingsGroup title={t("settings.about.title")}>
<AppLanguageSelector descriptionMode="tooltip" grouped={true} />
+ <ThemeSelector descriptionMode="tooltip" grouped={true} />
<SettingContainer
title={t("settings.about.version.title")}
description={t("settings.about.version.description")}
diff --git a/src/i18n/locales/ar/translation.json b/src/i18n/locales/ar/translation.json
index 17dd9a73..8062a9f8 100644
--- a/src/i18n/locales/ar/translation.json
+++ b/src/i18n/locales/ar/translation.json
@@ -618,6 +618,15 @@
"title": "لغة التطبيق",
"description": "تغيير لغة واجهة Handy"
},
+ "theme": {
+ "title": "سمة التطبيق",
+ "description": "اختر ما إذا كان Handy يتبع مظهر النظام أو يبقى فاتحًا أو داكنًا",
+ "options": {
+ "system": "النظام",
+ "light": "فاتح",
+ "dark": "داكن"
+ }
+ },
"overlay": {
"transcribing": "...جاري التفريغ",
"processing": "...جاري المعالجة"
diff --git a/src/i18n/locales/bg/translation.json b/src/i18n/locales/bg/translation.json
index 20011187..302e5c12 100644
--- a/src/i18n/locales/bg/translation.json
+++ b/src/i18n/locales/bg/translation.json
@@ -618,6 +618,15 @@
"title": "Език на приложението",
"description": "Промяна на езика на интерфейса на Handy"
},
+ "theme": {
+ "title": "Тема на приложението",
+ "description": "Изберете дали Handy да следва системната тема, или да остане светла или тъмна",
+ "options": {
+ "system": "Системна",
+ "light": "Светла",
+ "dark": "Тъмна"
+ }
+ },
"overlay": {
"transcribing": "Транскрибиране...",
"processing": "Обработка..."
diff --git a/src/i18n/locales/cs/translation.json b/src/i18n/locales/cs/translation.json
index 8d1b7442..cbdc7561 100644
--- a/src/i18n/locales/cs/translation.json
+++ b/src/i18n/locales/cs/translation.json
@@ -618,6 +618,15 @@
"title": "Jazyk aplikace",
"description": "Změňte jazyk rozhraní Handy"
},
+ "theme": {
+ "title": "Motiv aplikace",
+ "description": "Zvolte, zda má Handy sledovat motiv systému, nebo zůstat světlý či tmavý",
+ "options": {
+ "system": "Systém",
+ "light": "Světlý",
+ "dark": "Tmavý"
+ }
+ },
"overlay": {
"transcribing": "Přepisuji...",
"processing": "Zpracovávám..."
diff --git a/src/i18n/locales/de/translation.json b/src/i18n/locales/de/translation.json
index d44df3f8..dcf04594 100644
--- a/src/i18n/locales/de/translation.json
+++ b/src/i18n/locales/de/translation.json
@@ -618,6 +618,15 @@
"title": "Anwendungssprache",
"description": "Sprache der Handy-Oberfläche ändern"
},
+ "theme": {
+ "title": "Anwendungsdesign",
+ "description": "Wählen Sie, ob Handy dem Systemthema folgt oder hell bzw. dunkel bleibt",
+ "options": {
+ "system": "System",
+ "light": "Hell",
+ "dark": "Dunkel"
+ }
+ },
"overlay": {
"transcribing": "Transkribiere...",
"processing": "Verarbeite..."
diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json
index 43954bbc..b1a8cc19 100644
--- a/src/i18n/locales/en/translation.json
+++ b/src/i18n/locales/en/translation.json
@@ -621,6 +621,15 @@
"title": "Application Language",
"description": "Change the language of the Handy interface"
},
+ "theme": {
+ "title": "Application Theme",
+ "description": "Choose whether Handy follows your system theme or stays light or dark",
+ "options": {
+ "system": "System",
+ "light": "Light",
+ "dark": "Dark"
+ }
+ },
"overlay": {
"transcribing": "Transcribing...",
"processing": "Processing..."
diff --git a/src/i18n/locales/es/translation.json b/src/i18n/locales/es/translation.json
index 935745c7..ee34f552 100644
--- a/src/i18n/locales/es/translation.json
+++ b/src/i18n/locales/es/translation.json
@@ -618,6 +618,15 @@
"title": "Idioma de la aplicación",
"description": "Cambia el idioma de la interfaz de Handy"
},
+ "theme": {
+ "title": "Tema de la aplicación",
+ "description": "Elige si Handy sigue el tema del sistema o permanece claro u oscuro",
+ "options": {
+ "system": "Sistema",
+ "light": "Claro",
+ "dark": "Oscuro"
+ }
+ },
"overlay": {
"transcribing": "Transcribiendo...",
"processing": "Procesando..."
diff --git a/src/i18n/locales/fr/translation.json b/src/i18n/locales/fr/translation.json
index 929fa026..b4bb98a7 100644
--- a/src/i18n/locales/fr/translation.json
+++ b/src/i18n/locales/fr/translation.json
@@ -618,6 +618,15 @@
"title": "Langue de l'application",
"description": "Changer la langue de l'interface de Handy"
},
+ "theme": {
+ "title": "Thème de l'application",
+ "description": "Choisissez si Handy suit le thème du système ou reste clair ou sombre",
+ "options": {
+ "system": "Système",
+ "light": "Clair",
+ "dark": "Sombre"
+ }
+ },
"overlay": {
"transcribing": "Transcription...",
"processing": "Traitement..."
diff --git a/src/i18n/locales/he/translation.json b/src/i18n/locales/he/translation.json
index 36d9ad08..dc3dcc80 100644
--- a/src/i18n/locales/he/translation.json
+++ b/src/i18n/locales/he/translation.json
@@ -618,6 +618,15 @@
"title": "שפת האפליקציה",
"description": "שנה את שפת הממשק של Handy"
},
+ "theme": {
+ "title": "ערכת נושא של האפליקציה",
+ "description": "בחר אם Handy יעקוב אחר ערכת הנושא של המערכת או יישאר בהיר או כהה",
+ "options": {
+ "system": "מערכת",
+ "light": "בהיר",
+ "dark": "כהה"
+ }
+ },
"overlay": {
"transcribing": "מתמלל...",
"processing": "מעבד..."
diff --git a/src/i18n/locales/it/translation.json b/src/i18n/locales/it/translation.json
index 63dec463..91df17b0 100644
--- a/src/i18n/locales/it/translation.json
+++ b/src/i18n/locales/it/translation.json
@@ -618,6 +618,15 @@
"title": "Lingua Applicazione",
"description": "Cambia la lingua dell'interfaccia di Handy"
},
+ "theme": {
+ "title": "Tema dell'applicazione",
+ "description": "Scegli se Handy segue il tema di sistema o resta chiaro o scuro",
+ "options": {
+ "system": "Sistema",
+ "light": "Chiaro",
+ "dark": "Scuro"
+ }
+ },
"overlay": {
"transcribing": "Trascrizione...",
"processing": "Elaborazione..."
diff --git a/src/i18n/locales/ja/translation.json b/src/i18n/locales/ja/translation.json
index fdbf763e..560e798c 100644
--- a/src/i18n/locales/ja/translation.json
+++ b/src/i18n/locales/ja/translation.json
@@ -618,6 +618,15 @@
"title": "アプリの言語",
"description": "Handy インターフェースの言語を変更"
},
+ "theme": {
+ "title": "アプリのテーマ",
+ "description": "Handy をシステムのテーマに合わせるか、ライトまたはダークで固定するかを選択します",
+ "options": {
+ "system": "システム",
+ "light": "ライト",
+ "dark": "ダーク"
+ }
+ },
"overlay": {
"transcribing": "文字起こし中…",
"processing": "処理中…"
diff --git a/src/i18n/locales/ko/translation.json b/src/i18n/locales/ko/translation.json
index 11ef6468..8392596e 100644
--- a/src/i18n/locales/ko/translation.json
+++ b/src/i18n/locales/ko/translation.json
@@ -618,6 +618,15 @@
"title": "애플리케이션 언어",
"description": "Handy 인터페이스의 언어를 변경하세요"
},
+ "theme": {
+ "title": "앱 테마",
+ "description": "Handy가 시스템 테마를 따를지, 밝게 또는 어둡게 유지할지 선택하세요",
+ "options": {
+ "system": "시스템",
+ "light": "밝게",
+ "dark": "어둡게"
+ }
+ },
"overlay": {
"transcribing": "텍스트로 변환 중...",
"processing": "처리 중..."
diff --git a/src/i18n/locales/ne/translation.json b/src/i18n/locales/ne/translation.json
index 51c03f14..6a4a7b20 100644
--- a/src/i18n/locales/ne/translation.json
+++ b/src/i18n/locales/ne/translation.json
@@ -621,6 +621,15 @@
"title": "एपको भाषा",
"description": "Handy इन्टरफेसको भाषा परिवर्तन गर्नुहोस्"
},
+ "theme": {
+ "title": "अनुप्रयोगको थिम",
+ "description": "Handy ले तपाईंको सिस्टम थिम अनुसरण गर्ने वा उज्यालो वा अँध्यारो रहने छान्नुहोस्",
+ "options": {
+ "system": "सिस्टम",
+ "light": "उज्यालो",
+ "dark": "अँध्यारो"
+ }
+ },
"overlay": {
"transcribing": "ट्रान्सक्राइब गरिँदैछ...",
"processing": "प्रशोधन गरिँदैछ..."
diff --git a/src/i18n/locales/nl/translation.json b/src/i18n/locales/nl/translation.json
index dd234959..9ebbfe5d 100644
--- a/src/i18n/locales/nl/translation.json
+++ b/src/i18n/locales/nl/translation.json
@@ -621,6 +621,15 @@
"title": "Interfacetaal",
"description": "Wijzig de taal van de Handy-interface"
},
+ "theme": {
+ "title": "App-thema",
+ "description": "Kies of Handy het systeemthema volgt of licht of donker blijft",
+ "options": {
+ "system": "Systeem",
+ "light": "Licht",
+ "dark": "Donker"
+ }
+ },
"overlay": {
"transcribing": "Transcriberen...",
"processing": "Verwerken..."
diff --git a/src/i18n/locales/pl/translation.json b/src/i18n/locales/pl/translation.json
index d65bf9f2..eab79049 100644
--- a/src/i18n/locales/pl/translation.json
+++ b/src/i18n/locales/pl/translation.json
@@ -618,6 +618,15 @@
"title": "Język aplikacji",
"description": "Zmień język interfejsu Handy"
},
+ "theme": {
+ "title": "Motyw aplikacji",
+ "description": "Wybierz, czy Handy ma podążać za motywem systemu, czy pozostać jasny lub ciemny",
+ "options": {
+ "system": "System",
+ "light": "Jasny",
+ "dark": "Ciemny"
+ }
+ },
"overlay": {
"transcribing": "Transkrypcja...",
"processing": "Przetwarzanie..."
diff --git a/src/i18n/locales/pt/translation.json b/src/i18n/locales/pt/translation.json
index 235447b0..6156a7a0 100644
--- a/src/i18n/locales/pt/translation.json
+++ b/src/i18n/locales/pt/translation.json
@@ -618,6 +618,15 @@
"title": "Idioma da Aplicação",
"description": "Alterar o idioma da interface do Handy"
},
+ "theme": {
+ "title": "Tema do aplicativo",
+ "description": "Escolha se o Handy segue o tema do sistema ou permanece claro ou escuro",
+ "options": {
+ "system": "Sistema",
+ "light": "Claro",
+ "dark": "Escuro"
+ }
+ },
"overlay": {
"transcribing": "Transcrevendo...",
"processing": "Processando..."
diff --git a/src/i18n/locales/ru/translation.json b/src/i18n/locales/ru/translation.json
index b749abce..06ef999b 100644
--- a/src/i18n/locales/ru/translation.json
+++ b/src/i18n/locales/ru/translation.json
@@ -618,6 +618,15 @@
"title": "Язык приложения",
"description": "Изменить язык интерфейса Handy"
},
+ "theme": {
+ "title": "Тема приложения",
+ "description": "Выберите, следует ли Handy системной теме или остаётся светлым либо тёмным",
+ "options": {
+ "system": "Системная",
+ "light": "Светлая",
+ "dark": "Тёмная"
+ }
+ },
"overlay": {
"transcribing": "Расшифровка...",
"processing": "Обработка..."
diff --git a/src/i18n/locales/sv/translation.json b/src/i18n/locales/sv/translation.json
index 345b06ac..a86aadb1 100644
--- a/src/i18n/locales/sv/translation.json
+++ b/src/i18n/locales/sv/translation.json
@@ -618,6 +618,15 @@
"title": "Applikationsspråk",
"description": "Ändra språket i Handy-gränssnittet"
},
+ "theme": {
+ "title": "Apptema",
+ "description": "Välj om Handy ska följa systemets tema eller förbli ljust eller mörkt",
+ "options": {
+ "system": "System",
+ "light": "Ljust",
+ "dark": "Mörkt"
+ }
+ },
"overlay": {
"transcribing": "Transkriberar...",
"processing": "Bearbetar..."
diff --git a/src/i18n/locales/tr/translation.json b/src/i18n/locales/tr/translation.json
index 944e3f65..22d9e0b1 100644
--- a/src/i18n/locales/tr/translation.json
+++ b/src/i18n/locales/tr/translation.json
@@ -618,6 +618,15 @@
"title": "Uygulama Dili",
"description": "Handy arayüzünün dilini değiştirin"
},
+ "theme": {
+ "title": "Uygulama teması",
+ "description": "Handy'nin sistem temasını izlemesini ya da açık veya koyu kalmasını seçin",
+ "options": {
+ "system": "Sistem",
+ "light": "Açık",
+ "dark": "Koyu"
+ }
+ },
"overlay": {
"transcribing": "Transkribe ediliyor...",
"processing": "İşleniyor..."
diff --git a/src/i18n/locales/uk/translation.json b/src/i18n/locales/uk/translation.json
index a4d03580..5c0d913d 100644
--- a/src/i18n/locales/uk/translation.json
+++ b/src/i18n/locales/uk/translation.json
@@ -618,6 +618,15 @@
"title": "Мова інтерфейсу",
"description": "Змінити мову інтерфейсу Handy"
},
+ "theme": {
+ "title": "Тема застосунку",
+ "description": "Виберіть, чи має Handy слідувати темі системи, чи залишатися світлою або темною",
+ "options": {
+ "system": "Системна",
+ "light": "Світла",
+ "dark": "Темна"
+ }
+ },
"overlay": {
"transcribing": "Обробка...",
"processing": "Постобробка..."
diff --git a/src/i18n/locales/vi/translation.json b/src/i18n/locales/vi/translation.json
index dc25cda9..332a20b6 100644
--- a/src/i18n/locales/vi/translation.json
+++ b/src/i18n/locales/vi/translation.json
@@ -618,6 +618,15 @@
"title": "Ngôn ngữ ứng dụng",
"description": "Thay đổi ngôn ngữ giao diện của Handy"
},
+ "theme": {
+ "title": "Giao diện ứng dụng",
+ "description": "Chọn xem Handy theo chủ đề hệ thống hay giữ ở chế độ sáng hoặc tối",
+ "options": {
+ "system": "Hệ thống",
+ "light": "Sáng",
+ "dark": "Tối"
+ }
+ },
"overlay": {
"transcribing": "Đang chuyển đổi...",
"processing": "Đang xử lý..."
diff --git a/src/i18n/locales/zh-TW/translation.json b/src/i18n/locales/zh-TW/translation.json
index bde58b36..c08e8504 100644
--- a/src/i18n/locales/zh-TW/translation.json
+++ b/src/i18n/locales/zh-TW/translation.json
@@ -618,6 +618,15 @@
"title": "應用程式語言",
"description": "變更 Handy 介面的語言"
},
+ "theme": {
+ "title": "應用程式主題",
+ "description": "選擇 Handy 跟隨系統主題,或維持淺色或深色",
+ "options": {
+ "system": "跟隨系統",
+ "light": "淺色",
+ "dark": "深色"
+ }
+ },
"overlay": {
"transcribing": "正在轉錄...",
"processing": "處理中..."
diff --git a/src/i18n/locales/zh/translation.json b/src/i18n/locales/zh/translation.json
index fe9b0250..a239dca7 100644
--- a/src/i18n/locales/zh/translation.json
+++ b/src/i18n/locales/zh/translation.json
@@ -618,6 +618,15 @@
"title": "应用语言",
"description": "更改 Handy 界面的语言"
},
+ "theme": {
+ "title": "应用主题",
+ "description": "选择 Handy 跟随系统主题,还是保持浅色或深色",
+ "options": {
+ "system": "跟随系统",
+ "light": "浅色",
+ "dark": "深色"
+ }
+ },
"overlay": {
"transcribing": "正在转录...",
"processing": "处理中..."
diff --git a/src/lib/utils/theme.ts b/src/lib/utils/theme.ts
new file mode 100644
index 00000000..fb55e57e
--- /dev/null
+++ b/src/lib/utils/theme.ts
@@ -0,0 +1,63 @@
+import { commands, type Theme } from "@/bindings";
+
+/**
+ * Appearance theme handling.
+ *
+ * Handy already ships a full light palette and a full dark palette (see
+ * `App.css`). This module lets the user pick which one is used instead of
+ * always following the OS:
+ * - `system` removes the override so the `prefers-color-scheme` media query
+ * governs (the historical behaviour).
+ * - `light` / `dark` set `data-theme` on the document root, whose
+ * higher-specificity CSS selectors win over the media query.
+ *
+ * The choice is persisted in `AppSettings` (source of truth) and mirrored to
+ * localStorage so it can be applied synchronously on boot, before React mounts,
+ * avoiding a flash of the wrong palette.
+ */
+
+export const THEME_STORAGE_KEY = "handy.theme";
+
+export const THEME_OPTIONS: Theme[] = ["system", "light", "dark"];
+
+const isTheme = (value: unknown): value is Theme =>
+ value === "system" || value === "light" || value === "dark";
+
+/** Apply a theme to the document root and remember it for the next launch. */
+export const applyTheme = (theme: Theme): void => {
+ const root = document.documentElement;
+ if (theme === "system") {
+ delete root.dataset.theme;
+ } else {
+ root.dataset.theme = theme;
+ }
+ try {
+ localStorage.setItem(THEME_STORAGE_KEY, theme);
+ } catch {
+ // localStorage may be unavailable (e.g. private mode); the setting still
+ // persists in AppSettings, so this only costs a one-frame flash on boot.
+ }
+};
+
+/** Read the last-applied theme for synchronous boot-time application. */
+export const getStoredTheme = (): Theme => {
+ try {
+ const stored = localStorage.getItem(THEME_STORAGE_KEY);
+ if (isTheme(stored)) return stored;
+ } catch {
+ // ignore
+ }
+ return "system";
+};
+
+/** Apply the persisted theme from AppSettings (the source of truth). */
+export const syncThemeFromSettings = async (): Promise<void> => {
+ try {
+ const result = await commands.getAppSettings();
+ if (result.status === "ok") {
+ applyTheme(result.data.theme ?? "system");
+ }
+ } catch (e) {
+ console.warn("Failed to sync theme from settings:", e);
+ }
+};
diff --git a/src/main.tsx b/src/main.tsx
index 1e83ae74..3cd2ed60 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -2,10 +2,20 @@ import React from "react";
import ReactDOM from "react-dom/client";
import { platform } from "@tauri-apps/plugin-os";
import App from "./App";
+import {
+ applyTheme,
+ getStoredTheme,
+ syncThemeFromSettings,
+} from "./lib/utils/theme";
// Set platform before render so CSS can scope per-platform (e.g. scrollbar styles)
document.documentElement.dataset.platform = platform();
+// Apply the last-known theme synchronously before render to avoid a flash of
+// the wrong palette, then reconcile with the persisted setting once it loads.
+applyTheme(getStoredTheme());
+syncThemeFromSettings();
+
// Initialize i18n
import "./i18n";
diff --git a/src/stores/settingsStore.ts b/src/stores/settingsStore.ts
index 744f9daf..b4e04282 100644
--- a/src/stores/settingsStore.ts
+++ b/src/stores/settingsStore.ts
@@ -145,6 +145,7 @@ const settingUpdaters: {
commands.changeAppendTrailingSpaceSetting(value as boolean),
log_level: (value) => commands.setLogLevel(value as any),
app_language: (value) => commands.changeAppLanguageSetting(value as string),
+ theme: (value) => commands.changeThemeSetting(value as string),
experimental_enabled: (value) =>
commands.changeExperimentalEnabledSetting(value as boolean),
lazy_stream_close: (value) =>
diff --git a/src/styles/theme.css b/src/styles/theme.css
index 401e00db..2494b5b0 100644
--- a/src/styles/theme.css
+++ b/src/styles/theme.css
@@ -1,20 +1,37 @@
/* Handy Colors */
:root {
- --color-text: #0f0f0f;
- --color-background: #fbfbfb;
+ /* Palette source of truth. Each themed color is defined once as a
+ light/dark pair; the active tokens below and the `data-theme` overrides
+ in App.css reference these, so a hex value lives in exactly one place. */
+ --light-color-text: #0f0f0f;
+ --light-color-background: #fbfbfb;
+ --light-color-logo-primary: #faa2ca;
+ --light-color-logo-stroke: #382731;
+
+ --dark-color-text: #fbfbfb;
+ --dark-color-background: #2c2b29;
+ --dark-color-logo-primary: #f28cbb;
+ --dark-color-logo-stroke: #fad1ed;
+
+ /* Tokens that do not change between light and dark */
--color-background-ui: #da5893;
- --color-logo-primary: #faa2ca;
- --color-logo-stroke: #382731;
--color-text-stroke: #f6f6f6;
--color-mid-gray: #808080;
+
+ /* Active palette — defaults to light, follows the OS via the media query
+ below, or is forced by `data-theme` (see App.css). */
+ --color-text: var(--light-color-text);
+ --color-background: var(--light-color-background);
+ --color-logo-primary: var(--light-color-logo-primary);
+ --color-logo-stroke: var(--light-color-logo-stroke);
}
@media (prefers-color-scheme: dark) {
:root {
- --color-text: #fbfbfb;
- --color-background: #2c2b29;
- --color-logo-primary: #f28cbb;
- --color-logo-stroke: #fad1ed;
+ --color-text: var(--dark-color-text);
+ --color-background: var(--dark-color-background);
+ --color-logo-primary: var(--dark-color-logo-primary);
+ --color-logo-stroke: var(--dark-color-logo-stroke);
}
}