revert: 回滚之前的错误修改,恢复为命令行模式
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -32,7 +32,6 @@ dist-electron/
|
|||||||
# XCOpenCodeWeb (来自独立仓库 https://github.com/anomalyco/XCOpenCodeWeb)
|
# XCOpenCodeWeb (来自独立仓库 https://github.com/anomalyco/XCOpenCodeWeb)
|
||||||
remote/xcopencodeweb/XCOpenCodeWeb.exe
|
remote/xcopencodeweb/XCOpenCodeWeb.exe
|
||||||
service/xcopencodeweb/XCOpenCodeWeb.exe
|
service/xcopencodeweb/XCOpenCodeWeb.exe
|
||||||
bin/*.exe
|
|
||||||
|
|
||||||
# Tools output
|
# Tools output
|
||||||
tools/tongyi/ppt_output/
|
tools/tongyi/ppt_output/
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
export const appConfig = {
|
|
||||||
opencode: {
|
|
||||||
mode: 'command', // 'command' | 'exe'
|
|
||||||
exePath: 'bin/XCOpenCodeWeb.exe',
|
|
||||||
port: 4096,
|
|
||||||
healthCheckInterval: 10000,
|
|
||||||
maxRestartAttempts: 3,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import { spawn, ChildProcess } from 'child_process';
|
import { spawn, ChildProcess } from 'child_process';
|
||||||
import { app } from 'electron';
|
|
||||||
import path from 'path';
|
|
||||||
import log from 'electron-log';
|
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;
|
const HEALTH_CHECK_TIMEOUT = 2000;
|
||||||
|
|
||||||
class OpenCodeService {
|
class OpenCodeService {
|
||||||
@@ -13,15 +13,7 @@ class OpenCodeService {
|
|||||||
private _isRunning = false;
|
private _isRunning = false;
|
||||||
|
|
||||||
get port(): number {
|
get port(): number {
|
||||||
return appConfig.opencode.port;
|
return OPENCODE_PORT;
|
||||||
}
|
|
||||||
|
|
||||||
get healthCheckInterval(): number {
|
|
||||||
return appConfig.opencode.healthCheckInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
get maxRestartAttempts(): number {
|
|
||||||
return appConfig.opencode.maxRestartAttempts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isRunning(): boolean {
|
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<string, string> {
|
private getAuthHeaders(): Record<string, string> {
|
||||||
const password = 'xc_opencode_password';
|
const password = 'xc_opencode_password';
|
||||||
const encoded = Buffer.from(`:${password}`).toString('base64');
|
const encoded = Buffer.from(`:${password}`).toString('base64');
|
||||||
@@ -76,14 +51,14 @@ class OpenCodeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async restart(): Promise<void> {
|
private async restart(): Promise<void> {
|
||||||
if (this.restartAttempts >= this.maxRestartAttempts) {
|
if (this.restartAttempts >= MAX_RESTART_ATTEMPTS) {
|
||||||
log.error('[OpenCodeService] Max restart attempts reached, giving up');
|
log.error('[OpenCodeService] Max restart attempts reached, giving up');
|
||||||
this._isRunning = false;
|
this._isRunning = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.restartAttempts++;
|
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.stop();
|
||||||
await this.start();
|
await this.start();
|
||||||
@@ -100,7 +75,7 @@ class OpenCodeService {
|
|||||||
log.warn('[OpenCodeService] Health check failed, attempting restart...');
|
log.warn('[OpenCodeService] Health check failed, attempting restart...');
|
||||||
await this.restart();
|
await this.restart();
|
||||||
}
|
}
|
||||||
}, this.healthCheckInterval);
|
}, HEALTH_CHECK_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
async start(): Promise<{ success: boolean; error?: string }> {
|
async start(): Promise<{ success: boolean; error?: string }> {
|
||||||
@@ -110,14 +85,9 @@ class OpenCodeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const opencodePath = this.getOpenCodePath();
|
log.info('[OpenCodeService] Starting OpenCode server...');
|
||||||
const opencodeArgs = this.getOpenCodeArgs();
|
|
||||||
const mode = appConfig.opencode.mode;
|
|
||||||
|
|
||||||
log.info(`[OpenCodeService] Starting OpenCode server (mode: ${mode})...`);
|
this.process = spawn('opencode', ['serve'], {
|
||||||
log.info(`[OpenCodeService] Path: ${opencodePath}`);
|
|
||||||
|
|
||||||
this.process = spawn(opencodePath, opencodeArgs, {
|
|
||||||
stdio: 'pipe',
|
stdio: 'pipe',
|
||||||
shell: true,
|
shell: true,
|
||||||
detached: false,
|
detached: false,
|
||||||
|
|||||||
@@ -122,12 +122,10 @@
|
|||||||
"dist-api/**/*",
|
"dist-api/**/*",
|
||||||
"shared/**/*",
|
"shared/**/*",
|
||||||
"tools/**/*",
|
"tools/**/*",
|
||||||
"bin/**/*",
|
|
||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"asarUnpack": [
|
"asarUnpack": [
|
||||||
"tools/**/*",
|
"tools/**/*"
|
||||||
"bin/**/*"
|
|
||||||
],
|
],
|
||||||
"win": {
|
"win": {
|
||||||
"target": "nsis"
|
"target": "nsis"
|
||||||
|
|||||||
Reference in New Issue
Block a user