fix: kill clash when exit in service mode, close #241

This commit is contained in:
GyDi 2022-10-22 13:55:06 +08:00
parent c9d9909d74
commit 294d980b52
No known key found for this signature in database
GPG Key ID: 1C95E0D3467B3084

View File

@ -22,6 +22,9 @@ pub struct Service {
sidecar: Option<CommandChild>,
logs: Arc<RwLock<VecDeque<String>>>,
#[allow(unused)]
use_service_mode: bool,
}
impl Service {
@ -31,6 +34,7 @@ impl Service {
Service {
sidecar: None,
logs: Arc::new(RwLock::new(queue)),
use_service_mode: false,
}
}
@ -46,6 +50,8 @@ impl Service {
verge.enable_service_mode.clone().unwrap_or(false)
};
self.use_service_mode = enable;
if !enable {
return self.start_clash_by_sidecar();
}
@ -74,14 +80,8 @@ impl Service {
{
let _ = self.stop_clash_by_sidecar();
let enable = {
let data = Data::global();
let verge = data.verge.lock();
verge.enable_service_mode.clone().unwrap_or(false)
};
if enable {
tauri::async_runtime::spawn(async move {
if self.use_service_mode {
tauri::async_runtime::block_on(async move {
log_if_err!(Self::stop_clash_by_service().await);
});
}