From 53c104540611b47432f22de11812b64f69a8050e Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Fri, 13 Mar 2026 20:42:02 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20=E5=9B=9E=E6=BB=9A=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E4=B8=BA=E5=91=BD=E4=BB=A4=E8=A1=8C=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - electron/config.ts | 9 ------ electron/services/opencodeService.ts | 48 ++++++---------------------- package.json | 4 +-- 4 files changed, 10 insertions(+), 52 deletions(-) delete mode 100644 electron/config.ts diff --git a/.gitignore b/.gitignore index f0dfd3b..03fcb72 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,6 @@ dist-electron/ # XCOpenCodeWeb (来自独立仓库 https://github.com/anomalyco/XCOpenCodeWeb) remote/xcopencodeweb/XCOpenCodeWeb.exe service/xcopencodeweb/XCOpenCodeWeb.exe -bin/*.exe # Tools output tools/tongyi/ppt_output/ diff --git a/electron/config.ts b/electron/config.ts deleted file mode 100644 index aaa158a..0000000 --- a/electron/config.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const appConfig = { - opencode: { - mode: 'command', // 'command' | 'exe' - exePath: 'bin/XCOpenCodeWeb.exe', - port: 4096, - healthCheckInterval: 10000, - maxRestartAttempts: 3, - }, -} diff --git a/electron/services/opencodeService.ts b/electron/services/opencodeService.ts index 45b23a4..a46e06e 100644 --- a/electron/services/opencodeService.ts +++ b/electron/services/opencodeService.ts @@ -1,9 +1,9 @@ import { spawn, ChildProcess } from 'child_process'; -import { app } from 'electron'; -import path from 'path'; import log from 'electron-log'; -import { appConfig } from '../config'; +const OPENCODE_PORT = 4096; +const HEALTH_CHECK_INTERVAL = 10000; +const MAX_RESTART_ATTEMPTS = 3; const HEALTH_CHECK_TIMEOUT = 2000; class OpenCodeService { @@ -13,15 +13,7 @@ class OpenCodeService { private _isRunning = false; get port(): number { - return appConfig.opencode.port; - } - - get healthCheckInterval(): number { - return appConfig.opencode.healthCheckInterval; - } - - get maxRestartAttempts(): number { - return appConfig.opencode.maxRestartAttempts; + return OPENCODE_PORT; } isRunning(): boolean { @@ -36,23 +28,6 @@ class OpenCodeService { }; } - private getOpenCodePath(): string { - if (appConfig.opencode.mode === 'exe') { - const basePath = app.isPackaged - ? path.dirname(app.getPath('exe')) - : path.join(process.cwd(), 'bin'); - return path.join(basePath, appConfig.opencode.exePath); - } - return 'opencode'; - } - - private getOpenCodeArgs(): string[] { - if (appConfig.opencode.mode === 'exe') { - return ['serve']; - } - return ['serve']; - } - private getAuthHeaders(): Record { const password = 'xc_opencode_password'; const encoded = Buffer.from(`:${password}`).toString('base64'); @@ -76,14 +51,14 @@ class OpenCodeService { } private async restart(): Promise { - if (this.restartAttempts >= this.maxRestartAttempts) { + if (this.restartAttempts >= MAX_RESTART_ATTEMPTS) { log.error('[OpenCodeService] Max restart attempts reached, giving up'); this._isRunning = false; return; } this.restartAttempts++; - log.info(`[OpenCodeService] Attempting restart (${this.restartAttempts}/${this.maxRestartAttempts})...`); + log.info(`[OpenCodeService] Attempting restart (${this.restartAttempts}/${MAX_RESTART_ATTEMPTS})...`); await this.stop(); await this.start(); @@ -100,7 +75,7 @@ class OpenCodeService { log.warn('[OpenCodeService] Health check failed, attempting restart...'); await this.restart(); } - }, this.healthCheckInterval); + }, HEALTH_CHECK_INTERVAL); } async start(): Promise<{ success: boolean; error?: string }> { @@ -110,14 +85,9 @@ class OpenCodeService { } try { - const opencodePath = this.getOpenCodePath(); - const opencodeArgs = this.getOpenCodeArgs(); - const mode = appConfig.opencode.mode; + log.info('[OpenCodeService] Starting OpenCode server...'); - log.info(`[OpenCodeService] Starting OpenCode server (mode: ${mode})...`); - log.info(`[OpenCodeService] Path: ${opencodePath}`); - - this.process = spawn(opencodePath, opencodeArgs, { + this.process = spawn('opencode', ['serve'], { stdio: 'pipe', shell: true, detached: false, diff --git a/package.json b/package.json index 04d07db..2f60ff8 100644 --- a/package.json +++ b/package.json @@ -122,12 +122,10 @@ "dist-api/**/*", "shared/**/*", "tools/**/*", - "bin/**/*", "package.json" ], "asarUnpack": [ - "tools/**/*", - "bin/**/*" + "tools/**/*" ], "win": { "target": "nsis"