fix: restart clash core after change it

This commit is contained in:
wonfen 2025-04-19 22:23:58 +08:00
parent 05b910dc17
commit 541b78ba6f
2 changed files with 23 additions and 7 deletions

View File

@ -40,11 +40,22 @@ pub async fn change_clash_core(clash_core: String) -> CmdResult<Option<String>>
.await
{
Ok(_) => {
log::info!(target: "app", "core changed to {clash_core}");
// 切换内核后重启内核
match CoreManager::global().restart_core().await {
Ok(_) => {
log::info!(target: "app", "core changed and restarted to {clash_core}");
handle::Handle::notice_message("config_core::change_success", &clash_core);
handle::Handle::refresh_clash();
Ok(None)
}
Err(err) => {
let error_msg = format!("Core changed but failed to restart: {}", err);
log::error!(target: "app", "{}", error_msg);
handle::Handle::notice_message("config_core::change_error", &error_msg);
Ok(Some(error_msg))
}
}
}
Err(err) => {
let error_msg = err.to_string();
log::error!(target: "app", "failed to change core: {error_msg}");

View File

@ -45,13 +45,18 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
try {
closeAllConnections();
await changeClashCore(core);
const errorMsg = await changeClashCore(core);
if (errorMsg) {
Notice.error(errorMsg);
return;
}
mutateVerge();
setTimeout(() => {
mutate("getClashConfig");
mutate("getVersion");
}, 100);
// Notice.success(t("Switched to _clash Core", { core: `${core}` }), 1000);
}, 500);
} catch (err: any) {
Notice.error(err?.message || err.toString());
}