From 4c86477d6f4d6b29f71b2943b4bde194c2c6f252 Mon Sep 17 00:00:00 2001 From: lencx Date: Sun, 1 Jan 2023 16:21:20 +0800 Subject: [PATCH] chore: window --- UPDATE_LOG.md | 5 +++++ src-tauri/src/app/menu.rs | 42 ++++++++++++++++++++++++++++----------- src-tauri/src/main.rs | 5 +++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/UPDATE_LOG.md b/UPDATE_LOG.md index 8a6b166..0c12a73 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -1,5 +1,10 @@ # UPDATE LOG +## v0.7.5 + +fix: +- close the main window and hide it in the tray (windows systems) + ## v0.7.4 fix: diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rs index 7fe9b6e..0c948f1 100644 --- a/src-tauri/src/app/menu.rs +++ b/src-tauri/src/app/menu.rs @@ -293,12 +293,13 @@ pub fn menu_handler(event: WindowMenuEvent) { // --- SystemTray Menu pub fn tray_menu() -> SystemTray { if cfg!(target_os = "macos") { - return SystemTray::new().with_menu( + SystemTray::new().with_menu( SystemTrayMenu::new() .add_item(CustomMenuItem::new( "control_center".to_string(), "Control Center", )) + .add_native_item(SystemTrayMenuItem::Separator) .add_item(CustomMenuItem::new( "show_dock_icon".to_string(), "Show Dock Icon", @@ -307,20 +308,28 @@ pub fn tray_menu() -> SystemTray { "hide_dock_icon".to_string(), "Hide Dock Icon", )) + .add_item(CustomMenuItem::new( + "show_core".to_string(), + "Show ChatGPT", + )) .add_native_item(SystemTrayMenuItem::Separator) .add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")), - ); + ) + } else { + SystemTray::new().with_menu( + SystemTrayMenu::new() + .add_item(CustomMenuItem::new( + "control_center".to_string(), + "Control Center", + )) + .add_item(CustomMenuItem::new( + "show_core".to_string(), + "Show ChatGPT", + )) + .add_native_item(SystemTrayMenuItem::Separator) + .add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")), + ) } - - SystemTray::new().with_menu( - SystemTrayMenu::new() - .add_item(CustomMenuItem::new( - "control_center".to_string(), - "Control Center", - )) - .add_native_item(SystemTrayMenuItem::Separator) - .add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")), - ) } // --- SystemTray Event @@ -361,6 +370,15 @@ pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) { .unwrap(); } } + "show_core" => { + let core_win = app.get_window("core").unwrap(); + let tray_win = app.get_window("tray").unwrap(); + if !core_win.is_visible().unwrap() { + core_win.show().unwrap(); + core_win.set_focus().unwrap(); + tray_win.hide().unwrap(); + } + } "quit" => std::process::exit(0), _ => (), }, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0db83a4..82ebd8d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -82,7 +82,12 @@ async fn main() { // TODO: https://github.com/tauri-apps/tauri/issues/3084 // event.window().hide().unwrap(); // https://github.com/tauri-apps/tao/pull/517 + #[cfg(target_os = "macos")] event.window().minimize().unwrap(); + + // fix: https://github.com/lencx/ChatGPT/issues/93 + #[cfg(not(target_os = "macos"))] + event.window().hide().unwrap(); } api.prevent_close(); }