From ac884da56bbfed11a155ada1d542c460f039ffb1 Mon Sep 17 00:00:00 2001 From: huzibaca Date: Wed, 30 Oct 2024 06:27:29 +0800 Subject: [PATCH] fix: performance issues caused by closing windows on mac --- src-tauri/src/core/handle.rs | 9 ++++++--- src-tauri/src/lib.rs | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/core/handle.rs b/src-tauri/src/core/handle.rs index 19eed0ee..0b487007 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 f972c67a..efa8d1bc 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(_) => {