From 3df40def1ecbbed7151e1126413859ca010e98c6 Mon Sep 17 00:00:00 2001 From: farion1231 Date: Tue, 5 Aug 2025 20:30:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=B5=8F=E8=A7=88=E9=80=89=E6=8B=A9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在主进程添加文件选择对话框,支持选择 settings.json 配置文件 - 更新类型定义和预加载脚本,添加 selectConfigFile API - 在界面底部配置路径区域添加"浏览"按钮 - 优化样式布局,使配置路径和浏览按钮水平排列 - 修复 React 导入警告,移除未使用的 React 导入 --- src/main/index.ts | 22 +++++++++++++++++++++- src/main/preload.ts | 3 ++- src/renderer/App.css | 19 +++++++++++++++++++ src/renderer/App.tsx | 18 ++++++++++++++++-- src/shared/types.ts | 1 + 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 82185c8..3cb3123 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,4 +1,4 @@ -import { app, BrowserWindow, ipcMain } from 'electron' +import { app, BrowserWindow, ipcMain, dialog } from 'electron' import path from 'path' import Store from 'electron-store' import { Provider, AppConfig } from '../shared/types' @@ -98,4 +98,24 @@ ipcMain.handle('switchProvider', async (_, providerId: string) => { ipcMain.handle('getClaudeCodeConfigPath', () => { return getClaudeCodeConfig().path +}) + +ipcMain.handle('selectConfigFile', async () => { + if (!mainWindow) return null + + const result = await dialog.showOpenDialog(mainWindow, { + properties: ['openFile'], + title: '选择 Claude Code 配置文件', + filters: [ + { name: 'JSON 文件', extensions: ['json'] }, + { name: '所有文件', extensions: ['*'] } + ], + defaultPath: 'settings.json' + }) + + if (result.canceled || result.filePaths.length === 0) { + return null + } + + return result.filePaths[0] }) \ No newline at end of file diff --git a/src/main/preload.ts b/src/main/preload.ts index 6854a8e..7b4b94f 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -9,5 +9,6 @@ contextBridge.exposeInMainWorld('electronAPI', { updateProvider: (provider: Provider) => ipcRenderer.invoke('updateProvider', provider), checkStatus: (provider: Provider) => ipcRenderer.invoke('checkStatus', provider), switchProvider: (providerId: string) => ipcRenderer.invoke('switchProvider', providerId), - getClaudeCodeConfigPath: () => ipcRenderer.invoke('getClaudeCodeConfigPath') + getClaudeCodeConfigPath: () => ipcRenderer.invoke('getClaudeCodeConfigPath'), + selectConfigFile: () => ipcRenderer.invoke('selectConfigFile') }) \ No newline at end of file diff --git a/src/renderer/App.css b/src/renderer/App.css index 53c640e..38fb59b 100644 --- a/src/renderer/App.css +++ b/src/renderer/App.css @@ -69,4 +69,23 @@ border-radius: 4px; font-size: 0.9rem; color: #7f8c8d; + display: flex; + justify-content: space-between; + align-items: center; +} + +.browse-btn { + padding: 0.5rem 1rem; + border: none; + border-radius: 4px; + background: #3498db; + color: white; + cursor: pointer; + font-size: 0.9rem; + transition: all 0.2s; + margin-left: 1rem; +} + +.browse-btn:hover { + background: #2980b9; } \ No newline at end of file diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 6f1890e..fb0fd50 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react' +import { useState, useEffect } from 'react' import { Provider, ProviderStatus } from '../shared/types' import ProviderList from './components/ProviderList' import AddProviderModal from './components/AddProviderModal' @@ -99,6 +99,13 @@ function App() { } } + const handleSelectConfigFile = async () => { + const selectedPath = await window.electronAPI.selectConfigFile() + if (selectedPath) { + setConfigPath(selectedPath) + } + } + return (
@@ -133,7 +140,14 @@ function App() { {configPath && (
- 配置文件位置: {configPath} + 配置文件位置: {configPath} +
)} diff --git a/src/shared/types.ts b/src/shared/types.ts index 0d7f4dd..b526092 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -29,6 +29,7 @@ declare global { checkStatus: (provider: Provider) => Promise switchProvider: (providerId: string) => Promise getClaudeCodeConfigPath: () => Promise + selectConfigFile: () => Promise } } } \ No newline at end of file