From 450ca875f9696309e38e2c65aaa004b5446dd9f8 Mon Sep 17 00:00:00 2001 From: ZenEcho Date: Wed, 18 Feb 2026 14:57:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=90=AFsing?= =?UTF-8?q?box=E6=97=B6=E7=8A=B6=E6=80=81=E5=86=B2=E7=AA=81=E5=B9=B6?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=B8=B8=E6=88=8F=E5=8A=A0=E9=80=9F=E4=B8=8E?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E4=BB=A3=E7=90=86=E7=9A=84=E8=80=A6=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复singbox重启时立即停止可能导致的状态冲突,通过设置抑制标志和等待进程退出。 移除游戏加速与本地代理功能的耦合逻辑,使两者独立运行互不干扰。 优化.gitignore文件结构,增加注释分组。 --- .gitignore | 10 +++++++++- dist-electron/main.js | 3 ++- electron/singbox/manager.ts | 3 ++- src/stores/games.ts | 17 ----------------- src/stores/local-proxy.ts | 11 +---------- 5 files changed, 14 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index e76932b..5df92d7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,14 +6,23 @@ yarn-debug.log* yarn-error.log* pnpm-debug.log* lerna-debug.log* + +# Coverage coverage + +# Dependencies node_modules + +# Build outputs dist dist-ssr dist-electron release *.local + +# App runtime data .lagzero-dev + # Editor directories and files .vscode/* .idea @@ -23,4 +32,3 @@ release *.njsproj *.sln *.sw? -dist-electron/* diff --git a/dist-electron/main.js b/dist-electron/main.js index b17faec..1d16539 100644 --- a/dist-electron/main.js +++ b/dist-electron/main.js @@ -10569,7 +10569,8 @@ class SingBoxManager { }); ipcMain.handle("singbox-stop", () => this.stop()); ipcMain.handle("singbox-restart", async (_, configContent) => { - this.stop(); + this.suppressNextStoppedStatus = true; + await this.stopAndWaitForExit(5e3); const configPath = path.join(app.getPath("userData"), "config.json"); await fs.writeFile(configPath, configContent); await this.start(configPath); diff --git a/electron/singbox/manager.ts b/electron/singbox/manager.ts index 30a5be6..69becb3 100644 --- a/electron/singbox/manager.ts +++ b/electron/singbox/manager.ts @@ -36,7 +36,8 @@ export class SingBoxManager { }) ipcMain.handle('singbox-stop', () => this.stop()) ipcMain.handle('singbox-restart', async (_, configContent: string) => { - this.stop() + this.suppressNextStoppedStatus = true + await this.stopAndWaitForExit(5000) const configPath = path.join(app.getPath('userData'), 'config.json') await fs.writeFile(configPath, configContent) await this.start(configPath) diff --git a/src/stores/games.ts b/src/stores/games.ts index 5913f41..b9244cc 100644 --- a/src/stores/games.ts +++ b/src/stores/games.ts @@ -5,7 +5,6 @@ import type { Game } from '@/types' import { useNodeStore } from './nodes' import { generateSingboxConfig } from '@/utils/singbox-config' import { useSettingsStore } from './settings' -import { useLocalProxyStore } from './local-proxy' export type { Game } @@ -194,7 +193,6 @@ export const useGameStore = defineStore('games', () => { const nodeStore = useNodeStore() const settingsStore = useSettingsStore() - const localProxyStore = useLocalProxyStore() const selectedNodeId = String(game.nodeId || '') const node = nodeStore.nodes.find(n => n.id === selectedNodeId || n.tag === selectedNodeId) @@ -204,15 +202,6 @@ export const useGameStore = defineStore('games', () => { throw new Error(msg) } - if (settingsStore.localProxyEnabled) { - try { - const port = await window.system.findAvailablePort(settingsStore.localProxyPort, 2) - settingsStore.localProxyPort = port - } catch (e) { - console.error('Failed to find available port for local proxy:', e) - } - } - try { const rawGame = toRaw(game) as Game const rawNode = toRaw(node) as any @@ -235,10 +224,6 @@ export const useGameStore = defineStore('games', () => { if (shouldEnableChainProxy) await window.proxyMonitor.start(String(rawGame.id), procs) else await window.proxyMonitor.stop() - if (settingsStore.localProxyEnabled) { - localProxyStore.setActiveNode(String(rawNode.id || rawNode.tag || '')) - } - setGameStatus(id, 'accelerating') } catch (e) { console.error('Failed to start game acceleration:', e) @@ -247,13 +232,11 @@ export const useGameStore = defineStore('games', () => { } async function stopGame(_id: string) { - const localProxyStore = useLocalProxyStore() try { // @ts-ignore await window.proxyMonitor.stop() resetAllAccelerationStatus() - await localProxyStore.startLocalProxy('game-stop') } catch (e) { console.error('Failed to stop game acceleration:', e) throw e diff --git a/src/stores/local-proxy.ts b/src/stores/local-proxy.ts index e759fae..6d82521 100644 --- a/src/stores/local-proxy.ts +++ b/src/stores/local-proxy.ts @@ -5,7 +5,6 @@ import type { NodeConfig } from '@/utils/protocol' import { generateSingboxConfig } from '@/utils/singbox-config' import { useNodeStore } from './nodes' import { useSettingsStore } from './settings' -import { useGameStore } from './games' const LOCAL_PROXY_HOSTS = ['www.google.com', 'www.apple.com'] @@ -67,12 +66,11 @@ export const useLocalProxyStore = defineStore('local-proxy', () => { return nodes[idx] || nodes[0] || null } - async function startLocalProxy(reason: 'startup' | 'settings' | 'game-stop' = 'startup'): Promise { + async function startLocalProxy(reason: 'startup' | 'settings' = 'startup'): Promise { if (starting.value) return false const settings = useSettingsStore() const nodeStore = useNodeStore() - const gameStore = useGameStore() if (!settings.localProxyEnabled) { running.value = false @@ -80,11 +78,6 @@ export const useLocalProxyStore = defineStore('local-proxy', () => { return false } - // Do not interrupt active acceleration unless we're recovering from stop. - if (reason !== 'game-stop' && gameStore.getAcceleratingGame()) { - return false - } - starting.value = true try { if (nodeStore.nodes.length === 0) { @@ -133,8 +126,6 @@ export const useLocalProxyStore = defineStore('local-proxy', () => { } async function stopLocalProxy(): Promise { - const gameStore = useGameStore() - if (gameStore.getAcceleratingGame()) return await window.proxyMonitor.stop() await window.singbox.stop() running.value = false