feat: 首页开发

This commit is contained in:
2026-04-12 10:34:33 +08:00
parent a2a3bd2bee
commit 9a91093325
3 changed files with 83 additions and 34 deletions

View File

@@ -103,12 +103,18 @@ function buildEnv(exeDir) {
}
function getExePath() {
// 开发模式__dirname = .vite/build往上两级到项目根
// 打包模式:用 process.resourcesPath
// 根据平台和架构确定可执行文件名及目录
const isWin = process.platform === 'win32';
const exeName = isWin ? 'opencode.exe' : 'opencode';
if (app.isPackaged) {
return path.join(process.resourcesPath, 'opencode.exe');
return path.join(process.resourcesPath, exeName);
}
return path.join(__dirname, '..', '..', 'resources', 'windows', 'x64', 'opencode.exe');
// 开发模式__dirname = .vite/build往上两级到项目根
const platformDir = process.platform === 'darwin' ? 'darwin' : 'windows';
const archDir = process.arch === 'arm64' ? 'arm64' : 'x64';
return path.join(__dirname, '..', '..', 'resources', platformDir, archDir, exeName);
}
async function startOpencode() {
@@ -121,11 +127,16 @@ async function startOpencode() {
const exeDir = path.dirname(exePath);
await fs.promises.access(exePath, fs.constants.F_OK);
// macOS/Linux 需要确保可执行权限
if (process.platform !== 'win32') {
await fs.promises.chmod(exePath, 0o755);
}
opencodePort = await resolvePort();
opencodeProcess = spawn(exePath, ['serve', '--port', String(opencodePort)], {
cwd: exeDir,
windowsHide: true,
env: buildEnv(exeDir),
...(process.platform === 'win32' ? { windowsHide: true } : {}),
});
opencodeProcess.stdout?.on('data', (d) => console.log(`[opencode] ${d.toString().trim()}`));