mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
fix: ensure app state is saved on exit and window events for better state management
This commit is contained in:
@@ -19,7 +19,7 @@ use tauri::AppHandle;
|
|||||||
use tauri::Manager;
|
use tauri::Manager;
|
||||||
use tauri_plugin_autostart::MacosLauncher;
|
use tauri_plugin_autostart::MacosLauncher;
|
||||||
use tauri_plugin_deep_link::DeepLinkExt;
|
use tauri_plugin_deep_link::DeepLinkExt;
|
||||||
use tauri_plugin_window_state::{StateFlags, WindowExt};
|
use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt};
|
||||||
use tokio::time::{timeout, Duration};
|
use tokio::time::{timeout, Duration};
|
||||||
use utils::logging::Type;
|
use utils::logging::Type;
|
||||||
|
|
||||||
@@ -350,12 +350,26 @@ pub fn run() {
|
|||||||
if code.is_none() {
|
if code.is_none() {
|
||||||
api.prevent_exit();
|
api.prevent_exit();
|
||||||
}
|
}
|
||||||
|
if let Some(app_handle) = core::handle::Handle::global().app_handle() {
|
||||||
|
logging_error!(
|
||||||
|
Type::Window,
|
||||||
|
true,
|
||||||
|
app_handle.save_window_state(StateFlags::all())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tauri::RunEvent::Exit => {
|
tauri::RunEvent::Exit => {
|
||||||
// avoid duplicate cleanup
|
// avoid duplicate cleanup
|
||||||
if core::handle::Handle::global().is_exiting() {
|
if core::handle::Handle::global().is_exiting() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if let Some(app_handle) = core::handle::Handle::global().app_handle() {
|
||||||
|
logging_error!(
|
||||||
|
Type::Window,
|
||||||
|
true,
|
||||||
|
app_handle.save_window_state(StateFlags::all())
|
||||||
|
);
|
||||||
|
}
|
||||||
feat::clean();
|
feat::clean();
|
||||||
}
|
}
|
||||||
tauri::RunEvent::WindowEvent { label, event, .. } => {
|
tauri::RunEvent::WindowEvent { label, event, .. } => {
|
||||||
@@ -374,6 +388,13 @@ pub fn run() {
|
|||||||
} else {
|
} else {
|
||||||
logging!(warn, Type::Window, true, "尝试隐藏窗口但窗口不存在");
|
logging!(warn, Type::Window, true, "尝试隐藏窗口但窗口不存在");
|
||||||
}
|
}
|
||||||
|
if let Some(app_handle) = core::handle::Handle::global().app_handle() {
|
||||||
|
logging_error!(
|
||||||
|
Type::Window,
|
||||||
|
true,
|
||||||
|
app_handle.save_window_state(StateFlags::all())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tauri::WindowEvent::Focused(true) => {
|
tauri::WindowEvent::Focused(true) => {
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
@@ -437,6 +458,13 @@ pub fn run() {
|
|||||||
hotkey::Hotkey::global().unregister("CMD+W")
|
hotkey::Hotkey::global().unregister("CMD+W")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if let Some(app_handle) = core::handle::Handle::global().app_handle() {
|
||||||
|
logging_error!(
|
||||||
|
Type::Window,
|
||||||
|
true,
|
||||||
|
app_handle.save_window_state(StateFlags::all())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user