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