feat: control final tun config

This commit is contained in:
GyDi
2022-04-01 23:55:44 +08:00
parent cbe7c69154
commit 7cb467c960
3 changed files with 56 additions and 57 deletions

View File

@@ -317,16 +317,6 @@ pub fn patch_verge_config(
let tun_mode = payload.enable_tun_mode.clone();
let system_proxy = payload.enable_system_proxy.clone();
// change tun mode
if tun_mode.is_some() {
let mut clash = clash_state.0.lock().unwrap();
let profiles = profiles_state.0.lock().unwrap();
wrap_err!(clash.tun_mode(tun_mode.unwrap()))?;
clash.update_config();
wrap_err!(clash.activate_enhanced(&profiles, false, false))?;
}
let mut verge = verge_state.0.lock().unwrap();
wrap_err!(verge.patch_config(payload))?;
@@ -339,6 +329,23 @@ pub fn patch_verge_config(
.unwrap();
}
// change tun mode
if tun_mode.is_some() {
#[cfg(target_os = "windows")]
if *tun_mode.as_ref().unwrap() {
let wintun_dll = dirs::app_home_dir().join("wintun.dll");
if !wintun_dll.exists() {
log::error!("failed to enable TUN for missing `wintun.dll`");
return Err("failed to enable TUN for missing `wintun.dll`".into());
}
}
let clash = clash_state.0.lock().unwrap();
let profiles = profiles_state.0.lock().unwrap();
wrap_err!(clash.activate_enhanced(&profiles, false, false))?;
}
Ok(())
}