mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-27 16:00:09 +08:00
fix(tun): make the TUN switch reflect what the Core actually runs
The switch read enable_tun_mode while the Core was given enable_tun_mode && !session_suppression, so falling back to Sidecar left it showing a TUN that was not running, with nothing to write the flag back. Drop the session flag: the stored preference is the only truth, re-checked at startup and written off when the conditions for it are not met, and the switch renders it against current capability.
This commit is contained in:
@@ -19,11 +19,7 @@ use clash_verge_draft::Draft;
|
||||
use clash_verge_logging::{Type, logging, logging_error};
|
||||
use serde_yaml_ng::{Mapping, Value};
|
||||
use smartstring::alias::String;
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
path::PathBuf,
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
use std::{collections::HashSet, path::PathBuf};
|
||||
use tokio::sync::{Mutex, MutexGuard, OnceCell};
|
||||
use tokio::time::sleep;
|
||||
|
||||
@@ -34,7 +30,6 @@ pub(crate) struct Config {
|
||||
runtime_config: Draft<IRuntime>,
|
||||
}
|
||||
|
||||
static TUN_SESSION_SUPPRESSED: AtomicBool = AtomicBool::new(false);
|
||||
static CONFIG_WRITE_LOCK: Mutex<()> = Mutex::const_new(());
|
||||
|
||||
impl Config {
|
||||
@@ -82,24 +77,7 @@ impl Config {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn tun_suppressed_for_session() -> bool {
|
||||
TUN_SESSION_SUPPRESSED.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
pub(crate) async fn suppress_tun_for_session() {
|
||||
TUN_SESSION_SUPPRESSED.store(true, Ordering::Release);
|
||||
Handle::refresh_verge();
|
||||
let _ = tray::Tray::global().update_menu().await;
|
||||
}
|
||||
|
||||
pub(crate) async fn restore_tun_for_session() {
|
||||
TUN_SESSION_SUPPRESSED.store(false, Ordering::Release);
|
||||
Handle::refresh_verge();
|
||||
let _ = tray::Tray::global().update_menu().await;
|
||||
}
|
||||
|
||||
pub(crate) async fn disable_tun_and_persist() -> Result<()> {
|
||||
TUN_SESSION_SUPPRESSED.store(false, Ordering::Release);
|
||||
let verge = Self::verge().await;
|
||||
verge.edit_draft(|draft| {
|
||||
draft.enable_tun_mode = Some(false);
|
||||
|
||||
Reference in New Issue
Block a user