diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2bb7c08..3093a68 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -27,7 +27,7 @@ regex = "1.7.0" tokio = { version = "1.23.0", features = ["macros"] } reqwest = "0.11.13" wry = "0.23.4" - +dark-light = "1.0.0" [dependencies.tauri-plugin-log] git = "https://github.com/tauri-apps/tauri-plugin-log" branch = "dev" diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rs index 58ced06..7fe9b6e 100644 --- a/src-tauri/src/app/menu.rs +++ b/src-tauri/src/app/menu.rs @@ -41,7 +41,9 @@ pub fn init() -> Menu { CustomMenuItem::new("titlebar".to_string(), "Titlebar").accelerator("CmdOrCtrl+B"); let theme_light = CustomMenuItem::new("theme_light".to_string(), "Light"); let theme_dark = CustomMenuItem::new("theme_dark".to_string(), "Dark"); + let theme_system = CustomMenuItem::new("theme_system".to_string(), "System"); let is_dark = chat_conf.theme == "Dark"; + let is_system = chat_conf.theme == "System"; let stay_on_top_menu = if chat_conf.stay_on_top { stay_on_top.selected() @@ -65,7 +67,7 @@ pub fn init() -> Menu { Submenu::new( "Theme", Menu::new() - .add_item(if is_dark { + .add_item(if is_dark || is_system { theme_light } else { theme_light.selected() @@ -74,6 +76,11 @@ pub fn init() -> Menu { theme_dark.selected() } else { theme_dark + }) + .add_item(if is_system { + theme_system.selected() + } else { + theme_system }), ) .into(), @@ -230,9 +237,11 @@ pub fn menu_handler(event: WindowMenuEvent) { .unwrap(); tauri::api::process::restart(&app.env()); } - "theme_light" | "theme_dark" => { + "theme_light" | "theme_dark" | "theme_system" => { let theme = if menu_id == "theme_dark" { "Dark" + } else if menu_id == "theme_system" { + "System" } else { "Light" }; diff --git a/src-tauri/src/conf.rs b/src-tauri/src/conf.rs index 8c07c1b..7153908 100644 --- a/src-tauri/src/conf.rs +++ b/src-tauri/src/conf.rs @@ -177,7 +177,17 @@ impl ChatConfJson { pub fn theme() -> Option { let conf = ChatConfJson::get_chat_conf(); - if conf.theme == "Dark" { + if conf.theme == "System" { + let mode = dark_light::detect(); + return match mode { + // Dark mode + dark_light::Mode::Dark => Some(Theme::Dark), + // Light mode + dark_light::Mode::Light => Some(Theme::Light), + // Unspecified + dark_light::Mode::Default => Some(Theme::Light), + } + } if conf.theme == "Dark" { Some(Theme::Dark) } else { Some(Theme::Light) diff --git a/src/view/General.tsx b/src/view/General.tsx index b231cd9..084c947 100644 --- a/src/view/General.tsx +++ b/src/view/General.tsx @@ -111,6 +111,11 @@ export default function General() { Light Dark + { + (["darwin", "windows"].includes(platformInfo) ) && ( + System + ) + }