diff --git a/src-tauri/src/core/handle.rs b/src-tauri/src/core/handle.rs index 19eed0e..0b48700 100644 --- a/src-tauri/src/core/handle.rs +++ b/src-tauri/src/core/handle.rs @@ -30,9 +30,12 @@ impl Handle { } pub fn get_window(&self) -> Option { - self.app_handle() - .as_ref() - .and_then(|a| a.get_webview_window("main")) + let app_handle = self.app_handle().unwrap(); + let window: Option = app_handle.get_webview_window("main"); + if window.is_none() { + log::debug!(target:"app", "main window not found"); + } + window } pub fn refresh_clash() { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f972c67..efa8d1b 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -141,8 +141,11 @@ pub fn run() { tauri::RunEvent::WindowEvent { label, event, .. } => { if label == "main" { match event { - tauri::WindowEvent::CloseRequested { .. } => { + tauri::WindowEvent::CloseRequested { api, .. } => { println!("closing window..."); + api.prevent_close(); + let window = core::handle::Handle::global().get_window().unwrap(); + log_err!(window.minimize()); let _ = resolve::save_window_size_position(true); } tauri::WindowEvent::Moved(_) | tauri::WindowEvent::Resized(_) => {