Jason
ba336fc416
feat(settings): add auto-launch on system startup feature
...
Implement auto-launch functionality with proper state synchronization
and error handling across Windows, macOS, and Linux platforms.
Key changes:
- Add auto_launch module using auto-launch crate 0.5
- Define typed errors (AutoLaunchPathError, AutoLaunchEnableError, etc.)
- Sync system state with settings.json on app startup
- Only call system API when auto-launch state actually changes
- Add UI toggle in Window Settings panel
- Add i18n support for auto-launch settings (en/zh)
Implementation details:
- Settings file (settings.json) is the single source of truth
- On startup, system state is synced to match settings.json
- Error handling uses Rust type system with proper error propagation
- Frontend optimized to avoid unnecessary system API calls
Platform support:
- Windows: HKEY_CURRENT_USER registry modification
- macOS: AppleScript-based launch item (configurable to Launch Agent)
- Linux: XDG autostart desktop file
2025-11-21 23:23:35 +08:00
Jason
7fa0a7b166
feat(skills): enhance error messages with i18n support
...
- Add structured error format with error codes and context
- Create skillErrorParser to format errors for user-friendly display
- Add comprehensive i18n keys for all skill-related errors (zh/en)
- Extend download timeout from 15s to 60s to reduce false positives
- Fix: Pass correct error title based on operation context (load/install/uninstall)
Error improvements:
- SKILL_NOT_FOUND: Show skill directory name
- DOWNLOAD_TIMEOUT: Display repo info and timeout duration with network suggestion
- DOWNLOAD_FAILED: Show HTTP status code with specific suggestions (403/404/429)
- SKILL_DIR_NOT_FOUND: Show full path with URL check suggestion
- EMPTY_ARCHIVE: Suggest checking repository URL
Users will now see detailed error messages instead of generic "Error".
2025-11-21 16:20:01 +08:00
Jason
b498f0fe91
refactor(i18n): complete error message internationalization and code cleanup
...
Replaced all remaining hardcoded error types with AppError::localized for
full bilingual support and simplified error handling logic.
Backend changes:
- usage_script.rs: Converted InvalidHttpMethod to localized error
- provider.rs: Replaced all 7 ProviderNotFound instances with localized errors
* Line 436: Delete provider validation
* Line 625: Update provider metadata
* Line 785: Test usage script provider lookup
* Line 855: Query usage provider lookup
* Line 924: Prepare Codex provider switch
* Line 1011: Prepare Claude provider switch
* Line 1272: Delete provider snapshot
- provider.rs: Simplified error message formatting (removed 40+ lines)
* Removed redundant string matching fallback logic
* Now uses clean language-based selection for Localized errors
* Falls back to default Display for other error types
- error.rs: Removed unused error variants
* Deleted InvalidHttpMethod (replaced with localized)
* Deleted ProviderNotFound (replaced with localized)
Code quality improvements:
- Reduced complexity: 40+ lines of string matching removed
- Better maintainability: Centralized error message handling
- Type safety: All provider errors now use consistent localized format
Impact:
- 100% i18n coverage for provider and usage script error messages
- Cleaner, more maintainable error handling code
- No unused error variants remaining
2025-11-05 10:11:47 +08:00
Jason
85334d8dce
refine(usage): enhance query robustness and error handling
...
Backend improvements:
- Add InvalidHttpMethod error enum for better error semantics
- Clamp HTTP timeout to 2-30s to prevent config abuse
- Strict HTTP method validation instead of silent fallback to GET
Frontend improvements:
- Add i18n support for usage query errors (en/zh)
- Improve error handling with type-safe unknown instead of any
- Optimize i18n import (direct import instead of dynamic)
- Disable auto-retry for usage queries to avoid API stampede
Additional changes:
- Apply prettier formatting to affected files
Files changed:
- src-tauri/src/error.rs (+2)
- src-tauri/src/usage_script.rs (+8 -2)
- src/i18n/locales/{en,zh}.json (+4 -1 each)
- src/lib/api/usage.ts (+21 -4)
- src/lib/query/queries.ts (+1)
- style: prettier formatting on 6 other files
2025-11-03 10:24:59 +08:00
Jason
5c3aca18eb
refactor(backend): implement transaction mechanism and i18n errors for provider service
...
This commit completes phase 4 service layer extraction by introducing:
1. **Transaction mechanism with 2PC (Two-Phase Commit)**:
- Introduced `run_transaction()` wrapper with snapshot-based rollback
- Implemented `LiveSnapshot` enum to capture and restore live config files
- Added `PostCommitAction` to separate config.json persistence from live file writes
- Applied to critical operations: add, update, switch providers
- Ensures atomicity: memory + config.json + live files stay consistent
2. **Internationalized error handling**:
- Added `AppError::Localized` variant with key + zh + en messages
- Implemented `AppError::localized()` helper function
- Migrated 24 error sites to use i18n-ready errors
- Enables frontend to display errors in user's preferred language
3. **Concurrency optimization**:
- Fixed `get_custom_endpoints()` to use read lock instead of write lock
- Ensured async IO operations (usage query) execute outside lock scope
- Added defensive RAII lock management with explicit scope blocks
4. **Code organization improvements**:
- Reduced commands/provider.rs from ~800 to ~320 lines (-60%)
- Expanded services/provider.rs with transaction infrastructure
- Added unit tests for validation and credential extraction
- Documented legacy file cleanup logic with inline comments
5. **Backfill mechanism refinement**:
- Ensured live config is synced back to memory before switching
- Maintains SSOT (Single Source of Truth) architecture principle
- Handles Codex dual-file (auth.json + config.toml) atomically
Breaking changes: None (internal refactoring only)
Performance: Improved read concurrency, no measurable overhead from snapshots
Test coverage: Added validation tests, updated service layer tests
2025-10-28 17:47:15 +08:00
Jason
c01e495eea
refactor(backend): phase 1 - unified error handling with thiserror
...
Introduce AppError enum to replace Result<T, String> pattern across
the codebase, improving error context preservation and type safety.
## Changes
### Core Infrastructure
- Add src/error.rs with AppError enum using thiserror
- Add thiserror dependency to Cargo.toml
- Implement helper functions: io(), json(), toml() for ergonomic error creation
- Implement From<PoisonError> for automatic lock error conversion
- Implement From<AppError> for String to maintain Tauri command compatibility
### Module Migrations (60% complete)
- config.rs: Full migration to AppError
- read_json_file, write_json_file, atomic_write
- archive_file, copy_file, delete_file
- claude_mcp.rs: Full migration to AppError
- get_mcp_status, read_mcp_json, upsert_mcp_server
- delete_mcp_server, validate_command_in_path
- set_mcp_servers_map
- codex_config.rs: Full migration to AppError
- write_codex_live_atomic with rollback support
- read_and_validate_codex_config_text
- validate_config_toml
- app_config.rs: Partial migration
- MultiAppConfig::load, MultiAppConfig::save
- store.rs: Partial migration
- AppState::save now returns Result<(), AppError>
- commands.rs: Minimal changes
- Use .map_err(Into::into) for compatibility
- mcp.rs: Minimal changes
- sync_enabled_to_claude uses Into::into conversion
### Documentation
- Add docs/BACKEND_REFACTOR_PLAN.md with detailed refactoring roadmap
## Benefits
- Type-safe error handling with preserved error chains
- Better error messages with file paths and context
- Reduced boilerplate code (118 Result<T, String> instances to migrate)
- Automatic error conversion for seamless integration
## Testing
- All existing tests pass (4/4)
- Compilation successful with no warnings
- Build time: 0.61s (no performance regression)
## Remaining Work
- claude_plugin.rs (7 functions)
- migration.rs, import_export.rs
- Add unit tests for error.rs
- Complete commands.rs migration after dependent modules
Co-authored-by: Claude <claude@anthropic.com >
2025-10-27 16:29:11 +08:00