mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 19:56:50 +08:00
refactor: fix
This commit is contained in:
parent
09965f1cc6
commit
dc941575fe
|
@ -44,49 +44,32 @@ pub async fn update_profile(index: String, option: Option<PrfOption>) -> CmdResu
|
|||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn select_profile(index: String) -> CmdResult {
|
||||
let mut profiles = ProfilesN::global().config.lock();
|
||||
wrap_err!(profiles.put_current(index))?;
|
||||
drop(profiles);
|
||||
|
||||
wrap_err!(tauri::async_runtime::block_on(async {
|
||||
CoreManager::global().activate_config().await
|
||||
}))
|
||||
pub async fn select_profile(index: String) -> CmdResult {
|
||||
wrap_err!({ ProfilesN::global().config.lock().put_current(index) })?;
|
||||
wrap_err!(CoreManager::global().activate_config().await)
|
||||
}
|
||||
|
||||
/// change the profile chain
|
||||
#[tauri::command]
|
||||
pub fn change_profile_chain(chain: Option<Vec<String>>) -> CmdResult {
|
||||
let mut profiles = ProfilesN::global().config.lock();
|
||||
wrap_err!(profiles.put_chain(chain))?;
|
||||
drop(profiles);
|
||||
|
||||
wrap_err!(tauri::async_runtime::block_on(async {
|
||||
CoreManager::global().activate_config().await
|
||||
}))
|
||||
pub async fn change_profile_chain(chain: Option<Vec<String>>) -> CmdResult {
|
||||
wrap_err!({ ProfilesN::global().config.lock().put_chain(chain) })?;
|
||||
wrap_err!(CoreManager::global().activate_config().await)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn change_profile_valid(valid: Option<Vec<String>>) -> CmdResult {
|
||||
let mut profiles = ProfilesN::global().config.lock();
|
||||
wrap_err!(profiles.put_valid(valid))?;
|
||||
drop(profiles);
|
||||
|
||||
wrap_err!(tauri::async_runtime::block_on(async {
|
||||
CoreManager::global().activate_config().await
|
||||
}))
|
||||
pub async fn change_profile_valid(valid: Option<Vec<String>>) -> CmdResult {
|
||||
wrap_err!({ ProfilesN::global().config.lock().put_valid(valid) })?;
|
||||
wrap_err!(CoreManager::global().activate_config().await)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn delete_profile(index: String) -> CmdResult {
|
||||
let mut profiles = ProfilesN::global().config.lock();
|
||||
if wrap_err!(profiles.delete_item(index))? {
|
||||
drop(profiles);
|
||||
pub async fn delete_profile(index: String) -> CmdResult {
|
||||
let should_update = { wrap_err!(ProfilesN::global().config.lock().delete_item(index))? };
|
||||
|
||||
wrap_err!(tauri::async_runtime::block_on(async {
|
||||
CoreManager::global().activate_config().await
|
||||
}))?;
|
||||
if should_update {
|
||||
wrap_err!(CoreManager::global().activate_config().await)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -185,10 +168,8 @@ pub fn patch_verge_config(payload: IVerge) -> CmdResult {
|
|||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn change_clash_core(clash_core: Option<String>) -> CmdResult {
|
||||
wrap_err!(tauri::async_runtime::block_on(async {
|
||||
CoreManager::global().change_core(clash_core).await
|
||||
}))
|
||||
pub async fn change_clash_core(clash_core: Option<String>) -> CmdResult {
|
||||
wrap_err!(CoreManager::global().change_core(clash_core).await)
|
||||
}
|
||||
|
||||
/// restart the sidecar
|
||||
|
|
|
@ -58,22 +58,11 @@ impl ClashN {
|
|||
pub fn patch_config(&self, patch: Mapping) -> Result<()> {
|
||||
let mut config = self.config.lock();
|
||||
|
||||
let port_key = Value::from("mixed-port");
|
||||
let server_key = Value::from("external-controller");
|
||||
let secret_key = Value::from("secret");
|
||||
|
||||
let change_info = patch.contains_key(&port_key)
|
||||
|| patch.contains_key(&server_key)
|
||||
|| patch.contains_key(&secret_key);
|
||||
|
||||
for (key, value) in patch.into_iter() {
|
||||
config.insert(key, value);
|
||||
}
|
||||
|
||||
if change_info {
|
||||
let mut info = self.info.lock();
|
||||
*info = ClashInfoN::from(&*config);
|
||||
}
|
||||
drop(config);
|
||||
|
||||
self.save_config()
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ impl VergeN {
|
|||
patch!(auto_close_connection);
|
||||
patch!(default_latency_test);
|
||||
|
||||
drop(config);
|
||||
self.save_file()
|
||||
}
|
||||
|
||||
|
|
|
@ -79,12 +79,12 @@ impl CoreManager {
|
|||
let clash_core = { self.clash_core.lock().clone() };
|
||||
|
||||
let output = Command::new_sidecar(clash_core)?
|
||||
.args(["-t", config_path])
|
||||
.args(["-t", "-f", config_path])
|
||||
.output()?;
|
||||
|
||||
if !output.status.success() {
|
||||
Logger::global().set_log(output.stderr.clone());
|
||||
bail!("{}", output.stderr); // 过滤掉终端颜色值
|
||||
Logger::global().set_log(output.stdout.clone());
|
||||
bail!("{}", output.stdout); // 过滤掉终端颜色值
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -177,17 +177,19 @@ impl CoreManager {
|
|||
// 清掉旧日志
|
||||
Logger::global().clear_log();
|
||||
|
||||
let old_core = {
|
||||
let mut self_core = self.clash_core.lock();
|
||||
let old_core = self_core.clone(); // 保存一下旧值
|
||||
let old_core = self_core.to_owned(); // 保存一下旧值
|
||||
*self_core = clash_core.clone();
|
||||
drop(self_core);
|
||||
old_core
|
||||
};
|
||||
|
||||
match self.run_core() {
|
||||
Ok(_) => {
|
||||
// 更新到配置文件
|
||||
let mut verge = VergeN::global().config.lock();
|
||||
verge.clash_core = Some(clash_core);
|
||||
drop(verge);
|
||||
{
|
||||
VergeN::global().config.lock().clash_core = Some(clash_core);
|
||||
}
|
||||
|
||||
let _ = VergeN::global().save_file();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user