Commit Graph

49 Commits

  • feat: Implement Speed Test Function
    * feat: add unified endpoint speed test for API providers
    
    Add a comprehensive endpoint latency testing system that allows users to:
    - Test multiple API endpoints concurrently
    - Auto-select the fastest endpoint based on latency
    - Add/remove custom endpoints dynamically
    - View latency results with color-coded indicators
    
    Backend (Rust):
    - Implement parallel HTTP HEAD requests with configurable timeout
    - Handle various error scenarios (timeout, connection failure, invalid URL)
    - Return structured latency data with status codes
    
    Frontend (React):
    - Create interactive speed test UI component with auto-sort by latency
    - Support endpoint management (add/remove custom endpoints)
    - Extract and update Codex base_url from TOML configuration
    - Integrate with provider presets for default endpoint candidates
    
    This feature improves user experience when selecting optimal API endpoints,
    especially useful for users with multiple provider options or proxy setups.
    
    * refactor: convert endpoint speed test to modal dialog
    
    - Transform EndpointSpeedTest component into a modal dialog
    - Add "Advanced" button next to base URL input to open modal
    - Support ESC key and backdrop click to close modal
    - Apply Linear design principles: minimal styling, clean layout
    - Remove unused showBaseUrlInput variable
    - Implement same modal pattern for both Claude and Codex
    
    * fix: prevent modal cascade closing when ESC is pressed
    
    - Add state checks to prevent parent modal from closing when child modals (endpoint speed test or template wizard) are open
    - Update ESC key handler dependencies to track all modal states
    - Ensures only the topmost modal responds to ESC key
    
    * refactor: unify speed test panel UI with project design system
    
    UI improvements:
    - Update modal border radius from rounded-lg to rounded-xl
    - Unify header padding from px-6 py-4 to p-6
    - Change speed test button color to blue theme (bg-blue-500) for consistency
    - Update footer background from bg-gray-50 to bg-gray-100
    - Style "Done" button as primary action button with blue theme
    - Adjust footer button spacing and hover states
    
    Simplify endpoint display:
    - Remove endpoint labels (e.g., "Current Address", "Custom 1")
    - Display only URL for cleaner interface
    - Clean up all label-related logic:
      * Remove label field from EndpointCandidate interface
      * Remove label generation in buildInitialEntries function
      * Remove label handling in useEffect merge logic
      * Remove label generation in handleAddEndpoint
      * Remove label parameters from claudeSpeedTestEndpoints
      * Remove label parameters from codexSpeedTestEndpoints
    
    * refactor: improve endpoint list UI consistency
    
    - Show delete button for all endpoints on hover for uniform UI
    - Change selected state to use blue theme matching main interface:
      * Blue border (border-blue-500) for selected items
      * Light blue background (bg-blue-50/dark:bg-blue-900/20)
      * Blue indicator dot (bg-blue-500/dark:bg-blue-400)
    - Switch from compact list (space-y-px) to card-based layout (space-y-2)
    - Add rounded corners to each endpoint item for better visual separation
    
    * feat: persist custom endpoints to settings.json
    
    - Extend AppSettings to store custom endpoints for Claude and Codex
    - Add Tauri commands: get/add/remove/update custom endpoints
    - Update frontend API with endpoint persistence methods
    - Modify EndpointSpeedTest to load/save custom endpoints via API
    - Track endpoint last used time for future sorting/cleanup
    - Store endpoints per app type in settings.json instead of localStorage
    
    * - feat(types): add Provider.meta and ProviderMeta (snake_case) with custom_endpoints map
    
    - feat(provider-form): persist custom endpoints on provider create by merging EndpointSpeedTest’s custom URLs into meta.custom_endpoints on submit
    
    - feat(endpoint-speed-test): add onCustomEndpointsChange callback emitting normalized custom URLs; wire it for both Claude/Codex modals
    
    - fix(api): send alias param names (app/appType/app_type and provider_id/providerId) in Tauri invokes to avoid “missing providerId” with older backends
    
    - storage: custom endpoints are stored in ~/.cc-switch/config.json under providers[<id>].meta.custom_endpoints (not in settings.json)
    
    - behavior: edit flow remains immediate writes; create flow now writes once via addProvider, removing the providerId dependency during creation
    
    * feat: add endpoint candidates support and code formatting improvements
    
    - Add endpointCandidates field to ProviderPreset and CodexProviderPreset interfaces
    - Integrate preset endpoint candidates into speed test endpoint selection
    - Add multiple endpoint options for PackyCode providers (Claude & Codex)
    - Apply consistent code formatting (trailing commas, line breaks)
    - Improve template value type safety and readability
    
    * refactor: improve endpoint management button UX
    
    Replace ambiguous "Advanced" text with intuitive "Manage & Test" label accompanied by Zap icon, making the endpoint management panel entry point more discoverable and self-explanatory for both Claude and Codex configurations.
    
    * - merge: merge origin/main, resolve conflicts and preserve both feature sets
    - feat(tauri): register import/export and file dialogs; keep endpoint speed test and custom endpoints
    - feat(api): add updateTrayMenu and onProviderSwitched; wire import/export APIs
    - feat(types): extend global API declarations (import/export)
    - chore(presets): GLM preset supports both new and legacy model keys
    - chore(rust): add chrono dependency; refresh lockfile
    
    ---------
    
    Co-authored-by: Jason <farion1231@gmail.com>
  • refactor: optimize React state updates and improve UI text clarity
    - Use functional setState to ensure proper state updates in ProviderForm
    - Improve Chinese UI text consistency in CodexConfigEditor:
      - Change "API 基础地址" to "API 请求地址" for clarity
      - Simplify "供应商官网" to "官网地址"
      - Update placeholder text for consistency
    - Move requires_openai_auth to model_providers section in Codex config template
  • feat: add dedicated API key URL support for third-party providers
    - Add optional apiKeyUrl field to ProviderPreset interface for third-party providers
    - Update ProviderForm to prioritize apiKeyUrl over websiteUrl for third-party category
    - Make provider display name required in CodexConfigEditor with validation
    - Configure PackyCode preset with affiliate API key URL
    
    This allows third-party providers to have separate URLs for their service homepage
    and API key acquisition, improving user experience when obtaining API keys.
  • feat: enhance Codex provider configuration wizard with display name field
    - Add separate display name field for provider (supports Chinese)
    - Keep provider code field for internal identifier (English only)
    - Add onNameChange callback to update provider name from wizard
    - Improve code formatting consistency in ProviderForm
  • feat: add configuration wizard for custom Codex providers
    - Add quick configuration wizard modal for custom providers
    - Generate auth.json and config.toml from simple inputs (API key, base URL, model name)
    - Extract generation logic into reusable functions (generateThirdPartyAuth, generateThirdPartyConfig)
    - Pre-populate custom template when selecting custom option
    - Add wizard button link in PresetSelector for custom mode
    - Update PackyCode preset to use the new generation functions
  • fix(codex): improve config snippet handling with consistent trimming
    - Trim config snippets during initialization from localStorage and defaults
    - Trim snippets before comparison in toggle and change handlers
    - Store trimmed values to localStorage for consistency
    - Prevents configuration matching issues caused by accidental whitespace
  • - fix(linux): disable modal backdrop blur on Linux (WebKitGTK/Wayland) to prevent freeze when opening Add Provider panel
    - refactor(ui): add runtime platform detector and conditionally apply blur only on non-Linux platforms
    - chore: verify typecheck and renderer build succeed; no functional regression expected
  • refactor: simplify TOML common config handling by removing markers
    - Remove COMMON_CONFIG_MARKER_START/END constants
    - Simplify config snippet addition/removal logic
    - Use natural append/replace approach instead of markers
    - Fix unused variable warning
    - Improve user experience with cleaner config output
  • fix: improve VS Code config synchronization and code formatting
    - Add automatic VS Code config sync when base_url changes in TOML
    - Improve error handling for VS Code configuration writes
    - Enhance state management with ref tracking to prevent duplicate API calls
    - Fix code formatting issues and improve readability across components
    - Optimize common configuration handling for both Claude and Codex providers
  • fix: improve JSON validation with unified validation function
    - Extract common validateJsonConfig function for reuse
    - Apply unified validation to both main config and common config snippets
    - Add real-time JSON validation to JsonEditor component using CodeMirror linter
    - Simplify error handling without over-engineering error position extraction
  • fix: prevent automatic quote correction in TOML input fields
    - Remove unnecessary normalizeSmartQuotes function and its usage
    - Add input attributes to prevent automatic text correction (inputMode, data-gramm, etc.)
    - Delete unused textNormalization.ts utility file
    - Keep user's original input without any quote transformation
  • feat: add common config support for Codex with TOML format
    - Added separate common config state and storage for Codex
    - Implemented TOML-based common config merging with markers
    - Created UI components for Codex common config editor
    - Added toggle and edit functionality similar to Claude config
    - Store Codex common config in localStorage separately
    - Support appending/removing common TOML snippets to config.toml
  • fix: resolve checkbox sync issue when editing common config snippet
    The checkbox state was becoming out of sync when users edited the common config
    snippet. Added a ref flag to track when updates are coming from common config
    changes to prevent the handleChange function from incorrectly resetting the
    checkbox state during these updates.
  • refactor: replace co-authored setting with flexible common config snippet feature
    - Replace single "disable co-authored" checkbox with universal "common config snippet" functionality
    - Add localStorage persistence for common config snippets
    - Implement deep merge/remove operations for complex JSON structures
    - Add modal editor for managing common config snippets
    - Optimize performance with custom deepClone function instead of JSON.parse/stringify
    - Fix deep remove logic to only delete matching values
    - Improve error handling and validation for JSON snippets
  • fix(ui): add dark mode support for provider modals
    - Add dark mode styles to ProviderForm modal (background, borders, text)
    - Update ApiKeyInput component with dark mode colors
    - Add dark mode detection to ClaudeConfigEditor for JSON editor
    - Apply dark mode styles to CodexConfigEditor textareas
    - Update PresetSelector buttons for dark mode
    - Ensure consistent amber color scheme for all hint boxes in dark mode
    
    This ensures proper visibility and readability of add/edit provider dialogs
    when dark mode is enabled.
  • feat(ui): enhance provider form with brand icons and colors
    - Add Save icon to submit buttons in provider forms
    - Replace generic Zap icon with brand-specific icons (ClaudeIcon, CodexIcon)
    - Update selected state colors: Claude uses brand color #D97757, Codex uses black
    - Maintain visual consistency with AppSwitcher component
  • feat: add API key links for third-party providers and simplify Kimi model labels
    - Add "Get API Key" link support for third-party providers (e.g., PackyCode)
    - Simplify Kimi model selector labels by removing technical field names
      - Changed "主模型 (ANTHROPIC_MODEL)" to "主模型"
      - Changed "快速模型 (ANTHROPIC_SMALL_FAST_MODEL)" to "快速模型"
    - Improve user experience with cleaner, more intuitive interface labels
  • style: improve "Get API Key" link styling
    - Change link color to light blue (text-blue-400)
    - Remove arrow symbol from link text
    - Apply to domestic official and aggregator provider API key links
  • feat: enhance provider configuration UX with custom URL support and API key links
    - Add custom base URL input for custom providers
      - New "Request URL" field appears only in custom mode
      - Automatically syncs with ANTHROPIC_BASE_URL in config
      - Includes helpful amber-styled hint about Claude API compatibility
    
    - Add "Get API Key" links for non-official providers
      - Shows for cn_official, aggregator, and third_party categories
      - Links point to provider's official website
      - Styled as subtle helper text (text-xs, gray-500)
      - Positioned closely under API key input for better visual grouping
    
    - Improve UI consistency and hints
      - Unify all hint boxes to use amber color scheme (amber-50/amber-200/amber-600)
      - Update model placeholders to latest versions (GLM-4.5, GLM-4.5-Air)
      - Simplify provider names (remove version numbers and redundant text)
    
    - Update provider presets
      - GLM models: glm-4-plus → GLM-4.5, glm-4-flash → GLM-4.5-Air
      - Qwen models: qwen-coder-turbo → qwen3-coder-plus
      - Cleaner naming: "Claude官方登录" → "Claude官方", "DeepSeek v3.1" → "DeepSeek"
    
    - Fix Kimi model selector behavior
      - Remove API key requirement for displaying selector
      - Avoid showing duplicate model input fields for Kimi preset
      - Improve hint message clarity
  • feat: improve custom provider configuration UX
    - Show API key input field for custom mode
    - Initialize default custom mode with JSON template on modal open
    - Change default API key from placeholder to empty string
    - Remove Save icon from submit button for cleaner UI
    - Ensure consistent behavior between default and manually selected custom mode
  • feat: require API key for non-official Claude providers
    - Add required asterisk to API key input label for non-official providers
    - Pre-fill API key placeholder when switching to custom mode
    - Ensure consistent validation across Claude and Codex providers
  • feat: simplify Claude provider configuration form
    - Add optional model input fields (ANTHROPIC_MODEL, ANTHROPIC_SMALL_FAST_MODEL)
    - Place model inputs in a single row for better space utilization
    - Move website URL field above API configuration section
    - Add JSON template for custom mode to guide users
    - Simplify field labels and remove redundant descriptions
    - Keep JSON editor for advanced configuration flexibility
  • feat(providers): add provider categorization system
    - Add ProviderCategory type with official, cn_official, aggregator, third_party, and custom categories
    - Update Provider interface and Rust struct to include optional category field
    - Enhance ProviderForm to automatically sync category when selecting presets
    - Improve PresetSelector to show category-based styling and hints
    - Add category classification to all provider presets
    - Support differentiated interactions (e.g., hide API key input for official providers)
    - Maintain backward compatibility with existing configurations
  • feat(updater): 优化更新体验与 UI
    - ui: UpdateBadge 使用 Tailwind 内置过渡,支持点击打开设置,保留图标动画
    
    - updater: 新增 UpdateContext 首启延迟检查,忽略版本键名命名空间化(含旧键迁移),并发保护
    
    - settings: 去除版本硬编码回退;检测到更新时复用 updateHandle 下载并安装,并新增常显“更新日志”入口
    
    - a11y: 更新徽标支持键盘触达(Enter/Space)
    
    - refactor: 移除未使用的 runUpdateFlow 导出
    
    - chore: 类型检查通过,整体行为与权限边界未改变
  • refactor(styles): migrate from CSS variables to Tailwind classes
    - Replace all CSS custom properties with Tailwind utility classes
    - Add tailwind.config.js with custom color palette matching Linear design
    - Reduce index.css from 89 to 37 lines (58% reduction)
    - Maintain consistent visual appearance with semantic color usage
    - Update all components to use Tailwind classes instead of CSS variables
  • feat: refactor ProviderForm component with new subcomponents (#13)
    * feat: refactor ProviderForm component with new subcomponents
    
    - Introduced PresetSelector, ApiKeyInput, ClaudeConfigEditor, and CodexConfigEditor for improved modularity and readability.
    - Simplified preset selection logic for both Claude and Codex configurations.
    - Enhanced API Key input handling with dedicated components for better user experience.
    - Removed redundant code and improved state management in the ProviderForm component.
    
    * feat: add Kimi model selection to ProviderForm component
    
    - Introduced KimiModelSelector for enhanced model configuration options.
    - Implemented state management for Kimi model selection, including initialization and updates based on preset selection.
    - Improved user experience by conditionally displaying the Kimi model selector based on the selected preset.
    - Refactored related logic to ensure proper handling of Kimi-specific settings in the ProviderForm.
    
    * feat: enhance API Key input and model selection in ProviderForm
    
    - Added toggle functionality to show/hide API Key in ApiKeyInput component for improved user experience.
    - Updated placeholder text in ProviderForm to provide clearer instructions based on the selected preset.
    - Enhanced KimiModelSelector to display a more informative message when API Key is not provided.
    - Refactored provider presets to remove hardcoded API Key values for better security practices.
    
    * fix(kimi): optimize debounce implementation in model selector
    
    - Fix initial state: use empty string instead of apiKey.trim()
    - Refactor fetchModels to fetchModelsWithKey with explicit key parameter
    - Ensure consistent behavior between auto-fetch and manual refresh
    - Eliminate mental overhead from optional parameter fallback logic
    
    * fix(api-key): remove custom masking logic, use native password input
    
    - Remove getDisplayValue function with custom star masking
    - Use native browser password input behavior for better UX consistency
    - Simplify component logic while maintaining show/hide toggle functionality
    
    * chore: format code with prettier
    
    - Apply consistent code formatting across all TypeScript files
    - Fix indentation and spacing according to project style guide
    
    ---------
    
    Co-authored-by: Jason <farion1231@gmail.com>
  • feat: 系统托盘 (#12)
    * feat: 系统托盘
    
    1. 添加系统托盘
    2. 托盘添加切换供应商功能
    3. 整理组件目录
    
    * feat: 优化系统托盘菜单结构
    
    - 扁平化Claude和Codex的菜单结构,直接将所有供应商添加到主菜单,简化用户交互。
    - 添加无供应商时的提示信息,提升用户体验。
    - 更新分隔符文本以增强可读性。
    
    * feat: integrate Tailwind CSS and Lucide icons
    
    - Added Tailwind CSS for styling and layout improvements.
    - Integrated Lucide icons for enhanced UI elements.
    - Updated project structure by removing unused CSS files and components.
    - Refactored configuration files to support new styling and component structure.
    - Introduced new components for managing providers with improved UI interactions.   
    
    * fix: 修复类型声明和分隔符实现问题
    
    - 修复 updateTrayMenu 返回类型不一致(Promise<void> -> Promise<boolean>)
    - 添加缺失的 UnlistenFn 类型导入
    - 使用 MenuBuilder.separator() 替代文本分隔符
    
    ---------
    
    Co-authored-by: farion1231 <farion1231@gmail.c
  • feat: JsonEditor for inputting JSON content (#4)
    * feat(editor): add JsonEditor component for JSON configuration editing
    
    * fix(provider): update API Key visibility logic in ProviderForm component
    
    * fix(editor): stabilize JsonEditor height and restore API Key logic
    
    - Revert API Key visibility to preset-based rule and injection to non-custom preset only.
    - Reduce JsonEditor min-height from rows*22px to rows*18px to lessen layout jitter when switching presets.
    - Keep fonts/size consistent with the previous textarea for visual parity.
    
    * - fix(form): remove websiteUrl auto-extraction from JSON to prevent incorrect overrides
    
    ---------
    
    Co-authored-by: Jason <farion1231@gmail.com>
  • feat(ui): improve provider configuration UX with custom option
    - Add explicit "Custom" button in preset selection
    - Set "Custom" as default selection when adding new provider
    - Update label from "One-click import" to "Choose configuration type"
    - Add contextual hints for different configuration modes:
      - Custom mode: "Manually configure provider, complete configuration required"
      - Official preset: "Official login, no API Key required"
      - Other presets: "Use preset configuration, only API Key required"
    - Remove redundant "(optional)" text from Codex config.toml hint
    - Improve clarity for users who were confused about adding custom providers
  • revert: restore app/appType param compatibility and revert segmented-thumb pointer-events change
    - Restore backend commands to accept app_type/app/appType with priority app_type
    - Frontend invoke() now passes both { app_type, app } again
    - Revert CSS change that set pointer-events: none on segmented-thumb
    - Keep minor fix: open_config_folder signature uses handle + respects both names
    
    Note: warnings for non_snake_case (appType) are expected for compatibility.
  • - feat(codex): 引入 Codex 应用与供应商切换(管理 auth.json/config.toml,支持备份与恢复)
    - feat(core): 多应用配置 v2(claude/codex)与 ProviderManager;支持 v1→v2 自动迁移
    - feat(ui): 新增 Codex 页签与双编辑器表单;统一 window.api 支持 app 参数
    - feat(tauri): 新增 get_config_status/open_config_folder/open_external 命令并适配 Codex
    - fix(codex): 主配置缺失时不执行默认导入(对齐 Claude 行为)
    - chore: 配置目录展示与重启提示等细节优化
  • feat: add prettier formatter and MIT license
    - Add prettier dev dependency for code formatting
    - Create MIT LICENSE file
    - Format TypeScript files with prettier
    - Update provider order in README (Qwen coder first)
    - Update add provider screenshot with new UI
  • feat: add official preset orange theme and disabled API input
    - Add Anthropic orange theme styling for official preset buttons
    - Auto-disable API Key input field when official preset is selected
    - Add isOfficial field for precise official preset identification
    - Enhance UX: official login requires no manual API Key input
  • chore: format code and fix bundle identifier for v3.0.0 release
    - Format all TypeScript/React code with Prettier
    - Format all Rust code with cargo fmt
    - Fix bundle identifier from .app to .desktop to avoid macOS conflicts
    - Prepare codebase for v3.0.0 Tauri release
  • fix: prevent modal header jumping when toggling API key field
    Reserve fixed height for API key input container and use visibility/opacity
    for show/hide instead of conditional rendering to maintain consistent modal
    height when selecting presets
  • - feat(form): Support API Key ⇄ JSON two-way binding in edit modal
    - feat(utils): Add helpers to read/write/detect API Key in config
    - refactor(form): Reuse unified linking logic for preset and edit flows
    - chore: Preserve website URL extraction and signature-disable behaviors
    - build: Verify renderer build locally
  • - fix(types): 统一导入到 src/types.ts,移除 shared/types 残留路径
    - chore(tsconfig): 将 include 扩展为 src/**/* 覆盖迁移后的源文件
    - feat(build): Vite 设置 root 为 src,并将 build.outDir 设为 ../dist 以匹配 Tauri frontendDist
    - refactor(api): 去除未使用的 plugin-shell import;统一 electronAPI 类型定义至 vite-env.d.ts
    - build: 验证 renderer 构建通过,产物输出至 dist/
  • refactor: 清理 Electron 遗留代码并优化项目结构
    - 删除 Electron 主进程代码 (src/main/)
    - 删除构建产物文件夹 (build/, dist/, release/)
    - 清理 package.json 中的 Electron 依赖和脚本
    - 删除 TypeScript 配置中的 Electron 相关文件
    - 优化前端代码结构至 Tauri 标准结构 (src/renderer → src/)
    - 删除移动端图标和不必要文件
    - 更新文档说明技术栈变更为 Tauri