fix(windows): eliminate console flash and UI freeze on provider switch

Switching providers or toggling proxy takeover on Windows flashed a
transient cmd window and froze the UI for up to a couple of seconds.
Three fixes:

- Spawn `codex debug models --bundled` with CREATE_NO_WINDOW so the
  console child of the GUI-subsystem app (npm's codex.cmd runs via
  cmd.exe) no longer opens a visible window.
- Cache the ProxyChat model catalog template in a process-wide OnceCell:
  only successful loads are cached, failures stay retryable, so the
  Codex CLI starts at most once per app run instead of on every switch.
- Run switch_provider via spawn_blocking: sync Tauri commands execute on
  the main thread, so the blocking catalog generation (and the
  block_on'd per-app switch lock) froze the UI. Concurrency is already
  serialized by ProxyService::lock_switch_for_app.
This commit is contained in:
Jason
2026-07-15 10:59:06 +08:00
parent 08710d51fc
commit 3bc828aecc
2 changed files with 124 additions and 10 deletions
+11 -4
View File
@@ -1,5 +1,5 @@
use indexmap::IndexMap;
use tauri::{Emitter, State};
use tauri::{Emitter, Manager, State};
use crate::app_config::AppType;
use crate::commands::copilot::CopilotAuthState;
@@ -100,13 +100,20 @@ pub fn switch_provider_test_hook(
}
#[tauri::command]
pub fn switch_provider(
state: State<'_, AppState>,
pub async fn switch_provider(
app_handle: tauri::AppHandle,
app: String,
id: String,
) -> Result<SwitchResult, String> {
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
switch_provider_internal(&state, app_type, &id).map_err(|e| e.to_string())
tauri::async_runtime::spawn_blocking(move || {
let state = app_handle
.try_state::<AppState>()
.ok_or_else(|| "应用状态不可用".to_string())?;
switch_provider_internal(state.inner(), app_type, &id).map_err(|e| e.to_string())
})
.await
.map_err(|e| format!("供应商切换任务执行失败: {e}"))?
}
fn import_default_config_internal(state: &AppState, app_type: AppType) -> Result<bool, AppError> {