fix: save window size and pos in Windows
This commit is contained in:
parent
177a22df59
commit
4f158a4829
@ -141,7 +141,7 @@ impl Tray {
|
|||||||
"restart_clash" => feat::restart_clash_core(),
|
"restart_clash" => feat::restart_clash_core(),
|
||||||
"restart_app" => api::process::restart(&app_handle.env()),
|
"restart_app" => api::process::restart(&app_handle.env()),
|
||||||
"quit" => {
|
"quit" => {
|
||||||
let _ = resolve::save_window_size_position(app_handle);
|
let _ = resolve::save_window_size_position(app_handle, true);
|
||||||
|
|
||||||
resolve::resolve_reset();
|
resolve::resolve_reset();
|
||||||
api::process::kill_children();
|
api::process::kill_children();
|
||||||
|
@ -109,7 +109,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
match event {
|
match event {
|
||||||
tauri::WindowEvent::CloseRequested { api, .. } => {
|
tauri::WindowEvent::CloseRequested { api, .. } => {
|
||||||
api.prevent_close();
|
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| {
|
app_handle.get_window("main").map(|win| {
|
||||||
let _ = win.hide();
|
let _ = win.hide();
|
||||||
@ -121,12 +121,13 @@ fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
tauri::RunEvent::WindowEvent { label, event, .. } => {
|
tauri::RunEvent::WindowEvent { label, event, .. } => {
|
||||||
use tauri::Manager;
|
|
||||||
|
|
||||||
if label == "main" {
|
if label == "main" {
|
||||||
match event {
|
match event {
|
||||||
tauri::WindowEvent::CloseRequested { .. } => {
|
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);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ pub fn create_window(app_handle: &AppHandle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// save window size and position
|
/// 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
|
let win = app_handle
|
||||||
.get_window("main")
|
.get_window("main")
|
||||||
.ok_or(anyhow::anyhow!("failed to get window"))?;
|
.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 verge = Config::verge();
|
||||||
let mut verge = verge.latest();
|
let mut verge = verge.latest();
|
||||||
verge.window_size_position = Some(vec![size.width, size.height, pos.x, pos.y]);
|
verge.window_size_position = Some(vec![size.width, size.height, pos.x, pos.y]);
|
||||||
|
|
||||||
|
if save_to_file {
|
||||||
verge.save_file()?;
|
verge.save_file()?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user