mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-09-23 09:50:58 +02:00
fix: properly warmup nodecar
This commit is contained in:
+13
-6
@@ -119,14 +119,21 @@ impl<R: Runtime> WindowExt for WebviewWindow<R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn warm_up_nodecar() -> Result<(), String> {
|
async fn warm_up_nodecar(app: tauri::AppHandle) -> Result<(), String> {
|
||||||
use tokio::process::Command;
|
use tauri_plugin_shell::ShellExt;
|
||||||
use tokio::time::{timeout, Duration};
|
use tokio::time::{timeout, Duration};
|
||||||
|
|
||||||
let start_time = std::time::Instant::now();
|
let start_time = std::time::Instant::now();
|
||||||
|
|
||||||
let warmup_future = Command::new("nodecar").output();
|
// Use sidecar to execute a fast, harmless command that ensures the binary is loaded
|
||||||
match timeout(Duration::from_secs(15), warmup_future).await {
|
let cmd = app
|
||||||
|
.shell()
|
||||||
|
.sidecar("nodecar")
|
||||||
|
.map_err(|e| format!("Failed to create nodecar sidecar: {e}"))?
|
||||||
|
.arg("help")
|
||||||
|
|
||||||
|
let exec_future = async { cmd.output().await };
|
||||||
|
match timeout(Duration::from_secs(30), exec_future).await {
|
||||||
Ok(Ok(_output)) => {
|
Ok(Ok(_output)) => {
|
||||||
let duration = start_time.elapsed();
|
let duration = start_time.elapsed();
|
||||||
println!(
|
println!(
|
||||||
@@ -135,8 +142,8 @@ async fn warm_up_nodecar() -> Result<(), String> {
|
|||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Ok(Err(e)) => Err(format!("Failed to start nodecar warm-up: {e}")),
|
Ok(Err(e)) => Err(format!("Failed to execute nodecar for warm-up: {e}")),
|
||||||
Err(_) => Err("Nodecar warm-up timed out after 15s".to_string()),
|
Err(_) => Err("Nodecar warm-up timed out after 30s".to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user