mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 10:33:43 +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)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct Handle {
|
pub struct Handle {
|
||||||
pub app_handle: Arc<RwLock<Option<AppHandle>>>,
|
pub app_handle: Arc<RwLock<Option<AppHandle>>>,
|
||||||
|
pub is_exiting: Arc<RwLock<bool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handle {
|
impl Handle {
|
||||||
@ -17,6 +18,7 @@ impl Handle {
|
|||||||
|
|
||||||
HANDLE.get_or_init(|| Handle {
|
HANDLE.get_or_init(|| Handle {
|
||||||
app_handle: Arc::new(RwLock::new(None)),
|
app_handle: Arc::new(RwLock::new(None)),
|
||||||
|
is_exiting: Arc::new(RwLock::new(false)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,4 +70,13 @@ impl Handle {
|
|||||||
Tray::update_part()?;
|
Tray::update_part()?;
|
||||||
Ok(())
|
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>) {
|
pub fn quit(code: Option<i32>) {
|
||||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||||
|
handle::Handle::global().set_is_exiting();
|
||||||
resolve::resolve_reset();
|
resolve::resolve_reset();
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
tauri::async_runtime::block_on(async {
|
tauri::async_runtime::block_on(async {
|
||||||
resolve::restore_public_dns().await;
|
resolve::restore_public_dns().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
log_err!(handle::Handle::global().get_window().unwrap().close());
|
||||||
log_err!(app_handle.save_window_state(StateFlags::default()));
|
log_err!(app_handle.save_window_state(StateFlags::default()));
|
||||||
app_handle.exit(code.unwrap_or(0));
|
app_handle.exit(code.unwrap_or(0));
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,9 @@ pub fn run() {
|
|||||||
if label == "main" {
|
if label == "main" {
|
||||||
match event {
|
match event {
|
||||||
tauri::WindowEvent::CloseRequested { api, .. } => {
|
tauri::WindowEvent::CloseRequested { api, .. } => {
|
||||||
|
if core::handle::Handle::global().is_exiting() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
println!("closing window...");
|
println!("closing window...");
|
||||||
api.prevent_close();
|
api.prevent_close();
|
||||||
let window = core::handle::Handle::global().get_window().unwrap();
|
let window = core::handle::Handle::global().get_window().unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user