fix: save window size and pos in Windows

This commit is contained in:
GyDi 2023-07-22 13:13:16 +08:00
parent 177a22df59
commit 4f158a4829
No known key found for this signature in database
GPG Key ID: B28E790B95193457
3 changed files with 11 additions and 7 deletions

View File

@ -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();

View File

@ -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);
}
_ => {}
}

View File

@ -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(())
}