From 016666b93187e32b04bffd1a6df121fc47dcb917 Mon Sep 17 00:00:00 2001 From: Wendong-Fan Date: Sat, 4 Oct 2025 22:39:59 +0800 Subject: [PATCH 1/2] enhance: browser_install PR451 --- electron/main/install-deps.ts | 81 ++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 20 deletions(-) diff --git a/electron/main/install-deps.ts b/electron/main/install-deps.ts index ce524a55d..e57d1eaed 100644 --- a/electron/main/install-deps.ts +++ b/electron/main/install-deps.ts @@ -333,11 +333,28 @@ export async function installDependencies(version: string): Promise => { try { // Find the hybrid_browser_toolkit ts directory in the virtual environment - const sitePackagesPath = path.join(venvPath, 'lib', 'site-packages'); + // Need to determine the Python version to construct the correct path + let sitePackagesPath: string | null = null; + const libPath = path.join(venvPath, 'lib'); + + // Try to find the site-packages directory (it varies by Python version) + if (fs.existsSync(libPath)) { + const libContents = fs.readdirSync(libPath); + const pythonDir = libContents.find(name => name.startsWith('python')); + if (pythonDir) { + sitePackagesPath = path.join(libPath, pythonDir, 'site-packages'); + } + } + + if (!sitePackagesPath || !fs.existsSync(sitePackagesPath)) { + log.warn('[DEPS INSTALL] site-packages directory not found in venv, skipping npm install'); + return true; // Not an error if the venv structure is different + } + const toolkitPath = path.join(sitePackagesPath, 'camel', 'toolkits', 'hybrid_browser_toolkit', 'ts'); if (!fs.existsSync(toolkitPath)) { - log.warn('[DEPS INSTALL] hybrid_browser_toolkit ts directory not found, skipping npm install'); + log.warn('[DEPS INSTALL] hybrid_browser_toolkit ts directory not found at ' + toolkitPath + ', skipping npm install'); return true; // Not an error if the toolkit isn't installed } @@ -350,8 +367,9 @@ export async function installDependencies(version: string): Promise { + const npmExists = await new Promise(resolve => { testNpm.on('close', (code) => resolve(code === 0)); + testNpm.on('error', () => resolve(false)); }); if (npmExists) { @@ -375,15 +393,19 @@ export async function installDependencies(version: string): Promise((resolve, reject) => { - npmInstall.stdout.on('data', (data) => { - log.info(`[DEPS INSTALL] npm install: ${data}`); - safeMainWindowSend('install-dependencies-log', { type: 'stdout', data: data.toString() }); - }); + if (npmInstall.stdout) { + npmInstall.stdout.on('data', (data) => { + log.info(`[DEPS INSTALL] npm install: ${data}`); + safeMainWindowSend('install-dependencies-log', { type: 'stdout', data: data.toString() }); + }); + } - npmInstall.stderr.on('data', (data) => { - log.warn(`[DEPS INSTALL] npm install stderr: ${data}`); - safeMainWindowSend('install-dependencies-log', { type: 'stderr', data: data.toString() }); - }); + if (npmInstall.stderr) { + npmInstall.stderr.on('data', (data) => { + log.warn(`[DEPS INSTALL] npm install stderr: ${data}`); + safeMainWindowSend('install-dependencies-log', { type: 'stderr', data: data.toString() }); + }); + } npmInstall.on('close', (code) => { if (code === 0) { @@ -394,6 +416,11 @@ export async function installDependencies(version: string): Promise { + log.error(`[DEPS INSTALL] npm install process error: ${err}`); + reject(err); + }); }); // Run npm build (use the same npm command as install) @@ -414,16 +441,20 @@ export async function installDependencies(version: string): Promise((resolve, reject) => { - npmBuild.stdout.on('data', (data) => { - log.info(`[DEPS INSTALL] npm build: ${data}`); - safeMainWindowSend('install-dependencies-log', { type: 'stdout', data: data.toString() }); - }); + if (npmBuild.stdout) { + npmBuild.stdout.on('data', (data) => { + log.info(`[DEPS INSTALL] npm build: ${data}`); + safeMainWindowSend('install-dependencies-log', { type: 'stdout', data: data.toString() }); + }); + } - npmBuild.stderr.on('data', (data) => { - // TypeScript build warnings are common, don't treat as errors - log.info(`[DEPS INSTALL] npm build output: ${data}`); - safeMainWindowSend('install-dependencies-log', { type: 'stdout', data: data.toString() }); - }); + if (npmBuild.stderr) { + npmBuild.stderr.on('data', (data) => { + // TypeScript build warnings are common, don't treat as errors + log.info(`[DEPS INSTALL] npm build output: ${data}`); + safeMainWindowSend('install-dependencies-log', { type: 'stdout', data: data.toString() }); + }); + } npmBuild.on('close', (code) => { if (code === 0) { @@ -434,6 +465,11 @@ export async function installDependencies(version: string): Promise { + log.error(`[DEPS INSTALL] npm build process error: ${err}`); + reject(err); + }); }); // Optionally install Playwright browsers @@ -461,6 +497,11 @@ export async function installDependencies(version: string): Promise { + log.warn('[DEPS INSTALL] Playwright installation process error:', err); + resolve(); // Non-critical, continue + }); }); } catch (error) { log.warn('[DEPS INSTALL] Failed to install Playwright browsers:', error); From 076e232d58a8482ac3848bbe3c0c6e347422670b Mon Sep 17 00:00:00 2001 From: puzhen <1303385763@qq.com> Date: Sat, 4 Oct 2025 20:32:02 +0200 Subject: [PATCH 2/2] add individual npm cache dir --- electron/main/init.ts | 6 ++++++ electron/main/install-deps.ts | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/electron/main/init.ts b/electron/main/init.ts index b761e0289..11ed6ef38 100644 --- a/electron/main/init.ts +++ b/electron/main/init.ts @@ -153,11 +153,17 @@ export async function startBackend(setPort?: (port: number) => void): Promise