Compare commits

...

2 Commits

Author SHA1 Message Date
Memory
01b5ed1a8f
style: update Chip styles 2026-02-04 10:43:33 +08:00
Memory
4bfa02023c
perf: improve core startup performance 2026-02-04 10:20:59 +08:00
5 changed files with 83 additions and 47 deletions

View File

@ -160,7 +160,9 @@ async function prepareCore(detached: boolean, skipStop = false): Promise<CoreCon
} }
// 管理 Smart 内核覆写配置 // 管理 Smart 内核覆写配置
if (core === 'mihomo-smart') {
await manageSmartOverride() await manageSmartOverride()
}
// generateProfile 返回实际使用的 current // generateProfile 返回实际使用的 current
const current = await generateProfile() const current = await generateProfile()

View File

@ -9,7 +9,7 @@ const execPromise = promisify(exec)
// 常量 // 常量
const CORE_READY_MAX_RETRIES = 30 const CORE_READY_MAX_RETRIES = 30
const CORE_READY_RETRY_INTERVAL_MS = 500 const CORE_READY_RETRY_INTERVAL_MS = 100
export async function cleanupSocketFile(): Promise<void> { export async function cleanupSocketFile(): Promise<void> {
if (process.platform === 'win32') { if (process.platform === 'win32') {

View File

@ -128,9 +128,7 @@ app.on('open-url', async (_event, url) => {
await handleDeepLink(url) await handleDeepLink(url)
}) })
app.whenReady().then(async () => { const initPromise = (async () => {
electronApp.setAppUserModelId('party.mihomo.app')
await initBasic() await initBasic()
await checkHighPrivilegeCoreEarly() await checkHighPrivilegeCoreEarly()
await initAdminStatus() await initAdminStatus()
@ -144,11 +142,29 @@ app.whenReady().then(async () => {
appConfig.language = systemLanguage appConfig.language = systemLanguage
} }
await initI18n({ lng: appConfig.language }) await initI18n({ lng: appConfig.language })
return appConfig
} catch (e) { } catch (e) {
safeShowErrorBox('common.error.initFailed', `${e}`) safeShowErrorBox('common.error.initFailed', `${e}`)
app.quit() app.quit()
throw e
} }
})()
app.whenReady().then(async () => {
electronApp.setAppUserModelId('party.mihomo.app')
const appConfig = await initPromise
app.on('browser-window-created', (_, window) => {
optimizer.watchWindowShortcuts(window)
})
registerIpcMainHandlers()
const createWindowPromise = createWindow()
let coreStarted = false
const coreStartPromise = (async (): Promise<void> => {
try { try {
initCoreWatcher() initCoreWatcher()
const startPromises = await startCore() const startPromises = await startCore()
@ -159,37 +175,47 @@ app.whenReady().then(async () => {
await checkAdminRestartForTun() await checkAdminRestartForTun()
}) })
} }
coreStarted = true
} catch (e) { } catch (e) {
safeShowErrorBox('mihomo.error.coreStartFailed', `${e}`) safeShowErrorBox('mihomo.error.coreStartFailed', `${e}`)
} }
})()
const monitorPromise = (async (): Promise<void> => {
try { try {
await startMonitor() await startMonitor()
} catch { } catch {
// ignore // ignore
} }
})()
app.on('browser-window-created', (_, window) => { await createWindowPromise
optimizer.watchWindowShortcuts(window)
})
const { showFloatingWindow: showFloating = false, disableTray = false } = await getAppConfig() const { showFloatingWindow: showFloating = false, disableTray = false } = appConfig
registerIpcMainHandlers() const uiTasks: Promise<void>[] = [initShortcut()]
await createWindow()
if (showFloating) { if (showFloating) {
uiTasks.push(
(async () => {
try { try {
await showFloatingWindow() await showFloatingWindow()
} catch (error) { } catch (error) {
await logger.error('Failed to create floating window on startup', error) await logger.error('Failed to create floating window on startup', error)
} }
})()
)
} }
if (!disableTray) { if (!disableTray) {
await createTray() uiTasks.push(createTray())
} }
await initShortcut() await Promise.all(uiTasks)
await Promise.all([coreStartPromise, monitorPromise])
if (coreStarted) {
mainWindow?.webContents.send('core-started')
}
app.on('activate', () => { app.on('activate', () => {
showMainWindow() showMainWindow()

View File

@ -165,7 +165,7 @@ async function killOldMihomoProcesses(): Promise<void> {
} }
} }
await new Promise((resolve) => setTimeout(resolve, 500)) await new Promise((resolve) => setTimeout(resolve, 200))
} catch { } catch {
// 忽略错误 // 忽略错误
} }
@ -389,10 +389,16 @@ export async function initBasic(): Promise<void> {
} }
export async function init(): Promise<void> { export async function init(): Promise<void> {
await startSubStoreFrontendServer()
await startSubStoreBackendServer()
const { sysProxy } = await getAppConfig() const { sysProxy } = await getAppConfig()
const initTasks: Promise<void>[] = [
startSubStoreFrontendServer(),
startSubStoreBackendServer(),
startSSIDCheck()
]
initTasks.push(
(async (): Promise<void> => {
try { try {
if (sysProxy.enable) { if (sysProxy.enable) {
await startPacServer() await startPacServer()
@ -401,7 +407,9 @@ export async function init(): Promise<void> {
} catch { } catch {
// ignore // ignore
} }
})()
)
await startSSIDCheck() await Promise.all(initTasks)
initDeeplink() initDeeplink()
} }

View File

@ -58,10 +58,10 @@ const RuleItem: React.FC<RuleItemProps> = (props) => {
{payload} {payload}
</div> </div>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Chip size="sm" variant="flat" color="default" className="text-xs"> <Chip size="sm" radius="sm" variant="bordered" className="text-xs">
{type} {type}
</Chip> </Chip>
<Chip size="sm" variant="flat" color="default" className="text-xs"> <Chip size="sm" radius="sm" variant="bordered" className="text-xs">
{proxy} {proxy}
</Chip> </Chip>
</div> </div>