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
This commit is contained in:
17
electron/utils/chrome/getChromePath.ts
Normal file
17
electron/utils/chrome/getChromePath.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
// 启动本地Chrome
|
||||
export function getChromePath () {
|
||||
if (process.platform === 'win32') {
|
||||
// "C:\Program Files\Google\Chrome\Application\chrome.exe"
|
||||
return 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe';
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||
}
|
||||
|
||||
if (process.platform === 'linux') {
|
||||
return 'google-chrome';
|
||||
}
|
||||
}
|
||||
7
electron/utils/chrome/getProfileDir.ts
Normal file
7
electron/utils/chrome/getProfileDir.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import path from "node:path";
|
||||
import { app } from 'electron';
|
||||
|
||||
// 多账号隔离
|
||||
export function getProfileDir (accountId: string) {
|
||||
return path.join(app.getPath('userData'), `profiles`, accountId);
|
||||
}
|
||||
21
electron/utils/chrome/isChromeRunning.ts
Normal file
21
electron/utils/chrome/isChromeRunning.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import http from 'http';
|
||||
|
||||
// Chrome是否已运行
|
||||
export async function isChromeRunning(): Promise<boolean> {
|
||||
try {
|
||||
return new Promise((resolve) => {
|
||||
const req = http.get('http://127.0.0.1:9222/json/version', (res: any) => {
|
||||
resolve(res.statusCode === 200);
|
||||
});
|
||||
|
||||
req.on('error', () => resolve(false));
|
||||
|
||||
req.setTimeout(1000, () => {
|
||||
req.destroy();
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
17
electron/utils/chrome/isPortInUse.ts
Normal file
17
electron/utils/chrome/isPortInUse.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import net from 'net';
|
||||
|
||||
// 检查端口占用
|
||||
export function isPortInUse (port: number) {
|
||||
return new Promise((resolve) => {
|
||||
const server = net.createServer();
|
||||
|
||||
server.once('error', (err: any) => resolve(true));
|
||||
|
||||
server.once('listening', () => {
|
||||
server.close();
|
||||
resolve(false);
|
||||
});
|
||||
|
||||
server.listen(port);
|
||||
});
|
||||
}
|
||||
51
electron/utils/chrome/launchLocalChrome.ts
Normal file
51
electron/utils/chrome/launchLocalChrome.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
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秒
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user