移除状态检测功能,专注核心切换功能
- 删除 checkProviderStatus 函数和相关 IPC 处理 - 移除 App.tsx 中所有状态检测相关的状态和函数 - 简化 ProviderList.tsx,去除状态显示和检查按钮 - 清理 types.ts 中的 ProviderStatus 类型定义 - 界面更简洁,专注于供应商切换这一核心功能
This commit is contained in:
@@ -2,7 +2,7 @@ import { app, BrowserWindow, ipcMain, dialog } from 'electron'
|
||||
import path from 'path'
|
||||
import Store from 'electron-store'
|
||||
import { Provider, AppConfig } from '../shared/types'
|
||||
import { checkProviderStatus, switchProvider, getClaudeCodeConfig } from './services'
|
||||
import { switchProvider, getClaudeCodeConfig } from './services'
|
||||
|
||||
const store = new Store<AppConfig>()
|
||||
|
||||
@@ -79,10 +79,6 @@ ipcMain.handle('updateProvider', (_, provider: Provider) => {
|
||||
return true
|
||||
})
|
||||
|
||||
ipcMain.handle('checkStatus', async (_, provider: Provider) => {
|
||||
return await checkProviderStatus(provider)
|
||||
})
|
||||
|
||||
ipcMain.handle('switchProvider', async (_, providerId: string) => {
|
||||
const providers = store.get('providers', {})
|
||||
const provider = providers[providerId]
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import os from 'os'
|
||||
import { Provider, ProviderStatus } from '../shared/types'
|
||||
|
||||
export async function checkProviderStatus(
|
||||
provider: Provider
|
||||
): Promise<ProviderStatus> {
|
||||
// 暂时返回未检查状态
|
||||
return {
|
||||
isOnline: false,
|
||||
responseTime: -1,
|
||||
lastChecked: new Date(),
|
||||
error: '功能开发中'
|
||||
}
|
||||
}
|
||||
import { Provider } from '../shared/types'
|
||||
|
||||
export function getClaudeCodeConfig() {
|
||||
// Claude Code 配置文件路径
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Provider, ProviderStatus } from '../shared/types'
|
||||
import { Provider } from '../shared/types'
|
||||
import ProviderList from './components/ProviderList'
|
||||
import AddProviderModal from './components/AddProviderModal'
|
||||
import EditProviderModal from './components/EditProviderModal'
|
||||
@@ -8,9 +8,7 @@ import './App.css'
|
||||
function App() {
|
||||
const [providers, setProviders] = useState<Record<string, Provider>>({})
|
||||
const [currentProviderId, setCurrentProviderId] = useState<string>('')
|
||||
const [statuses, setStatuses] = useState<Record<string, ProviderStatus>>({})
|
||||
const [isAddModalOpen, setIsAddModalOpen] = useState(false)
|
||||
const [checkingStatus, setCheckingStatus] = useState<Record<string, boolean>>({})
|
||||
const [configPath, setConfigPath] = useState<string>('')
|
||||
const [editingProviderId, setEditingProviderId] = useState<string | null>(null)
|
||||
|
||||
@@ -33,32 +31,6 @@ function App() {
|
||||
setConfigPath(path)
|
||||
}
|
||||
|
||||
const checkAllStatuses = async () => {
|
||||
// 功能开发中
|
||||
alert('状态检查功能开发中')
|
||||
}
|
||||
|
||||
const checkSingleStatus = async (providerId: string) => {
|
||||
const provider = providers[providerId]
|
||||
if (!provider) return
|
||||
|
||||
setCheckingStatus(prev => ({ ...prev, [providerId]: true }))
|
||||
|
||||
try {
|
||||
// 暂时显示开发中状态
|
||||
const status: ProviderStatus = {
|
||||
isOnline: false,
|
||||
responseTime: -1,
|
||||
lastChecked: new Date(),
|
||||
error: '功能开发中'
|
||||
}
|
||||
setStatuses(prev => ({ ...prev, [providerId]: status }))
|
||||
} catch (error) {
|
||||
console.error('检查状态失败:', error)
|
||||
} finally {
|
||||
setCheckingStatus(prev => ({ ...prev, [providerId]: false }))
|
||||
}
|
||||
}
|
||||
|
||||
const handleAddProvider = async (provider: Omit<Provider, 'id'>) => {
|
||||
const newProvider: Provider = {
|
||||
@@ -111,12 +83,6 @@ function App() {
|
||||
<header className="app-header">
|
||||
<h1>Claude Code 供应商切换器</h1>
|
||||
<div className="header-actions">
|
||||
<button
|
||||
className="refresh-btn"
|
||||
onClick={checkAllStatuses}
|
||||
>
|
||||
检查状态(开发中)
|
||||
</button>
|
||||
<button
|
||||
className="add-btn"
|
||||
onClick={() => setIsAddModalOpen(true)}
|
||||
@@ -130,12 +96,9 @@ function App() {
|
||||
<ProviderList
|
||||
providers={providers}
|
||||
currentProviderId={currentProviderId}
|
||||
statuses={statuses}
|
||||
checkingStatus={checkingStatus}
|
||||
onSwitch={handleSwitchProvider}
|
||||
onDelete={handleDeleteProvider}
|
||||
onEdit={setEditingProviderId}
|
||||
onCheckStatus={checkSingleStatus}
|
||||
/>
|
||||
|
||||
{configPath && (
|
||||
|
||||
@@ -1,45 +1,22 @@
|
||||
import React from 'react'
|
||||
import { Provider, ProviderStatus } from '../../shared/types'
|
||||
import { Provider } from '../../shared/types'
|
||||
import './ProviderList.css'
|
||||
|
||||
interface ProviderListProps {
|
||||
providers: Record<string, Provider>
|
||||
currentProviderId: string
|
||||
statuses: Record<string, ProviderStatus>
|
||||
checkingStatus: Record<string, boolean>
|
||||
onSwitch: (id: string) => void
|
||||
onDelete: (id: string) => void
|
||||
onEdit: (id: string) => void
|
||||
onCheckStatus: (id: string) => void
|
||||
}
|
||||
|
||||
const ProviderList: React.FC<ProviderListProps> = ({
|
||||
providers,
|
||||
currentProviderId,
|
||||
statuses,
|
||||
checkingStatus,
|
||||
onSwitch,
|
||||
onDelete,
|
||||
onEdit,
|
||||
onCheckStatus
|
||||
onEdit
|
||||
}) => {
|
||||
const formatResponseTime = (time: number) => {
|
||||
if (time < 0) return '-'
|
||||
return `${time}ms`
|
||||
}
|
||||
|
||||
const getStatusIcon = (status?: ProviderStatus) => {
|
||||
if (!status) return '⏳'
|
||||
return status.isOnline ? '✅' : '❌'
|
||||
}
|
||||
|
||||
const getStatusText = (status?: ProviderStatus, isChecking?: boolean) => {
|
||||
if (isChecking) return '检查中...'
|
||||
if (!status) return '未检查'
|
||||
if (status.isOnline) return '正常'
|
||||
return status.error || '连接失败'
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="provider-list">
|
||||
{Object.values(providers).length === 0 ? (
|
||||
@@ -50,8 +27,6 @@ const ProviderList: React.FC<ProviderListProps> = ({
|
||||
) : (
|
||||
<div className="provider-items">
|
||||
{Object.values(providers).map((provider) => {
|
||||
const status = statuses[provider.id]
|
||||
const isChecking = checkingStatus[provider.id]
|
||||
const isCurrent = provider.id === currentProviderId
|
||||
|
||||
return (
|
||||
@@ -66,7 +41,6 @@ const ProviderList: React.FC<ProviderListProps> = ({
|
||||
name="provider"
|
||||
checked={isCurrent}
|
||||
onChange={() => onSwitch(provider.id)}
|
||||
disabled={!status?.isOnline}
|
||||
/>
|
||||
<span>{provider.name}</span>
|
||||
{isCurrent && <span className="current-badge">当前使用</span>}
|
||||
@@ -74,24 +48,7 @@ const ProviderList: React.FC<ProviderListProps> = ({
|
||||
<div className="provider-url">{provider.apiUrl}</div>
|
||||
</div>
|
||||
|
||||
<div className="provider-status">
|
||||
<span className="status-icon">{isChecking ? '🔄' : getStatusIcon(status)}</span>
|
||||
<span className="status-text">{getStatusText(status, isChecking)}</span>
|
||||
{status?.isOnline && !isChecking && (
|
||||
<span className="response-time">
|
||||
{formatResponseTime(status.responseTime)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="provider-actions">
|
||||
<button
|
||||
className="check-btn"
|
||||
onClick={() => onCheckStatus(provider.id)}
|
||||
disabled={true}
|
||||
>
|
||||
{isChecking ? '检查中' : '检查状态'}
|
||||
</button>
|
||||
<button
|
||||
className="enable-btn"
|
||||
onClick={() => onSwitch(provider.id)}
|
||||
|
||||
@@ -6,13 +6,6 @@ export interface Provider {
|
||||
model?: string
|
||||
}
|
||||
|
||||
export interface ProviderStatus {
|
||||
isOnline: boolean
|
||||
responseTime: number
|
||||
lastChecked: Date
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface AppConfig {
|
||||
providers: Record<string, Provider>
|
||||
current: string
|
||||
@@ -26,7 +19,6 @@ declare global {
|
||||
addProvider: (provider: Provider) => Promise<boolean>
|
||||
deleteProvider: (id: string) => Promise<boolean>
|
||||
updateProvider: (provider: Provider) => Promise<boolean>
|
||||
checkStatus: (provider: Provider) => Promise<ProviderStatus>
|
||||
switchProvider: (providerId: string) => Promise<boolean>
|
||||
getClaudeCodeConfigPath: () => Promise<string>
|
||||
selectConfigFile: () => Promise<string | null>
|
||||
|
||||
Reference in New Issue
Block a user