Files
zn-ai/electron/utils/chrome/launchLocalChrome.ts
duanshuwen 6615d11dd6 chore: restructure project and add i18n support
- Reorganize project structure with new electron and shared directories
- Add comprehensive i18n support with Chinese, English, and Japanese locales
- Update build configurations and TypeScript paths for new structure
- Add various UI components including chat interface and task management
- Include Windows release binaries and localization files
- Update dependencies and fix import paths throughout the codebase
2026-04-06 14:39:06 +08:00

52 lines
1.3 KiB
TypeScript

import { getChromePath } from './getChromePath';
import { getProfileDir } from './getProfileDir';
import { isPortInUse } from './isPortInUse';
import { isChromeRunning } from './isChromeRunning';
import { spawn } from 'child_process';
import log from 'electron-log';
// 启动本地浏览器
export async function launchLocalChrome() {
const chromePath = getChromePath();
// 多账号隔离
const profileDir = getProfileDir('default');
log.info(`Launching Chrome with user data dir: ${profileDir}`);
// 检查端口是否被占用
const portInUse = await isPortInUse(9222);
if (portInUse) {
log.info('Chrome already running on port 9222, skip launching.');
return;
}
if (await isChromeRunning()) {
log.info('Chrome already running, skip launching.');
return;
}
return new Promise((resolve, reject) => {
const chromeProcess = spawn(chromePath as string, [
'--remote-debugging-port=9222',
'--window-size=1920,1080',
'--window-position=0,0',
'--no-first-run',
`--user-data-dir=${profileDir}`,
'--no-default-browser-check',
'about:blank'
// '--window-maximized',
], {
detached: true,
stdio: 'ignore'
});
chromeProcess.on('error', reject);
// 延迟几秒等浏览器起来
setTimeout(() => {
resolve(0);
}, 1000); // 延迟1秒
});
}