代理模块修改

This commit is contained in:
zhongluofeng
2026-07-16 18:26:57 +08:00
parent fb361aff9a
commit 15f29c5895
67 changed files with 2546 additions and 118 deletions
+41 -1
View File
@@ -16,8 +16,13 @@ export interface ProxySettings {
allowLan: boolean
systemProxy: boolean
autoStart: boolean
autoSystemProxy: boolean
currentProfile: string | null
profiles: ProfileMeta[]
autoSwitchEnabled: boolean
autoSwitchInterval: number
autoSwitchGroup: string
autoSwitchRegion: string
}
export interface ProfileMeta {
@@ -35,6 +40,13 @@ export interface KernelInfo {
version: string | null
}
export interface KernelUpdateInfo {
currentVersion: string | null
latestVersion: string
downloadUrl: string
hasUpdate: boolean
}
export interface ProxyStatus {
running: boolean
pid: number | null
@@ -108,6 +120,20 @@ export const useProxyStore = defineStore('proxy', () => {
await refreshStatus()
}
/** 等待 mihomo API 就绪(轮询 version 接口,最多等 10 秒) */
const waitForApi = async (timeoutMs = 10000): Promise<boolean> => {
const start = Date.now()
while (Date.now() - start < timeoutMs) {
try {
await invoke<MihomoVersion>('proxy_version')
return true
} catch {
await new Promise(r => setTimeout(r, 500))
}
}
return false
}
/** 获取 mihomo 版本(仅运行时可用) */
const refreshVersion = async () => {
try {
@@ -220,6 +246,16 @@ export const useProxyStore = defineStore('proxy', () => {
}
}
// ---------- 内核更新 ----------
const checkKernelUpdate = async (): Promise<KernelUpdateInfo> => {
return await invoke<KernelUpdateInfo>('proxy_check_kernel_update')
}
const updateKernel = async () => {
await invoke('proxy_update_kernel')
await refreshKernel()
}
return {
// state
kernel,
@@ -234,6 +270,7 @@ export const useProxyStore = defineStore('proxy', () => {
start,
stop,
restart,
waitForApi,
refreshVersion,
// proxies
loadProxies,
@@ -251,6 +288,9 @@ export const useProxyStore = defineStore('proxy', () => {
// system proxy
setSystemProxy,
clearSystemProxy,
toggleSystemProxy
toggleSystemProxy,
// kernel update
checkKernelUpdate,
updateKernel
}
})