support fixed proxy

This commit is contained in:
pompurin404 2024-08-27 10:05:47 +08:00
parent 1882a38aa2
commit d49e9bc420
No known key found for this signature in database
6 changed files with 16 additions and 13 deletions

View File

@ -9,7 +9,7 @@ import {
import { generateProfile } from './factory'
import { getAppConfig, patchAppConfig, patchControledMihomoConfig } from '../config'
import { dialog, safeStorage } from 'electron'
import { pauseWebsockets } from './mihomoApi'
import { pauseWebsockets, startMihomoTraffic } from './mihomoApi'
import { writeFile } from 'fs/promises'
import { promisify } from 'util'
import { mainWindow } from '..'
@ -59,6 +59,7 @@ export async function startCore(): Promise<void> {
}
}
if (data.toString().includes('RESTful API listening at')) {
await startMihomoTraffic()
retry = 10
resolve()
}

View File

@ -389,9 +389,8 @@ const mihomoConnections = async (): Promise<void> => {
export const pauseWebsockets = () => {
const recoverList: (() => void)[] = []
// Traffic 始终开启
// Traffic 内核启动时始终开启
stopMihomoTraffic()
recoverList.push(startMihomoTraffic)
if (mihomoMemoryWs) {
stopMihomoMemory()
recoverList.push(startMihomoMemory)

View File

@ -4,7 +4,7 @@ import windowStateKeeper from 'electron-window-state'
import { app, shell, BrowserWindow, Menu, dialog, Notification } from 'electron'
import { pauseWebsockets, startMihomoMemory, stopMihomoMemory } from './core/mihomoApi'
import { addProfileItem, getAppConfig } from './config'
import { stopCore } from './core/manager'
import { startCore, stopCore } from './core/manager'
import { triggerSysProxy } from './sys/sysproxy'
import icon from '../../resources/icon.png?asset'
import { createTray } from './resolve/tray'
@ -13,6 +13,7 @@ import { join } from 'path'
import { initShortcut } from './resolve/shortcut'
import { execSync } from 'child_process'
import { createElevateTask } from './sys/misc'
import { initProfileUpdater } from './core/profileUpdater'
export let mainWindow: BrowserWindow | null = null
@ -79,6 +80,14 @@ app.whenReady().then(async () => {
dialog.showErrorBox('应用初始化失败', `${e}`)
app.quit()
}
try {
await startCore()
setTimeout(async () => {
await initProfileUpdater()
}, 60000)
} catch (e) {
dialog.showErrorBox('内核启动失败', `${e}`)
}
// Default open or close DevTools by F12 in development
// and ignore CommandOrControl + R in production.

View File

@ -27,9 +27,6 @@ import { startPacServer } from '../resolve/server'
import { triggerSysProxy } from '../sys/sysproxy'
import { getAppConfig } from '../config'
import { app } from 'electron'
import { startCore } from '../core/manager'
import { initProfileUpdater } from '../core/profileUpdater'
import { startMihomoTraffic } from '../core/mihomoApi'
async function initDirs(): Promise<void> {
if (!existsSync(dataDir())) {
@ -138,11 +135,6 @@ export async function init(): Promise<void> {
await startPacServer()
const { sysProxy } = await getAppConfig()
await triggerSysProxy(sysProxy.enable)
await startCore()
await startMihomoTraffic()
setTimeout(async () => {
await initProfileUpdater()
}, 60000)
initDeeplink()
}

View File

@ -52,13 +52,14 @@ const ProxyItem: React.FC<Props> = (props) => {
PubSub.unsubscribe(token)
}
}, [])
const fixed = group.fixed && group.fixed === proxy.name
return (
<Card
onPress={() => onSelect(group.name, proxy.name)}
isPressable
fullWidth
className={`${selected ? 'bg-primary/30' : 'bg-content2'}`}
className={`${fixed ? 'bg-secondary/30' : selected ? 'bg-primary/30' : 'bg-content2'}`}
radius="sm"
>
<CardBody className="p-2">

View File

@ -147,6 +147,7 @@ interface IMihomoGroup {
all: string[]
extra: Record<string, { alive: boolean; history: IMihomoHistory[] }>
testUrl?: string
fixed?: string
hidden: boolean
history: IMihomoHistory[]
icon: string