diff --git a/Changelog.md b/Changelog.md index c39f92c43..59fa3efa2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -43,6 +43,7 @@
✨ 新增功能 +- **Mihomo(Meta) 内核升级至 v1.19.28** - 增加 TrustTunnel、OpenVPN、Tailscale、GostRelay 节点显示支持 - 全局扩展脚本增加恢复默认按钮 - DNS 添加 fake-ip-range6 可配置项 @@ -63,6 +64,7 @@ - 支持 Provider 节点延迟检测 - 优化页面不可见时的 Mihomo WebSocket 订阅,减少后台资源占用 - 代理组支持分别恢复普通模式和链式代理模式的滚动位置 +- 重构改进订阅配置切换逻辑
diff --git a/src-tauri/src/cmd/runtime.rs b/src-tauri/src/cmd/runtime.rs index b9c88471d..1671b2b6e 100644 --- a/src-tauri/src/cmd/runtime.rs +++ b/src-tauri/src/cmd/runtime.rs @@ -12,6 +12,28 @@ pub async fn get_runtime_config() -> CmdResult> { Ok(Config::runtime().await.latest_arc().config.clone()) } +/// 获取运行时代理组顺序 +#[tauri::command] +pub async fn get_runtime_proxy_group_order() -> CmdResult> { + let runtime = Config::runtime().await; + let runtime = runtime.latest_arc(); + + Ok(runtime + .config + .as_ref() + .and_then(|config| config.get("proxy-groups")) + .and_then(|groups| groups.as_sequence()) + .map(|groups| { + groups + .iter() + .filter_map(|group| group.get("name")) + .filter_map(|name| name.as_str()) + .map(String::from) + .collect() + }) + .unwrap_or_default()) +} + /// 获取运行时YAML配置 #[tauri::command] pub async fn get_runtime_yaml() -> CmdResult { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 94658b80e..fc19b303f 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -163,6 +163,7 @@ mod app_init { cmd::get_clash_mode, cmd::change_clash_core, cmd::get_runtime_config, + cmd::get_runtime_proxy_group_order, cmd::get_runtime_yaml, cmd::get_runtime_exists, cmd::get_runtime_logs, diff --git a/src/services/cmds.ts b/src/services/cmds.ts index cb70dbe84..a8bcc8cbd 100644 --- a/src/services/cmds.ts +++ b/src/services/cmds.ts @@ -93,6 +93,10 @@ export async function getRuntimeConfig() { return invoke('get_runtime_config') } +export async function getRuntimeProxyGroupOrder() { + return invoke('get_runtime_proxy_group_order') +} + export async function getRuntimeYaml() { return invoke('get_runtime_yaml') } @@ -132,10 +136,12 @@ export async function calcuProxies(): Promise<{ records: Record proxies: IProxyItem[] }> { - const [proxyResponse, providerResponse] = await Promise.all([ - getProxies(), - calcuProxyProviders(), - ]) + const [proxyResponse, providerResponse, runtimeGroupOrder] = + await Promise.all([ + getProxies(), + calcuProxyProviders(), + getRuntimeProxyGroupOrder(), + ]) const proxyRecord = proxyResponse.proxies const providerRecord = providerResponse @@ -199,6 +205,19 @@ export async function calcuProxies(): Promise<{ .concat(globalGroups) } + const groupOrder = new Map( + runtimeGroupOrder.map((name, index) => [name, index]), + ) + + groups.sort((a, b) => { + const aIndex = groupOrder.get(a.name) ?? Number.MAX_SAFE_INTEGER + const bIndex = groupOrder.get(b.name) ?? Number.MAX_SAFE_INTEGER + if (aIndex !== bIndex) return aIndex - bIndex + if (a.name < b.name) return -1 + if (a.name > b.name) return 1 + return 0 + }) + const proxies = [direct, reject].concat( Object.values(proxyRecord).filter( (p) => !p?.all?.length && p?.name !== 'DIRECT' && p?.name !== 'REJECT',