fix: 修复重启singbox时状态冲突并移除游戏加速与本地代理的耦合
修复singbox重启时立即停止可能导致的状态冲突,通过设置抑制标志和等待进程退出。 移除游戏加速与本地代理功能的耦合逻辑,使两者独立运行互不干扰。 优化.gitignore文件结构,增加注释分组。
This commit is contained in:
1 parent
e9b072fc92
commit
450ca875f9
5 files changed
+14
-30
No files matched your search
+9
-1
@@ -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/*
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<boolean> {
|
||||
async function startLocalProxy(reason: 'startup' | 'settings' = 'startup'): Promise<boolean> {
|
||||
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<void> {
|
||||
const gameStore = useGameStore()
|
||||
if (gameStore.getAcceleratingGame()) return
|
||||
await window.proxyMonitor.stop()
|
||||
await window.singbox.stop()
|
||||
running.value = false
|
||||
|
||||
Reference in new issue
Block a user