diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rs index 3c0a831..4978f57 100644 --- a/src-tauri/src/app/menu.rs +++ b/src-tauri/src/app/menu.rs @@ -68,6 +68,14 @@ pub fn init() -> Menu { titlebar }; + let system_tray = + CustomMenuItem::new("system_tray".to_string(), "System Tray"); + let system_tray_menu = if chat_conf.tray { + system_tray.selected() + } else { + system_tray + }; + let preferences_menu = Submenu::new( "Preferences", Menu::with_items([ @@ -80,6 +88,7 @@ pub fn init() -> Menu { titlebar_menu.into(), #[cfg(target_os = "macos")] CustomMenuItem::new("hide_dock_icon".to_string(), "Hide Dock Icon").into(), + system_tray_menu.into(), CustomMenuItem::new("inject_script".to_string(), "Inject Script") .accelerator("CmdOrCtrl+J") .into(), @@ -280,6 +289,15 @@ pub fn menu_handler(event: WindowMenuEvent) { .unwrap(); tauri::api::process::restart(&app.env()); } + "system_tray" => { + let chat_conf = conf::ChatConfJson::get_chat_conf(); + ChatConfJson::amend( + &serde_json::json!({ "tray": !chat_conf.tray }), + None, + ) + .unwrap(); + tauri::api::process::restart(&app.env()); + } "theme_light" | "theme_dark" | "theme_system" => { let theme = match menu_id { "theme_dark" => "Dark", diff --git a/src-tauri/src/conf.rs b/src-tauri/src/conf.rs index e2ba14a..21a204c 100644 --- a/src-tauri/src/conf.rs +++ b/src-tauri/src/conf.rs @@ -20,6 +20,7 @@ pub const DEFAULT_CHAT_CONF: &str = r#"{ "stay_on_top": false, "auto_update": "Prompt", "theme": "Light", + "tray": true, "titlebar": true, "popup_search": true, "global_shortcut": "", @@ -33,6 +34,7 @@ pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{ "stay_on_top": false, "auto_update": "Prompt", "theme": "Light", + "tray": true, "titlebar": false, "popup_search": true, "global_shortcut": "", @@ -53,6 +55,7 @@ pub struct ChatConfJson { pub theme: String, // auto update policy, Prompt/Silent/Disable pub auto_update: String, + pub tray: bool, pub popup_search: bool, pub stay_on_top: bool, pub default_origin: String,