mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 06:03:45 +08:00
fix: windows cannot save window state(2)
This commit is contained in:
parent
94259f9515
commit
4e2d9d6acd
@ -9,6 +9,7 @@ use tauri::{AppHandle, Emitter, Manager, WebviewWindow};
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Handle {
|
||||
pub app_handle: Arc<RwLock<Option<AppHandle>>>,
|
||||
pub is_exiting: Arc<RwLock<bool>>,
|
||||
}
|
||||
|
||||
impl Handle {
|
||||
@ -17,6 +18,7 @@ impl Handle {
|
||||
|
||||
HANDLE.get_or_init(|| Handle {
|
||||
app_handle: Arc::new(RwLock::new(None)),
|
||||
is_exiting: Arc::new(RwLock::new(false)),
|
||||
})
|
||||
}
|
||||
|
||||
@ -68,4 +70,13 @@ impl Handle {
|
||||
Tray::update_part()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_is_exiting(&self) {
|
||||
let mut is_exiting = self.is_exiting.write();
|
||||
*is_exiting = true;
|
||||
}
|
||||
|
||||
pub fn is_exiting(&self) -> bool {
|
||||
*self.is_exiting.read()
|
||||
}
|
||||
}
|
||||
|
@ -118,12 +118,14 @@ pub fn toggle_tun_mode() {
|
||||
|
||||
pub fn quit(code: Option<i32>) {
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
handle::Handle::global().set_is_exiting();
|
||||
resolve::resolve_reset();
|
||||
#[cfg(target_os = "macos")]
|
||||
tauri::async_runtime::block_on(async {
|
||||
resolve::restore_public_dns().await;
|
||||
});
|
||||
|
||||
log_err!(handle::Handle::global().get_window().unwrap().close());
|
||||
log_err!(app_handle.save_window_state(StateFlags::default()));
|
||||
app_handle.exit(code.unwrap_or(0));
|
||||
}
|
||||
|
@ -151,6 +151,9 @@ pub fn run() {
|
||||
if label == "main" {
|
||||
match event {
|
||||
tauri::WindowEvent::CloseRequested { api, .. } => {
|
||||
if core::handle::Handle::global().is_exiting() {
|
||||
return;
|
||||
}
|
||||
println!("closing window...");
|
||||
api.prevent_close();
|
||||
let window = core::handle::Handle::global().get_window().unwrap();
|
||||
|
Loading…
x
Reference in New Issue
Block a user