From 579f36a1ddad3f3e43143977fca44c8e4873dc55 Mon Sep 17 00:00:00 2001 From: GyDi Date: Mon, 10 Jan 2022 22:08:18 +0800 Subject: [PATCH] fix: update profile after restart clash --- src-tauri/src/cmds.rs | 25 +++++++++++++++++++++---- src-tauri/src/main.rs | 13 ++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index 3375b95..2b07b58 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -142,10 +142,27 @@ pub fn patch_profile( /// restart the sidecar #[tauri::command] -pub fn restart_sidecar(clash_state: State<'_, ClashState>) { - let mut clash_arc = clash_state.0.lock().unwrap(); - if let Err(err) = clash_arc.restart_sidecar() { - log::error!("{}", err); +pub fn restart_sidecar( + clash_state: State<'_, ClashState>, + profiles_state: State<'_, ProfilesState>, +) -> Result<(), String> { + let mut clash = clash_state.0.lock().unwrap(); + + match clash.restart_sidecar() { + Ok(_) => { + let profiles = profiles_state.0.lock().unwrap(); + match profiles.activate(clash.info.clone()) { + Ok(()) => Ok(()), + Err(err) => { + log::error!("{}", err); + Err(err) + } + } + } + Err(err) => { + log::error!("{}", err); + Err(err) + } } } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 5be5dac..0b63178 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -42,9 +42,16 @@ fn main() -> std::io::Result<()> { } "restart_clash" => { let clash_state = app_handle.state::(); - let mut clash_arc = clash_state.0.lock().unwrap(); - if let Err(err) = clash_arc.restart_sidecar() { - log::error!("{}", err); + let mut clash = clash_state.0.lock().unwrap(); + match clash.restart_sidecar() { + Ok(_) => { + let profiles = app_handle.state::(); + let profiles = profiles.0.lock().unwrap(); + if let Err(err) = profiles.activate(clash.info.clone()) { + log::error!("{}", err); + } + } + Err(err) => log::error!("{}", err), } } "quit" => {