diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs index 5907cf4..10548bd 100644 --- a/src-tauri/src/core/mod.rs +++ b/src-tauri/src/core/mod.rs @@ -93,7 +93,7 @@ impl Core { if silent_start.unwrap_or(false) { let window = self.window.lock(); window.as_ref().map(|win| { - win.hide().unwrap(); + win.close().unwrap(); }); } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0cec26d..ad4d70b 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -44,10 +44,23 @@ fn main() -> std::io::Result<()> { .on_system_tray_event(move |app_handle, event| match event { SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { "open_window" => { - let window = app_handle.get_window("main").unwrap(); - window.unminimize().unwrap(); - window.show().unwrap(); - window.set_focus().unwrap(); + tauri::window::WindowBuilder::new( + app_handle, + "main".to_string(), + tauri::WindowUrl::App("index.html".into()), + ) + .title("Clash Verge") + .center() + .decorations(false) + .fullscreen(false) + .inner_size(800.0, 636.0) + .min_inner_size(600.0, 520.0) + .build() + .err() + .and_then(|e| { + log::error!("{e}"); + Some(0) + }); } "system_proxy" => { let core = app_handle.state::(); @@ -156,17 +169,8 @@ fn main() -> std::io::Result<()> { .build(tauri::generate_context!()) .expect("error while running tauri application") .run(|app_handle, e| match e { - tauri::RunEvent::WindowEvent { label, event, .. } => match event { - tauri::WindowEvent::CloseRequested { api, .. } => { - let app_handle = app_handle.clone(); - api.prevent_close(); - app_handle.get_window(&label).unwrap().hide().unwrap(); - } - _ => {} - }, tauri::RunEvent::ExitRequested { .. } => { - resolve::resolve_reset(app_handle); - api::process::kill_children(); + api.prevent_exit(); } tauri::RunEvent::Exit => { resolve::resolve_reset(app_handle); diff --git a/src/components/layout/layout-control.tsx b/src/components/layout/layout-control.tsx index 0bba354..379527b 100644 --- a/src/components/layout/layout-control.tsx +++ b/src/components/layout/layout-control.tsx @@ -30,7 +30,7 @@ const LayoutControl = () => { diff --git a/src/pages/_layout.tsx b/src/pages/_layout.tsx index 6fa1498..58e1c1f 100644 --- a/src/pages/_layout.tsx +++ b/src/pages/_layout.tsx @@ -35,7 +35,7 @@ const Layout = () => { useEffect(() => { window.addEventListener("keydown", (e) => { - if (e.key === "Escape") appWindow.hide(); + if (e.key === "Escape") appWindow.close(); }); listen("verge://refresh-clash-config", async () => {