From b69d7f797986e8d3e3e752944bbdebd2ac4ed4ce Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 18 Sep 2025 09:33:58 +0800 Subject: [PATCH] feat: add TOML validation for Codex config and improve code formatting - Add real-time TOML syntax validation for Codex config field - Validate config TOML when saving provider settings - Format code to improve readability with proper error handling blocks - Reorganize imports for better consistency This ensures Codex config is valid TOML before saving, preventing runtime errors. --- src-tauri/src/commands.rs | 3 +++ src-tauri/src/lib.rs | 12 ++++++++---- src-tauri/src/migration.rs | 3 +-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index dd4f0aa..8369f85 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -32,6 +32,9 @@ fn validate_provider_settings(app_type: &AppType, provider: &Provider) -> Result if !(config_value.is_string() || config_value.is_null()) { return Err("Codex config 字段必须是字符串".to_string()); } + if let Some(cfg_text) = config_value.as_str() { + codex_config::validate_config_toml(cfg_text)?; + } } } } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 9bda47c..2dd5dd6 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -7,13 +7,13 @@ mod provider; mod store; use store::AppState; +#[cfg(target_os = "macos")] +use tauri::RunEvent; use tauri::{ menu::{CheckMenuItem, Menu, MenuBuilder, MenuItem}, tray::{TrayIconBuilder, TrayIconEvent}, }; use tauri::{Emitter, Manager}; -#[cfg(target_os = "macos")] -use tauri::RunEvent; /// 创建动态托盘菜单 fn create_tray_menu( @@ -144,7 +144,9 @@ fn handle_tray_menu_event(app: &tauri::AppHandle, event_id: &str) { provider_id, ) .await - { log::error!("切换Claude供应商失败: {}", e); } + { + log::error!("切换Claude供应商失败: {}", e); + } }); } id if id.starts_with("codex_") => { @@ -161,7 +163,9 @@ fn handle_tray_menu_event(app: &tauri::AppHandle, event_id: &str) { provider_id, ) .await - { log::error!("切换Codex供应商失败: {}", e); } + { + log::error!("切换Codex供应商失败: {}", e); + } }); } _ => { diff --git a/src-tauri/src/migration.rs b/src-tauri/src/migration.rs index e43e4b7..0768af7 100644 --- a/src-tauri/src/migration.rs +++ b/src-tauri/src/migration.rs @@ -148,8 +148,7 @@ pub fn migrate_copies_into_config(config: &mut MultiAppConfig) -> Result