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.

feat(onboarding): in-app LM Studio install + auto-server-start

purple13a4fb062965
diff --git a/src-tauri/src/commands/install.rs b/src-tauri/src/commands/install.rs
index a86cfc97..2d813e4f 100644
--- a/src-tauri/src/commands/install.rs
+++ b/src-tauri/src/commands/install.rs
@@ -576,6 +576,254 @@ pub fn install_ollama_status(state: State<'_, AppState>) -> Result<serde_json::V
}))
}
+// ── LM Studio Install (Windows) ─────────────────────────────────────────────
+//
+// LM Studio doesn't run as a Windows service like Ollama — it's a desktop app
+// whose embedded server is started via either the GUI ("Server" tab) or the
+// `lms` CLI (`lms server start`). The install flow here:
+// 1. Download the official LM Studio installer .exe
+// 2. Silent install with /S (NSIS / electron-builder convention)
+// 3. Run `lms bootstrap` to register the CLI on PATH
+// 4. Start the server on port 1234 via `lms server start --cors`
+//
+// Step 4 is what makes this Plug & Play — without it the user has to manually
+// open the app and toggle the server, which is exactly the "version one
+// usability cliff" we're trying to remove. If lms isn't on PATH yet (e.g.
+// install is too fresh), we look in `%USERPROFILE%/.lmstudio/bin/lms.exe`
+// directly.
+//
+// The hard-coded URL points to a known-stable release. LM Studio's installer
+// host doesn't expose a /latest redirect — every version is its own URL — so
+// the alternative would be to bake in a remote-version-check, which adds an
+// extra failure mode for offline users. A stale URL just means the user gets
+// a slightly older LM Studio; functionally fine.
+const LMSTUDIO_INSTALLER_URL: &str =
+ "https://installers.lmstudio.ai/win32/x64/0.3.16-6/LM-Studio-0.3.16-6-x64.exe";
+const LMSTUDIO_DEFAULT_PORT: u16 = 1234;
+
+fn lmstudio_lms_path() -> Option<PathBuf> {
+ // Post-install convention: `lms bootstrap` puts a launcher on PATH, but
+ // before bootstrap the .exe lives here. Try both.
+ let direct = dirs::home_dir().map(|h| h.join(".lmstudio").join("bin").join("lms.exe"));
+ if let Some(ref p) = direct {
+ if p.exists() {
+ return direct;
+ }
+ }
+
+ // After bootstrap: `where lms` returns it. We resolve via PATH.
+ if let Ok(out) = Command::new("where").arg("lms").output() {
+ if out.status.success() {
+ let s = String::from_utf8_lossy(&out.stdout);
+ if let Some(line) = s.lines().next() {
+ let p = PathBuf::from(line.trim());
+ if p.exists() {
+ return Some(p);
+ }
+ }
+ }
+ }
+
+ None
+}
+
+fn lmstudio_server_running() -> bool {
+ let client = reqwest::blocking::Client::builder()
+ .timeout(std::time::Duration::from_millis(800))
+ .build();
+ if let Ok(c) = client {
+ return c
+ .get(format!("http://localhost:{}/v1/models", LMSTUDIO_DEFAULT_PORT))
+ .send()
+ .map(|r| r.status().is_success() || r.status() == 401)
+ .unwrap_or(false);
+ }
+ false
+}
+
+#[tauri::command]
+pub fn install_lmstudio(state: State<'_, AppState>) -> Result<serde_json::Value, String> {
+ let mut install = state.lmstudio_install.lock().unwrap();
+ if install.status == "downloading"
+ || install.status == "installing"
+ || install.status == "starting"
+ {
+ return Ok(serde_json::json!({"status": "already_installing"}));
+ }
+
+ install.status = "downloading".to_string();
+ install.logs.clear();
+ install.download_progress = 0;
+ install.download_total = 0;
+ install.download_speed = 0.0;
+ install
+ .logs
+ .push("Downloading LM Studio installer...".to_string());
+ drop(install);
+
+ let lms_state = state.lmstudio_install.clone();
+
+ std::thread::spawn(move || {
+ let update = |status: &str, msg: &str| {
+ if let Ok(mut s) = lms_state.lock() {
+ s.status = status.to_string();
+ s.logs.push(msg.to_string());
+ }
+ };
+
+ let temp_dir = std::env::temp_dir();
+ let installer_path = temp_dir.join("LMStudioSetup.exe");
+
+ println!("[LMStudio] Downloading {}", LMSTUDIO_INSTALLER_URL);
+ if let Err(e) =
+ download_file_blocking(LMSTUDIO_INSTALLER_URL, &installer_path, &lms_state)
+ {
+ let err = format!(
+ "Download failed: {}. If the network is fine, the installer URL may have rotated — fall back to https://lmstudio.ai/download in your browser.",
+ e
+ );
+ println!("[LMStudio] {}", err);
+ update("error", &err);
+ return;
+ }
+
+ update(
+ "installing",
+ "Download complete. Running silent installer (this can take a minute)...",
+ );
+
+ // electron-builder NSIS supports /S for silent install. Ignore exit
+ // code: real failures surface via the absence of lms.exe afterwards.
+ let mut cmd = Command::new(&installer_path);
+ cmd.arg("/S");
+ #[cfg(target_os = "windows")]
+ cmd.creation_flags(CREATE_NO_WINDOW);
+ match cmd.output() {
+ Ok(_) => println!("[LMStudio] Installer finished"),
+ Err(e) => {
+ let err = format!("Could not run installer: {}", e);
+ println!("[LMStudio] {}", err);
+ update("error", &err);
+ return;
+ }
+ }
+
+ let _ = fs::remove_file(&installer_path);
+
+ // Bootstrap the lms CLI. First boot of the LM Studio app sometimes
+ // does this for us, but it requires the GUI to launch — which we don't
+ // want during an unattended install. Calling `lms bootstrap` on the
+ // raw .exe handles it without touching the GUI.
+ update("starting", "Bootstrapping `lms` CLI...");
+ let lms = lmstudio_lms_path();
+ match &lms {
+ Some(p) => {
+ let mut bs = Command::new(p);
+ bs.arg("bootstrap");
+ #[cfg(target_os = "windows")]
+ bs.creation_flags(CREATE_NO_WINDOW);
+ let _ = bs.output();
+ }
+ None => {
+ update(
+ "error",
+ "LM Studio installed but `lms.exe` not found. Open LM Studio once from the Start menu, then return here and click Re-Scan.",
+ );
+ return;
+ }
+ }
+
+ // Start the embedded server. `lms server start` is non-blocking — it
+ // detaches a background httpd. --cors so LU's web view (which is on a
+ // tauri:// origin) isn't blocked by the SOP. Port matches the
+ // provider-store default of 1234 so user config Just Works.
+ update("starting", "Starting LM Studio server on port 1234...");
+ if let Some(p) = lms {
+ let mut srv = Command::new(&p);
+ srv.args(["server", "start", "--cors", "--port"])
+ .arg(LMSTUDIO_DEFAULT_PORT.to_string())
+ .stdout(Stdio::null())
+ .stderr(Stdio::null());
+ #[cfg(target_os = "windows")]
+ srv.creation_flags(CREATE_NO_WINDOW);
+ let _ = srv.spawn();
+ }
+
+ // Wait for the server to respond. LM Studio's server typically takes
+ // ~3-5 s to bind in a fresh install (it loads its model index first).
+ update("starting", "Waiting for LM Studio server...");
+ let mut ready = false;
+ for i in 0..15 {
+ std::thread::sleep(std::time::Duration::from_secs(2));
+ if lmstudio_server_running() {
+ ready = true;
+ break;
+ }
+ println!("[LMStudio] Server not ready, attempt {}/15", i + 1);
+ }
+
+ if ready {
+ update("complete", "LM Studio server is up on localhost:1234.");
+ } else {
+ update(
+ "error",
+ "LM Studio installed but the server didn't come up. Open LM Studio from the Start menu and toggle the Server tab on, then click Re-Scan.",
+ );
+ }
+ });
+
+ Ok(serde_json::json!({"status": "downloading"}))
+}
+
+#[tauri::command]
+pub fn install_lmstudio_status(state: State<'_, AppState>) -> Result<serde_json::Value, String> {
+ let install = state.lmstudio_install.lock().unwrap();
+ Ok(serde_json::json!({
+ "status": install.status,
+ "logs": install.logs,
+ "download_progress": install.download_progress,
+ "download_total": install.download_total,
+ "download_speed": install.download_speed,
+ }))
+}
+
+/// Best-effort: spawn `lms server start` so we don't make the user open the
+/// LM Studio GUI just to flip the Server toggle. Idempotent — quick early-exit
+/// if the server is already responding.
+#[tauri::command]
+pub fn start_lmstudio_server() -> Result<serde_json::Value, String> {
+ if lmstudio_server_running() {
+ return Ok(serde_json::json!({"status": "already_running"}));
+ }
+ match lmstudio_lms_path() {
+ Some(p) => {
+ let mut srv = Command::new(&p);
+ srv.args(["server", "start", "--cors", "--port"])
+ .arg(LMSTUDIO_DEFAULT_PORT.to_string())
+ .stdout(Stdio::null())
+ .stderr(Stdio::null());
+ #[cfg(target_os = "windows")]
+ srv.creation_flags(CREATE_NO_WINDOW);
+ srv.spawn()
+ .map_err(|e| format!("spawn lms: {}", e))?;
+ Ok(serde_json::json!({"status": "starting"}))
+ }
+ None => Err(
+ "LM Studio is not installed (no lms.exe found). Use Settings → Install LM Studio first."
+ .to_string(),
+ ),
+ }
+}
+
+#[tauri::command]
+pub fn lmstudio_server_status() -> Result<serde_json::Value, String> {
+ Ok(serde_json::json!({
+ "running": lmstudio_server_running(),
+ "port": LMSTUDIO_DEFAULT_PORT,
+ "lms_present": lmstudio_lms_path().is_some(),
+ }))
+}
+
// ──────────────────────────────────────────────────────────────────────────────
#[allow(non_snake_case)]
diff --git a/src-tauri/src/commands/process.rs b/src-tauri/src/commands/process.rs
index 17208d31..33c17964 100644
--- a/src-tauri/src/commands/process.rs
+++ b/src-tauri/src/commands/process.rs
@@ -269,10 +269,33 @@ pub fn start_comfyui(state: State<'_, AppState>) -> Result<serde_json::Value, St
*path = Some(comfy_path.clone());
}
- // Validate python binary exists
- let python = &state.python_bin;
+ // Prefer the portable's bundled Python over the system one. ComfyUI
+ // Portable (NVIDIA, AMD, CPU variants) ships its own Python with the
+ // matching torch wheel pre-installed — using the system Python instead
+ // wastes that and on AMD it actively fails because system Python lacks
+ // the DirectML / ROCm bindings the portable installer prepared. Layout:
+ // <ComfyUI>/python_embeded/python.exe ← what we want
+ // <ComfyUI>/main.py
+ // Fixed Discord report from reload__: AMD Portable launchte nicht.
+ let portable_python = std::path::Path::new(&comfy_path)
+ .parent()
+ .and_then(|p| {
+ let candidate = p.join("python_embeded").join("python.exe");
+ if candidate.exists() { Some(candidate.to_string_lossy().to_string()) } else { None }
+ });
+ let bundled_python = portable_python.or_else(|| {
+ // Some portable variants nest python_embeded inside the ComfyUI dir
+ // itself rather than alongside it.
+ let candidate = std::path::Path::new(&comfy_path).join("python_embeded").join("python.exe");
+ if candidate.exists() { Some(candidate.to_string_lossy().to_string()) } else { None }
+ });
+ let python = bundled_python.as_deref().unwrap_or(&state.python_bin);
let port_str = port.to_string();
- println!("[ComfyUI] Using Python: {}", python);
+ if bundled_python.is_some() {
+ println!("[ComfyUI] Using bundled portable Python: {}", python);
+ } else {
+ println!("[ComfyUI] Using system Python: {}", python);
+ }
println!("[ComfyUI] Starting from: {} on port {}", comfy_path, port);
let mut cmd = Command::new(python);
@@ -660,7 +683,25 @@ pub fn auto_start_comfyui(state: &AppState) {
println!("[ComfyUI] Auto-starting from: {} on port {}", path, port);
*state.comfy_path.lock().unwrap() = Some(path.clone());
- let mut cmd = Command::new(&state.python_bin);
+ // Mirror the start_comfyui Python preference: use the portable's
+ // bundled Python when present so AMD / cu126 / CPU portables boot
+ // with the right torch wheel. See start_comfyui for full context.
+ let portable_python = std::path::Path::new(&path)
+ .parent()
+ .and_then(|p| {
+ let c = p.join("python_embeded").join("python.exe");
+ if c.exists() { Some(c.to_string_lossy().to_string()) } else { None }
+ })
+ .or_else(|| {
+ let c = std::path::Path::new(&path).join("python_embeded").join("python.exe");
+ if c.exists() { Some(c.to_string_lossy().to_string()) } else { None }
+ });
+ let python = portable_python.as_deref().unwrap_or(state.python_bin.as_str());
+ if portable_python.is_some() {
+ println!("[ComfyUI] Auto-start using bundled portable Python: {}", python);
+ }
+
+ let mut cmd = Command::new(python);
cmd.args(["main.py", "--listen", "127.0.0.1", "--port", &port_str, "--enable-cors-header", "*"])
.current_dir(&path)
.env("TQDM_DISABLE", "1")
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index aa3adcbb..d3d14ffb 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -45,6 +45,10 @@ fn main() {
commands::install::install_comfyui_status,
commands::install::install_ollama,
commands::install::install_ollama_status,
+ commands::install::install_lmstudio,
+ commands::install::install_lmstudio_status,
+ commands::install::start_lmstudio_server,
+ commands::install::lmstudio_server_status,
commands::install::install_custom_node,
// Whisper STT
commands::whisper::whisper_status,
diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs
index 599aba59..82397895 100644
--- a/src-tauri/src/state.rs
+++ b/src-tauri/src/state.rs
@@ -138,6 +138,7 @@ pub struct AppState {
pub pull_tokens: Arc<Mutex<HashMap<String, CancellationToken>>>,
pub install_status: Arc<Mutex<InstallState>>,
pub ollama_install: Arc<Mutex<InstallState>>,
+ pub lmstudio_install: Arc<Mutex<InstallState>>,
pub searxng_install: Mutex<InstallState>,
pub searxng_available: AtomicBool,
pub python_bin: String,
@@ -191,6 +192,7 @@ impl AppState {
pull_tokens: Arc::new(Mutex::new(HashMap::new())),
install_status: Arc::new(Mutex::new(InstallState::default())),
ollama_install: Arc::new(Mutex::new(InstallState::default())),
+ lmstudio_install: Arc::new(Mutex::new(InstallState::default())),
searxng_install: Mutex::new(InstallState::default()),
searxng_available: AtomicBool::new(false),
python_bin,