修复fetch API超时实现:使用AbortController替换不支持的timeout参数

- 替换fetch中的timeout选项为AbortController + setTimeout实现
- 修复TypeScript编译错误:timeout不存在于RequestInit类型中
- 添加proper超时清理逻辑避免内存泄漏
- 更新CLAUDE.md文档:统一使用pnpm命令,补充IPC接口说明
This commit is contained in:
farion1231
2025-08-06 08:08:27 +08:00
parent 3bd65c2acb
commit b83652a162
2 changed files with 46 additions and 8 deletions

View File

@@ -9,25 +9,28 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## 开发命令
```bash
# 安装依赖
pnpm install
# 开发模式(同时启动 Vite 开发服务器和 Electron 主进程监听)
npm run dev
pnpm run dev
# 仅构建主进程
npm run build:main
pnpm run build:main
# 仅构建渲染进程
npm run build:renderer
pnpm run build:renderer
# 完整构建
npm run build
pnpm run build
# 启动应用(需要先构建)
npm start
pnpm start
# 或
electron .
# 打包发布
npm run dist
pnpm run dist
```
## 代码架构
@@ -69,3 +72,33 @@ npm run dist
- 渲染进程使用 `tsconfig.json` + Vite 构建
- 开发时渲染进程运行在 `localhost:3000`
- 生产时渲染进程文件位于 `dist/renderer/`
## 依赖管理
项目使用 npm 管理依赖,但检测到 `pnpm-lock.yaml`,建议使用 pnpm
```bash
# 安装依赖
pnpm install
# 或使用 npm
npm install
```
## 核心 IPC 接口
主要的 IPC 接口定义在 `src/shared/types.ts` 中的 `window.electronAPI`
- `getProviders()`: 获取所有供应商配置
- `switchProvider(providerId)`: 切换当前供应商
- `addProvider(provider)`: 添加新供应商
- `updateProvider(provider)`: 更新供应商配置
- `deleteProvider(id)`: 删除供应商
- `getClaudeCodeConfigPath()`: 获取 Claude Code 配置路径
- `selectConfigFile()`: 打开文件选择对话框
## 重要说明
- 供应商配置存储在 `electron-store` 中,自动持久化
- 切换供应商会直接修改 `~/.claude/settings.json` 中的 `ANTHROPIC_AUTH_TOKEN``ANTHROPIC_BASE_URL`
- 应用支持多平台打包Windows NSIS、macOS DMG、Linux AppImage

View File

@@ -119,10 +119,15 @@ ipcMain.handle('selectConfigFile', async () => {
ipcMain.handle('checkStatus', async (_, provider: Provider) => {
// 简单的连通性检查 - 向API地址发送HEAD请求
try {
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), 5000)
const response = await fetch(provider.apiUrl, {
method: 'HEAD',
timeout: 5000
signal: controller.signal
})
clearTimeout(timeoutId)
return response.ok
} catch (error) {
console.error('检查供应商状态失败:', error)