mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-26 22:22:13 +08:00
fix(proxy): preserve runtime proxy group order
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
<details>
|
||||
<summary><strong> ✨ 新增功能 </strong></summary>
|
||||
|
||||
- **Mihomo(Meta) 内核升级至 v1.19.28**
|
||||
- 增加 TrustTunnel、OpenVPN、Tailscale、GostRelay 节点显示支持
|
||||
- 全局扩展脚本增加恢复默认按钮
|
||||
- DNS 添加 fake-ip-range6 可配置项
|
||||
@@ -63,6 +64,7 @@
|
||||
- 支持 Provider 节点延迟检测
|
||||
- 优化页面不可见时的 Mihomo WebSocket 订阅,减少后台资源占用
|
||||
- 代理组支持分别恢复普通模式和链式代理模式的滚动位置
|
||||
- 重构改进订阅配置切换逻辑
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
@@ -12,6 +12,28 @@ pub async fn get_runtime_config() -> CmdResult<Option<Mapping>> {
|
||||
Ok(Config::runtime().await.latest_arc().config.clone())
|
||||
}
|
||||
|
||||
/// 获取运行时代理组顺序
|
||||
#[tauri::command]
|
||||
pub async fn get_runtime_proxy_group_order() -> CmdResult<Vec<String>> {
|
||||
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<String> {
|
||||
|
||||
@@ -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,
|
||||
|
||||
+23
-4
@@ -93,6 +93,10 @@ export async function getRuntimeConfig() {
|
||||
return invoke<IConfigData | null>('get_runtime_config')
|
||||
}
|
||||
|
||||
export async function getRuntimeProxyGroupOrder() {
|
||||
return invoke<string[]>('get_runtime_proxy_group_order')
|
||||
}
|
||||
|
||||
export async function getRuntimeYaml() {
|
||||
return invoke<string | null>('get_runtime_yaml')
|
||||
}
|
||||
@@ -132,10 +136,12 @@ export async function calcuProxies(): Promise<{
|
||||
records: Record<string, IProxyItem>
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user