diff --git a/scripts/prepare.mjs b/scripts/prepare.mjs index 52838fb..186e343 100644 --- a/scripts/prepare.mjs +++ b/scripts/prepare.mjs @@ -336,9 +336,11 @@ function getSysproxyNodeName() { switch (platform) { case 'win32': - if (arch === 'x64') return isWin7Build ? 'sysproxy.win32-x64-msvc-win7.node' : 'sysproxy.win32-x64-msvc.node' + if (arch === 'x64') + return isWin7Build ? 'sysproxy.win32-x64-msvc-win7.node' : 'sysproxy.win32-x64-msvc.node' if (arch === 'arm64') return 'sysproxy.win32-arm64-msvc.node' - if (arch === 'ia32') return isWin7Build ? 'sysproxy.win32-ia32-msvc-win7.node' : 'sysproxy.win32-ia32-msvc.node' + if (arch === 'ia32') + return isWin7Build ? 'sysproxy.win32-ia32-msvc-win7.node' : 'sysproxy.win32-ia32-msvc.node' break case 'darwin': if (arch === 'x64') return 'sysproxy.darwin-x64.node' diff --git a/src/main/config/controledMihomo.ts b/src/main/config/controledMihomo.ts index 08d3d18..6db3be0 100644 --- a/src/main/config/controledMihomo.ts +++ b/src/main/config/controledMihomo.ts @@ -37,7 +37,10 @@ export async function getControledMihomoConfig(force = false): Promise { // 使用队列确保 profile 切换串行执行,避免竞态条件 let taskError: unknown = null changeProfileQueue = changeProfileQueue - .catch(() => { - }) + .catch(() => {}) .then(async () => { const { current } = await getProfileConfig() if (current === id) return @@ -221,7 +220,7 @@ export async function createProfile(item: Partial): Promise): Promise + const fetchSub = (useProxy: boolean, timeout: number) => fetchAndValidateSubscription({ ...baseOptions, useProxy, timeout }) let result: FetchResult if (newItem.useProxy || newItem.substore) { - result = await fetchSub(newItem.useProxy!, userItemTimeoutMs) + result = await fetchSub(Boolean(newItem.useProxy), userItemTimeoutMs) } else { try { result = await fetchSub(false, userItemTimeoutMs) } catch (directError) { try { - // smart fallback + // smart fallback result = await fetchSub(true, subscriptionTimeout) } catch { throw directError diff --git a/src/main/core/dns.ts b/src/main/core/dns.ts index ac3d899..4ac0211 100644 --- a/src/main/core/dns.ts +++ b/src/main/core/dns.ts @@ -44,11 +44,7 @@ async function getOriginDNS(): Promise { async function setDNS(dns: string): Promise { const service = await getDefaultService() try { - await axios.post( - 'http://localhost/dns', - { service, dns }, - { socketPath: helperSocketPath } - ) + await axios.post('http://localhost/dns', { service, dns }, { socketPath: helperSocketPath }) } catch { // fallback to osascript if helper not available const shell = `networksetup -setdnsservers "${service}" ${dns}` diff --git a/src/main/core/manager.ts b/src/main/core/manager.ts index 5b53a62..9b3bbc1 100644 --- a/src/main/core/manager.ts +++ b/src/main/core/manager.ts @@ -135,10 +135,7 @@ interface CoreConfig { // 准备核心配置 async function prepareCore(detached: boolean, skipStop = false): Promise { - const [appConfig, mihomoConfig] = await Promise.all([ - getAppConfig(), - getControledMihomoConfig() - ]) + const [appConfig, mihomoConfig] = await Promise.all([getAppConfig(), getControledMihomoConfig()]) const { core = 'mihomo', @@ -215,7 +212,10 @@ function spawnCoreProcess(config: CoreConfig): ChildProcess { }) if (process.platform === 'win32' && proc.pid) { - os.setPriority(proc.pid, os.constants.priority[cpuPriority as keyof typeof os.constants.priority]) + os.setPriority( + proc.pid, + os.constants.priority[cpuPriority as keyof typeof os.constants.priority] + ) } if (!detached) { @@ -294,7 +294,10 @@ function setupCoreListeners( new Promise((innerResolve) => { proc.stdout?.on('data', async (innerData) => { if ( - innerData.toString().toLowerCase().includes('start initial compatible provider default') + innerData + .toString() + .toLowerCase() + .includes('start initial compatible provider default') ) { try { mainWindow?.webContents.send('groupsUpdated') diff --git a/src/main/core/permissions.ts b/src/main/core/permissions.ts index cab1679..08bb508 100644 --- a/src/main/core/permissions.ts +++ b/src/main/core/permissions.ts @@ -191,7 +191,9 @@ async function checkHighPrivilegeMihomoProcess(): Promise { for (const executable of mihomoExecutables) { try { const { stdout } = await execPromise(`ps aux | grep ${executable} | grep -v grep`) - const lines = stdout.split('\n').filter((line) => line.trim() && line.includes(executable)) + const lines = stdout + .split('\n') + .filter((line) => line.trim() && line.includes(executable)) if (lines.length > 0) { foundProcesses = true @@ -337,7 +339,9 @@ export async function showErrorDialog(title: string, message: string): Promise Promise): Promise { +export async function validateTunPermissionsOnStartup( + _restartCore: () => Promise +): Promise { const { getControledMihomoConfig } = await import('../config') const { tun } = await getControledMihomoConfig() @@ -349,7 +353,9 @@ export async function validateTunPermissionsOnStartup(_restartCore: () => Promis if (!hasPermissions) { // 启动时没有权限,静默禁用 TUN,不弹窗打扰用户 - managerLogger.warn('TUN is enabled but insufficient permissions detected, auto-disabling TUN...') + managerLogger.warn( + 'TUN is enabled but insufficient permissions detected, auto-disabling TUN...' + ) await patchControledMihomoConfig({ tun: { enable: false } }) const { mainWindow } = await import('../index') diff --git a/src/main/sys/sysproxy.ts b/src/main/sys/sysproxy.ts index 18bea16..146be65 100644 --- a/src/main/sys/sysproxy.ts +++ b/src/main/sys/sysproxy.ts @@ -114,9 +114,7 @@ async function disableSysProxy(): Promise { await stopPacServer() if (process.platform === 'darwin') { - await helperRequest(() => - axios.get('http://localhost/off', { socketPath: helperSocketPath }) - ) + await helperRequest(() => axios.get('http://localhost/off', { socketPath: helperSocketPath })) } else { // Windows / Linux 直接使用 sysproxy-rs try { diff --git a/src/main/utils/appName.ts b/src/main/utils/appName.ts index a1c63f2..479f5a4 100644 --- a/src/main/utils/appName.ts +++ b/src/main/utils/appName.ts @@ -1,8 +1,8 @@ import fs from 'fs' import path from 'path' +import { spawnSync } from 'child_process' import plist from 'plist' import { findBestAppPath, isIOSApp } from './icon' -import { spawnSync } from 'child_process' export async function getAppName(appPath: string): Promise { if (process.platform === 'darwin') { @@ -20,7 +20,7 @@ export async function getAppName(appPath: string): Promise { try { const appName = getLocalizedAppName(targetPath) if (appName) return appName - } catch (err) { + } catch { // ignore } @@ -33,7 +33,7 @@ export async function getAppName(appPath: string): Promise { } else { // ignore } - } catch (err) { + } catch { // ignore } } diff --git a/src/main/utils/chromeRequest.ts b/src/main/utils/chromeRequest.ts index dec696e..47dde71 100644 --- a/src/main/utils/chromeRequest.ts +++ b/src/main/utils/chromeRequest.ts @@ -74,8 +74,7 @@ export async function request( } } - const cleanup = (): void => { - } + const cleanup = (): void => {} setupProxy() .then(() => { diff --git a/src/main/utils/github.ts b/src/main/utils/github.ts index 95a9621..bf5a041 100644 --- a/src/main/utils/github.ts +++ b/src/main/utils/github.ts @@ -1,4 +1,4 @@ -import { createWriteStream, createReadStream , existsSync, rmSync } from 'fs' +import { createWriteStream, createReadStream, existsSync, rmSync } from 'fs' import { writeFile } from 'fs/promises' import { execSync } from 'child_process' import { platform } from 'os' diff --git a/src/main/utils/init.ts b/src/main/utils/init.ts index 0fd1810..060a0be 100644 --- a/src/main/utils/init.ts +++ b/src/main/utils/init.ts @@ -190,7 +190,10 @@ async function initFiles(): Promise { } catch (error: unknown) { const code = (error as NodeJS.ErrnoException).code // 文件被占用或权限问题,如果目标已存在则跳过 - if ((code === 'EPERM' || code === 'EBUSY' || code === 'EACCES') && existsSync(targetPath)) { + if ( + (code === 'EPERM' || code === 'EBUSY' || code === 'EACCES') && + existsSync(targetPath) + ) { await initLogger.warn(`Skipping ${file}: file is in use or permission denied`) return } @@ -318,7 +321,11 @@ async function migrateMihomoConfig(): Promise { config['skip-auth-prefixes'][0] === '127.0.0.1/32' && !config['skip-auth-prefixes'].includes('::1/128') ) { - patches['skip-auth-prefixes'] = ['127.0.0.1/32', '::1/128', ...config['skip-auth-prefixes'].slice(1)] + patches['skip-auth-prefixes'] = [ + '127.0.0.1/32', + '::1/128', + ...config['skip-auth-prefixes'].slice(1) + ] } // 其他默认值 diff --git a/src/main/window.ts b/src/main/window.ts index 7d5143a..4b374e6 100644 --- a/src/main/window.ts +++ b/src/main/window.ts @@ -12,7 +12,12 @@ export let mainWindow: BrowserWindow | null = null let quitTimeout: NodeJS.Timeout | null = null export async function createWindow(): Promise { - const { useWindowFrame = false, silentStart = false, autoQuitWithoutCore = false, autoQuitWithoutCoreDelay = 60 } = await getAppConfig() + const { + useWindowFrame = false, + silentStart = false, + autoQuitWithoutCore = false, + autoQuitWithoutCoreDelay = 60 + } = await getAppConfig() const mainWindowState = windowStateKeeper({ defaultWidth: 800, defaultHeight: 600, @@ -47,7 +52,11 @@ export async function createWindow(): Promise { }) mainWindowState.manage(mainWindow) - setupWindowEvents(mainWindow, mainWindowState, { silentStart, autoQuitWithoutCore, autoQuitWithoutCoreDelay }) + setupWindowEvents(mainWindow, mainWindowState, { + silentStart, + autoQuitWithoutCore, + autoQuitWithoutCoreDelay + }) if (is.dev) { mainWindow.webContents.openDevTools() diff --git a/src/native/sysproxy/index.js b/src/native/sysproxy/index.js index 3c6d4a3..147988f 100644 --- a/src/native/sysproxy/index.js +++ b/src/native/sysproxy/index.js @@ -34,8 +34,10 @@ function getBindingName() { const win7 = isWindows7() switch (platform) { case 'win32': - if (arch === 'x64') return win7 ? 'sysproxy.win32-x64-msvc-win7.node' : 'sysproxy.win32-x64-msvc.node' - if (arch === 'ia32') return win7 ? 'sysproxy.win32-ia32-msvc-win7.node' : 'sysproxy.win32-ia32-msvc.node' + if (arch === 'x64') + return win7 ? 'sysproxy.win32-x64-msvc-win7.node' : 'sysproxy.win32-x64-msvc.node' + if (arch === 'ia32') + return win7 ? 'sysproxy.win32-ia32-msvc-win7.node' : 'sysproxy.win32-ia32-msvc.node' if (arch === 'arm64') return 'sysproxy.win32-arm64-msvc.node' break case 'darwin': diff --git a/src/renderer/src/components/connections/connection-item.tsx b/src/renderer/src/components/connections/connection-item.tsx index 7ff32aa..e73cb6f 100644 --- a/src/renderer/src/components/connections/connection-item.tsx +++ b/src/renderer/src/components/connections/connection-item.tsx @@ -169,4 +169,4 @@ const ConnectionItem = memo(ConnectionItemComponent, (prevProps, nextProps) => { ) }) -export default ConnectionItem \ No newline at end of file +export default ConnectionItem diff --git a/src/renderer/src/components/resources/proxy-provider.tsx b/src/renderer/src/components/resources/proxy-provider.tsx index 7bd4236..556e8b2 100644 --- a/src/renderer/src/components/resources/proxy-provider.tsx +++ b/src/renderer/src/components/resources/proxy-provider.tsx @@ -126,7 +126,9 @@ const ProxyProvider: React.FC = () => {