mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-02 10:21:16 +08:00
fix: resolve critical bugs in settings and import flow
Fixed two critical issues: 1. **Blocking Issue - restart_app return type error** - Fixed compilation error where restart_app() didn't return a value - Used async spawn with 100ms delay to allow response before restart - Prevents "unreachable code" compiler error 2. **High Priority - Import SQL doesn't refresh AppSettings cache** - Added reload_settings() function to refresh in-memory settings cache - Integrated into import flow to ensure imported settings take effect - Prevents imported settings being overwritten by stale memory cache - Affects: language, config directories, auto-launch, custom endpoints Changes: - src/commands/settings.rs: Async delayed restart with proper return value - src/settings.rs: New reload_settings() to sync memory cache from DB - src/commands/import_export.rs: Call reload_settings() after SQL import Verified: cargo clippy --lib and pnpm typecheck both pass
This commit is contained in:
@@ -48,6 +48,11 @@ pub async fn import_config_from_file(
|
||||
log::warn!("导入后同步 live 配置失败: {err}");
|
||||
}
|
||||
|
||||
// 重新加载设置到内存缓存,确保导入的设置生效
|
||||
if let Err(err) = crate::settings::reload_settings() {
|
||||
log::warn!("导入后重载设置失败: {err}");
|
||||
}
|
||||
|
||||
Ok::<_, AppError>(json!({
|
||||
"success": true,
|
||||
"message": "SQL imported successfully",
|
||||
|
||||
@@ -18,7 +18,12 @@ pub async fn save_settings(settings: crate::settings::AppSettings) -> Result<boo
|
||||
/// 重启应用程序(当 app_config_dir 变更后使用)
|
||||
#[tauri::command]
|
||||
pub async fn restart_app(app: AppHandle) -> Result<bool, String> {
|
||||
app.restart();
|
||||
// 在后台延迟重启,让函数有时间返回响应
|
||||
tauri::async_runtime::spawn(async move {
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
|
||||
app.restart();
|
||||
});
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// 获取 app_config_dir 覆盖配置 (从 Store)
|
||||
|
||||
Reference in New Issue
Block a user