diff --git a/src/main/config/override.ts b/src/main/config/override.ts index 5112e68..20afc36 100644 --- a/src/main/config/override.ts +++ b/src/main/config/override.ts @@ -54,9 +54,12 @@ export async function addOverrideItem(item: Partial): Promise { const config = await getOverrideConfig() const item = await getOverrideItem(id) - config.items = config.items?.filter((item) => item.id !== id) + if (!item) return + config.items = config.items?.filter((i) => i.id !== id) await setOverrideConfig(config) - await rm(overridePath(id, item?.ext || 'js')) + if (existsSync(overridePath(id, item.ext))) { + await rm(overridePath(id, item.ext)) + } } export async function createOverride(item: Partial): Promise { diff --git a/src/main/config/profile.ts b/src/main/config/profile.ts index 597a9d5..23719d0 100644 --- a/src/main/config/profile.ts +++ b/src/main/config/profile.ts @@ -368,12 +368,16 @@ export async function getProfile(id: string | undefined): Promise // attachment;filename=xxx.yaml; filename*=UTF-8''%xx%xx%xx function parseFilename(str: string): string { if (str.match(/filename\*=.*''/)) { - const filename = decodeURIComponent(str.split(/filename\*=.*''/)[1]) - return filename - } else { - const filename = str.split('filename=')[1] - return filename + const parts = str.split(/filename\*=.*''/) + if (parts[1]) { + return decodeURIComponent(parts[1]) + } } + const parts = str.split('filename=') + if (parts[1]) { + return parts[1].replace(/^["']|["']$/g, '') + } + return 'Remote File' } // subscription-userinfo: upload=1234; download=2234; total=1024000; expire=2218532293 diff --git a/src/main/core/factory.ts b/src/main/core/factory.ts index 9614cd8..8499c1e 100644 --- a/src/main/core/factory.ts +++ b/src/main/core/factory.ts @@ -25,8 +25,8 @@ import { createLogger } from '../utils/logger' const factoryLogger = createLogger('Factory') -let runtimeConfigStr: string -let runtimeConfig: IMihomoConfig +let runtimeConfigStr: string = '' +let runtimeConfig: IMihomoConfig = {} as IMihomoConfig // 辅助函数:处理带偏移量的规则 function processRulesWithOffset(ruleStrings: string[], currentRules: string[], isAppend = false) { diff --git a/src/main/lifecycle.ts b/src/main/lifecycle.ts index fe2046d..71c0616 100644 --- a/src/main/lifecycle.ts +++ b/src/main/lifecycle.ts @@ -14,8 +14,7 @@ done ${process.argv.join(' ')} & disown exit ` - spawn('sh', ['-c', `"${script}"`], { - shell: true, + spawn('sh', ['-c', script], { detached: true, stdio: 'ignore' }) @@ -57,7 +56,7 @@ export function setupPlatformSpecifics(): void { export function setupAppLifecycle(): void { app.on('before-quit', async (e) => { e.preventDefault() - triggerSysProxy(false) + await triggerSysProxy(false) await stopCore() app.exit() }) diff --git a/src/main/sys/sysproxy.ts b/src/main/sys/sysproxy.ts index 25b0ed3..3dec8d2 100644 --- a/src/main/sys/sysproxy.ts +++ b/src/main/sys/sysproxy.ts @@ -10,47 +10,52 @@ import axios from 'axios' import fs from 'fs' import { proxyLogger } from '../utils/logger' -let defaultBypass: string[] let triggerSysProxyTimer: NodeJS.Timeout | null = null const helperSocketPath = '/tmp/mihomo-party-helper.sock' -if (process.platform === 'linux') - defaultBypass = ['localhost', '127.0.0.1', '192.168.0.0/16', '10.0.0.0/8', '172.16.0.0/12', '::1'] -if (process.platform === 'darwin') - defaultBypass = [ - '127.0.0.1', - '192.168.0.0/16', - '10.0.0.0/8', - '172.16.0.0/12', - 'localhost', - '*.local', - '*.crashlytics.com', - '' - ] -if (process.platform === 'win32') - defaultBypass = [ - 'localhost', - '127.*', - '192.168.*', - '10.*', - '172.16.*', - '172.17.*', - '172.18.*', - '172.19.*', - '172.20.*', - '172.21.*', - '172.22.*', - '172.23.*', - '172.24.*', - '172.25.*', - '172.26.*', - '172.27.*', - '172.28.*', - '172.29.*', - '172.30.*', - '172.31.*', - '' - ] +const defaultBypass: string[] = (() => { + switch (process.platform) { + case 'linux': + return ['localhost', '127.0.0.1', '192.168.0.0/16', '10.0.0.0/8', '172.16.0.0/12', '::1'] + case 'darwin': + return [ + '127.0.0.1', + '192.168.0.0/16', + '10.0.0.0/8', + '172.16.0.0/12', + 'localhost', + '*.local', + '*.crashlytics.com', + '' + ] + case 'win32': + return [ + 'localhost', + '127.*', + '192.168.*', + '10.*', + '172.16.*', + '172.17.*', + '172.18.*', + '172.19.*', + '172.20.*', + '172.21.*', + '172.22.*', + '172.23.*', + '172.24.*', + '172.25.*', + '172.26.*', + '172.27.*', + '172.28.*', + '172.29.*', + '172.30.*', + '172.31.*', + '' + ] + default: + return ['localhost', '127.0.0.1', '192.168.0.0/16', '10.0.0.0/8', '172.16.0.0/12', '::1'] + } +})() export async function triggerSysProxy(enable: boolean): Promise { if (net.isOnline()) { diff --git a/src/main/utils/init.ts b/src/main/utils/init.ts index 9236505..03d1187 100644 --- a/src/main/utils/init.ts +++ b/src/main/utils/init.ts @@ -213,8 +213,12 @@ async function cleanup(): Promise { // logs const { maxLogDays = 7 } = await getAppConfig() const logs = await readdir(logDir()) + const datePattern = /^\d{4}-\d{2}-\d{2}/ for (const log of logs) { - const date = new Date(log.split('.')[0]) + const match = log.match(datePattern) + if (!match) continue + const date = new Date(match[0]) + if (isNaN(date.getTime())) continue const diff = Date.now() - date.getTime() if (diff > maxLogDays * 24 * 60 * 60 * 1000) { try { diff --git a/src/main/window.ts b/src/main/window.ts index 1e819f2..72085f0 100644 --- a/src/main/window.ts +++ b/src/main/window.ts @@ -118,7 +118,7 @@ function setupWindowEvents( }) window.on('session-end', async () => { - triggerSysProxy(false) + await triggerSysProxy(false) await stopCore() }) diff --git a/src/renderer/src/utils/ipc.ts b/src/renderer/src/utils/ipc.ts index e4d9c45..4d65b0d 100644 --- a/src/renderer/src/utils/ipc.ts +++ b/src/renderer/src/utils/ipc.ts @@ -196,10 +196,11 @@ export const writeTheme = (theme: string, css: string): Promise => invoke('writeTheme', theme, css) let applyThemeRunning = false -const applyThemeWaitList: string[] = [] +let pendingTheme: string | null = null + export async function applyTheme(theme: string): Promise { if (applyThemeRunning) { - applyThemeWaitList.push(theme) + pendingTheme = theme return } applyThemeRunning = true @@ -207,11 +208,10 @@ export async function applyTheme(theme: string): Promise { await invoke('applyTheme', theme) } finally { applyThemeRunning = false - if (applyThemeWaitList.length > 0) { - const nextTheme = applyThemeWaitList.shift() - if (nextTheme) { - await applyTheme(nextTheme) - } + if (pendingTheme !== null) { + const nextTheme = pendingTheme + pendingTheme = null + await applyTheme(nextTheme) } } }