chore: window

This commit is contained in:
lencx
2023-01-01 16:21:20 +08:00
parent e2235e7060
commit 4c86477d6f
3 changed files with 40 additions and 12 deletions

View File

@@ -1,5 +1,10 @@
# UPDATE LOG # UPDATE LOG
## v0.7.5
fix:
- close the main window and hide it in the tray (windows systems)
## v0.7.4 ## v0.7.4
fix: fix:

View File

@@ -293,12 +293,13 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
// --- SystemTray Menu // --- SystemTray Menu
pub fn tray_menu() -> SystemTray { pub fn tray_menu() -> SystemTray {
if cfg!(target_os = "macos") { if cfg!(target_os = "macos") {
return SystemTray::new().with_menu( SystemTray::new().with_menu(
SystemTrayMenu::new() SystemTrayMenu::new()
.add_item(CustomMenuItem::new( .add_item(CustomMenuItem::new(
"control_center".to_string(), "control_center".to_string(),
"Control Center", "Control Center",
)) ))
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(CustomMenuItem::new( .add_item(CustomMenuItem::new(
"show_dock_icon".to_string(), "show_dock_icon".to_string(),
"Show Dock Icon", "Show Dock Icon",
@@ -307,20 +308,28 @@ pub fn tray_menu() -> SystemTray {
"hide_dock_icon".to_string(), "hide_dock_icon".to_string(),
"Hide Dock Icon", "Hide Dock Icon",
)) ))
.add_item(CustomMenuItem::new(
"show_core".to_string(),
"Show ChatGPT",
))
.add_native_item(SystemTrayMenuItem::Separator) .add_native_item(SystemTrayMenuItem::Separator)
.add_item(CustomMenuItem::new("quit".to_string(), "Quit ChatGPT")), .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 // --- SystemTray Event
@@ -361,6 +370,15 @@ pub fn tray_handler(handle: &AppHandle, event: SystemTrayEvent) {
.unwrap(); .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), "quit" => std::process::exit(0),
_ => (), _ => (),
}, },

View File

@@ -82,7 +82,12 @@ async fn main() {
// TODO: https://github.com/tauri-apps/tauri/issues/3084 // TODO: https://github.com/tauri-apps/tauri/issues/3084
// event.window().hide().unwrap(); // event.window().hide().unwrap();
// https://github.com/tauri-apps/tao/pull/517 // https://github.com/tauri-apps/tao/pull/517
#[cfg(target_os = "macos")]
event.window().minimize().unwrap(); event.window().minimize().unwrap();
// fix: https://github.com/lencx/ChatGPT/issues/93
#[cfg(not(target_os = "macos"))]
event.window().hide().unwrap();
} }
api.prevent_close(); api.prevent_close();
} }