mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-30 18:52:12 +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:
@@ -180,6 +180,17 @@ impl IClashTemp {
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/// 容错读取当前代理模式。
|
||||
///
|
||||
/// 仅从已保存的 clash 配置 Mapping 中提取 `mode` 字段,不依赖 mihomo `/configs`
|
||||
/// 的严格 `BaseConfig` 反序列化,因此即使核心返回的字段与插件结构体不匹配也能取到。
|
||||
pub fn get_mode(&self) -> Option<String> {
|
||||
self.0.get("mode").and_then(|value| match value {
|
||||
Value::String(val_str) => Some(val_str.clone()),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub fn guard_redir_port(config: &Mapping) -> u16 {
|
||||
let mut port = config
|
||||
|
||||
Reference in New Issue
Block a user