mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-08 02:52:07 +08:00
fix(proxy): preserve runtime proxy group order
This commit is contained in:
+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