From 35cb750d19e078d00c7b2fdc15f09d0622f298fe Mon Sep 17 00:00:00 2001 From: farion1231 Date: Tue, 5 Aug 2025 09:51:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Electron=20=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E7=AA=97=E5=8F=A3=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修正 Electron 依赖版本为 28.0.0(解决安装问题) - 更新 package.json 中的启动脚本,改进并发命令执行 - 修正主进程入口文件路径配置 - 调整 TypeScript 编译配置的根目录设置 - 添加 Windows 开发环境启动脚本 start-dev.bat - 更新 .gitignore 排除编译产物和锁文件 问题原因:pnpm 默认阻止了 Electron 安装脚本执行,导致应用无法正常启动 --- .gitignore | 5 ++++- package.json | 10 ++++++---- src/main/index.ts | 9 ++++++++- start-dev.bat | 15 +++++++++++++++ tsconfig.main.json | 2 +- 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 start-dev.bat diff --git a/.gitignore b/.gitignore index ac95d79..846519e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ release/ .DS_Store *.log .env -.env.local \ No newline at end of file +.env.local +*.tsbuildinfo +.npmrc +pnpm-lock.yaml \ No newline at end of file diff --git a/package.json b/package.json index ec8e24b..7f19f66 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,12 @@ "name": "cc-switch", "version": "1.0.0", "description": "Claude Code 供应商切换工具", - "main": "dist/main.js", + "main": "dist/main/index.js", "scripts": { - "dev": "concurrently \"npm run dev:main\" \"npm run dev:renderer\"", - "dev:main": "tsc -w -p tsconfig.main.json", + "dev": "concurrently -k \"npm:dev:renderer\" \"npm:dev:electron:watch\"", + "dev:electron": "tsc -p tsconfig.main.json && electron .", + "dev:electron:watch": "tsc -p tsconfig.main.json && concurrently -k \"tsc -w -p tsconfig.main.json\" \"npm:electron\"", + "electron": "electron .", "dev:renderer": "vite", "build": "npm run build:renderer && npm run build:main", "build:main": "tsc -p tsconfig.main.json", @@ -22,7 +24,7 @@ "@types/react-dom": "^18.2.0", "@vitejs/plugin-react": "^4.2.0", "concurrently": "^8.2.0", - "electron": "^28.0.0", + "electron": "28.0.0", "electron-builder": "^24.0.0", "typescript": "^5.3.0", "vite": "^5.0.0" diff --git a/src/main/index.ts b/src/main/index.ts index 4bd3d31..82185c8 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -13,7 +13,7 @@ function createWindow() { width: 800, height: 600, webPreferences: { - preload: path.join(__dirname, 'preload.js'), + preload: path.join(__dirname, '../main/preload.js'), contextIsolation: true, nodeIntegration: false }, @@ -72,6 +72,13 @@ ipcMain.handle('deleteProvider', (_, id: string) => { return true }) +ipcMain.handle('updateProvider', (_, provider: Provider) => { + const providers = store.get('providers', {}) + providers[provider.id] = provider + store.set('providers', providers) + return true +}) + ipcMain.handle('checkStatus', async (_, provider: Provider) => { return await checkProviderStatus(provider) }) diff --git a/start-dev.bat b/start-dev.bat new file mode 100644 index 0000000..77ad180 --- /dev/null +++ b/start-dev.bat @@ -0,0 +1,15 @@ +@echo off +echo Starting CC Switch Development Server... +echo. + +echo [1/2] Starting Vite dev server... +start /B cmd /c "pnpm run dev:renderer" + +echo [2/2] Waiting for Vite to start... +timeout /t 5 /nobreak > nul + +echo Starting Electron... +pnpm run dev:electron + +echo. +echo Development server started! \ No newline at end of file diff --git a/tsconfig.main.json b/tsconfig.main.json index 5d0c13c..7ce821b 100644 --- a/tsconfig.main.json +++ b/tsconfig.main.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.node.json", "compilerOptions": { "outDir": "dist", - "rootDir": "src/main", + "rootDir": "src", "types": ["node"] }, "include": ["src/main/**/*", "src/shared/**/*"]