diff --git a/src-tauri/src/core/tray.rs b/src-tauri/src/core/tray.rs index 0398735..dd48b56 100644 --- a/src-tauri/src/core/tray.rs +++ b/src-tauri/src/core/tray.rs @@ -141,7 +141,7 @@ impl Tray { "restart_clash" => feat::restart_clash_core(), "restart_app" => api::process::restart(&app_handle.env()), "quit" => { - let _ = resolve::save_window_size_position(app_handle); + let _ = resolve::save_window_size_position(app_handle, true); resolve::resolve_reset(); api::process::kill_children(); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index a5d2efa..59903db 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -109,7 +109,7 @@ fn main() -> std::io::Result<()> { match event { tauri::WindowEvent::CloseRequested { api, .. } => { api.prevent_close(); - let _ = resolve::save_window_size_position(&app_handle); + let _ = resolve::save_window_size_position(&app_handle, true); app_handle.get_window("main").map(|win| { let _ = win.hide(); @@ -121,12 +121,13 @@ fn main() -> std::io::Result<()> { } #[cfg(not(target_os = "macos"))] tauri::RunEvent::WindowEvent { label, event, .. } => { - use tauri::Manager; - if label == "main" { match event { tauri::WindowEvent::CloseRequested { .. } => { - let _ = resolve::save_window_size_position(&app_handle); + let _ = resolve::save_window_size_position(&app_handle, true); + } + tauri::WindowEvent::Moved(_) | tauri::WindowEvent::Resized(_) => { + let _ = resolve::save_window_size_position(&app_handle, false); } _ => {} } diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index d7ac245..8d80ece 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -127,7 +127,7 @@ pub fn create_window(app_handle: &AppHandle) { } /// save window size and position -pub fn save_window_size_position(app_handle: &AppHandle) -> Result<()> { +pub fn save_window_size_position(app_handle: &AppHandle, save_to_file: bool) -> Result<()> { let win = app_handle .get_window("main") .ok_or(anyhow::anyhow!("failed to get window"))?; @@ -141,7 +141,10 @@ pub fn save_window_size_position(app_handle: &AppHandle) -> Result<()> { let verge = Config::verge(); let mut verge = verge.latest(); verge.window_size_position = Some(vec![size.width, size.height, pos.x, pos.y]); - verge.save_file()?; + + if save_to_file { + verge.save_file()?; + } Ok(()) }