Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(rust): the polled status commands froze the window on every tick

David91b414f7393e
diff --git a/src-tauri/src/commands/claude_code.rs b/src-tauri/src/commands/claude_code.rs
index 16cd90a5..a0d9e7d0 100644
--- a/src-tauri/src/commands/claude_code.rs
+++ b/src-tauri/src/commands/claude_code.rs
@@ -4,7 +4,7 @@ use std::process::{Command, Stdio};
#[cfg(target_os = "windows")]
use std::os::windows::process::CommandExt;
-use tauri::{AppHandle, Emitter, State};
+use tauri::{AppHandle, Emitter, Manager, State};
use crate::state::AppState;
@@ -373,8 +373,20 @@ pub fn start_claude_code(
// ── Stop Claude Code ──────────────────────────────────────────────────────
+// ASYNC + spawn_blocking: a SYNCHRONOUS Tauri command runs on the MAIN thread.
+// The State borrow cannot cross into the blocking pool, so the handle is
+// re-resolved there from the AppHandle (same pattern as engine.rs/whisper.rs).
#[tauri::command]
-pub fn stop_claude_code(state: State<'_, AppState>) -> Result<serde_json::Value, String> {
+pub async fn stop_claude_code(app: tauri::AppHandle) -> Result<serde_json::Value, String> {
+ tokio::task::spawn_blocking(move || {
+ let state = app.state::<AppState>();
+ stop_claude_code_blocking(&state)
+ })
+ .await
+ .map_err(|e| format!("stop_claude_code task: {e}"))?
+}
+
+fn stop_claude_code_blocking(state: &AppState) -> Result<serde_json::Value, String> {
let mut proc = state.claude_code_process.lock().unwrap();
if let Some(ref mut child) = *proc {
let pid = child.id();
diff --git a/src-tauri/src/commands/engine.rs b/src-tauri/src/commands/engine.rs
index 5f78b25e..23ac1508 100644
--- a/src-tauri/src/commands/engine.rs
+++ b/src-tauri/src/commands/engine.rs
@@ -431,10 +431,20 @@ pub async fn swap_bundled_model(
/// List `*.gguf` files in the built-in models dir, marking the one currently
/// loaded. Used by the frontend instead of `/v1/models` (which would only
/// report the single loaded model).
+// ASYNC + spawn_blocking: a SYNCHRONOUS Tauri command runs on the MAIN thread.
+// The State borrow cannot cross into the blocking pool, so the handle is
+// re-resolved there from the AppHandle (same pattern as engine.rs/whisper.rs).
#[tauri::command]
-pub fn list_bundled_models(
- state: State<'_, AppState>,
-) -> Result<serde_json::Value, String> {
+pub async fn list_bundled_models(app: tauri::AppHandle) -> Result<serde_json::Value, String> {
+ tokio::task::spawn_blocking(move || {
+ let state = app.state::<AppState>();
+ list_bundled_models_blocking(&state)
+ })
+ .await
+ .map_err(|e| format!("list_bundled_models task: {e}"))?
+}
+
+fn list_bundled_models_blocking(state: &AppState) -> Result<serde_json::Value, String> {
let dir = builtin_models_dir()?;
let loaded = state
.bundled_engine
diff --git a/src-tauri/src/commands/install.rs b/src-tauri/src/commands/install.rs
index 6ea4ca56..526666dd 100644
--- a/src-tauri/src/commands/install.rs
+++ b/src-tauri/src/commands/install.rs
@@ -62,8 +62,20 @@ fn check_install_disk_pressure(target_dir: &Path) -> Option<String> {
None
}
+// ASYNC + spawn_blocking: a SYNCHRONOUS Tauri command runs on the MAIN thread.
+// The State borrow cannot cross into the blocking pool, so the handle is
+// re-resolved there from the AppHandle (same pattern as engine.rs/whisper.rs).
#[tauri::command]
-pub fn cancel_comfyui_install(state: State<'_, AppState>) -> Result<serde_json::Value, String> {
+pub async fn cancel_comfyui_install(app: tauri::AppHandle) -> Result<serde_json::Value, String> {
+ tokio::task::spawn_blocking(move || {
+ let state = app.state::<AppState>();
+ cancel_comfyui_install_blocking(&state)
+ })
+ .await
+ .map_err(|e| format!("cancel_comfyui_install task: {e}"))?
+}
+
+fn cancel_comfyui_install_blocking(state: &AppState) -> Result<serde_json::Value, String> {
state.comfyui_install_cancel.store(true, Ordering::SeqCst);
if let Ok(mut s) = state.install_status.lock() {
// Mark as cancelling immediately so the UI can switch to a
@@ -1484,8 +1496,20 @@ fn install_ollama_macos_impl<F: Fn(&str, &str)>(
);
}
+// ASYNC + spawn_blocking: a SYNCHRONOUS Tauri command runs on the MAIN thread.
+// The State borrow cannot cross into the blocking pool, so the handle is
+// re-resolved there from the AppHandle (same pattern as engine.rs/whisper.rs).
#[tauri::command]
-pub fn install_ollama_status(state: State<'_, AppState>) -> Result<serde_json::Value, String> {
+pub async fn install_ollama_status(app: tauri::AppHandle) -> Result<serde_json::Value, String> {
+ tokio::task::spawn_blocking(move || {
+ let state = app.state::<AppState>();
+ install_ollama_status_blocking(&state)
+ })
+ .await
+ .map_err(|e| format!("install_ollama_status task: {e}"))?
+}
+
+fn install_ollama_status_blocking(state: &AppState) -> Result<serde_json::Value, String> {
let install = state.ollama_install.lock().unwrap();
Ok(serde_json::json!({
"status": install.status,
diff --git a/src-tauri/src/commands/trainer.rs b/src-tauri/src/commands/trainer.rs
index 434f393a..d303d7d7 100644
--- a/src-tauri/src/commands/trainer.rs
+++ b/src-tauri/src/commands/trainer.rs
@@ -683,8 +683,20 @@ pub fn character_training_status(state: State<'_, AppState>) -> Result<serde_jso
}))
}
+// ASYNC + spawn_blocking: a SYNCHRONOUS Tauri command runs on the MAIN thread.
+// The State borrow cannot cross into the blocking pool, so the handle is
+// re-resolved there from the AppHandle (same pattern as engine.rs/whisper.rs).
#[tauri::command]
-pub fn cancel_character_training(state: State<'_, AppState>) -> Result<(), String> {
+pub async fn cancel_character_training(app: tauri::AppHandle) -> Result<(), String> {
+ tokio::task::spawn_blocking(move || {
+ let state = app.state::<AppState>();
+ cancel_character_training_blocking(&state)
+ })
+ .await
+ .map_err(|e| format!("cancel_character_training task: {e}"))?
+}
+
+fn cancel_character_training_blocking(state: &AppState) -> Result<(), String> {
state.trainer_cancel.store(true, Ordering::SeqCst);
// Kill the live child directly too — pip/accelerate ignore the flag.
if let Ok(slot) = state.trainer_process.lock() {
diff --git a/src-tauri/src/commands/whisper.rs b/src-tauri/src/commands/whisper.rs
index 69dd3439..b83d8ffb 100644
--- a/src-tauri/src/commands/whisper.rs
+++ b/src-tauri/src/commands/whisper.rs
@@ -169,8 +169,20 @@ impl WhisperServer {
}
}
+// ASYNC + spawn_blocking: a SYNCHRONOUS Tauri command runs on the MAIN thread.
+// The State borrow cannot cross into the blocking pool, so the handle is
+// re-resolved there from the AppHandle (same pattern as engine.rs/whisper.rs).
#[tauri::command]
-pub fn whisper_status(state: State<'_, AppState>) -> Result<serde_json::Value, String> {
+pub async fn whisper_status(app: tauri::AppHandle) -> Result<serde_json::Value, String> {
+ tokio::task::spawn_blocking(move || {
+ let state = app.state::<AppState>();
+ whisper_status_blocking(&state)
+ })
+ .await
+ .map_err(|e| format!("whisper_status task: {e}"))?
+}
+
+fn whisper_status_blocking(state: &AppState) -> Result<serde_json::Value, String> {
let (running, ready, backend) = {
let whisper = state.whisper.lock().unwrap();
(whisper.process.is_some(), whisper.ready, whisper.backend.clone())
@@ -181,7 +193,7 @@ pub fn whisper_status(state: State<'_, AppState>) -> Result<serde_json::Value, S
// relaunch — the "reinstall every launch" report (#78, ElBiggus). If the
// server is up it's obviously installed; otherwise probe the resolved
// interpreter for the faster_whisper package.
- let available = running || whisper_package_installed(state.inner());
+ let available = running || whisper_package_installed(state);
Ok(serde_json::json!({
"available": available,
"backend": backend,