mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-28 00:42:08 +08:00
fix: read clash mode tolerantly and propagate mode-switch failures
The home mode card read the proxy mode only from mihomo's /configs (strict BaseConfig); when that response drifted a single field, the whole read failed and the card showed a bare "communication error". patch_clash_mode also swallowed backend PATCH failures and always returned Ok, so the UI could not tell a switch had actually failed. - add a tolerant get_clash_mode command that reads mode from the saved clash config (IClashTemp::get_mode), bypassing strict BaseConfig deserialization, and - make change_clash_mode return Result and have patch_clash_mode propagate it; the hotkey/tray callers log-and-ignore as before.
This commit is contained in:
@@ -125,19 +125,22 @@ impl Hotkey {
|
||||
}
|
||||
HotkeyFunction::ClashModeRule => {
|
||||
AsyncHandler::spawn(async move || {
|
||||
feat::change_clash_mode("rule".into()).await;
|
||||
// 错误已在 change_clash_mode 内部记录,此处显式忽略返回值
|
||||
let _ = feat::change_clash_mode("rule".into()).await;
|
||||
notify_event(NotificationEvent::ClashModeChanged { mode: "Rule" }).await;
|
||||
});
|
||||
}
|
||||
HotkeyFunction::ClashModeGlobal => {
|
||||
AsyncHandler::spawn(async move || {
|
||||
feat::change_clash_mode("global".into()).await;
|
||||
// 错误已在 change_clash_mode 内部记录,此处显式忽略返回值
|
||||
let _ = feat::change_clash_mode("global".into()).await;
|
||||
notify_event(NotificationEvent::ClashModeChanged { mode: "Global" }).await;
|
||||
});
|
||||
}
|
||||
HotkeyFunction::ClashModeDirect => {
|
||||
AsyncHandler::spawn(async move || {
|
||||
feat::change_clash_mode("direct".into()).await;
|
||||
// 错误已在 change_clash_mode 内部记录,此处显式忽略返回值
|
||||
let _ = feat::change_clash_mode("direct".into()).await;
|
||||
notify_event(NotificationEvent::ClashModeChanged { mode: "Direct" }).await;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -933,7 +933,8 @@ fn on_menu_event(_: &AppHandle, event: MenuEvent) {
|
||||
&& let Some(final_mode) = stripped.strip_suffix("_mode")
|
||||
{
|
||||
logging!(info, Type::ProxyMode, "Switch Proxy Mode To: {}", final_mode);
|
||||
feat::change_clash_mode(final_mode.into()).await;
|
||||
// 错误已在 change_clash_mode 内部记录,此处显式忽略返回值
|
||||
let _ = feat::change_clash_mode(final_mode.into()).await;
|
||||
}
|
||||
}
|
||||
MenuIds::DASHBOARD => {
|
||||
|
||||
Reference in New Issue
Block a user