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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(create): remote ComfyUI host media, boot host sync + one-click CORS fix (#82)
purple4588d5fd9bc1
diff --git a/src-tauri/src/commands/process.rs b/src-tauri/src/commands/process.rsindex 33731ee1..7601285a 100644--- a/src-tauri/src/commands/process.rs+++ b/src-tauri/src/commands/process.rs@@ -701,6 +701,116 @@ fn is_comfyui_running_on_port(port: u16) -> bool {.unwrap_or(false)}+/// Kill whatever process listens on `port` (David 2026-07-17, "Let me do it+/// for you" CORS-fix button). Only ever called with the user-configured+/// ComfyUI port, on an explicit button press — LU is about to relaunch that+/// ComfyUI under its own management with the CORS flag. Best effort: a port+/// nobody listens on is a no-op.+fn kill_port_owner(port: u16) {+ let own_pid = std::process::id();+ #[cfg(target_os = "windows")]+ {+ let mut cmd = Command::new("netstat");+ cmd.args(["-ano", "-p", "tcp"]);+ cmd.creation_flags(CREATE_NO_WINDOW);+ let Ok(out) = cmd.output() else { return };+ let text = String::from_utf8_lossy(&out.stdout);+ let needle = format!(":{}", port);+ let mut pids: Vec<u32> = Vec::new();+ for line in text.lines() {+ // Match on the LOCAL address column only; the state column is+ // locale-dependent ("LISTENING" / "ABHÖREN"), so don't parse it.+ let cols: Vec<&str> = line.split_whitespace().collect();+ if cols.len() >= 5 && cols[0].eq_ignore_ascii_case("tcp") && cols[1].ends_with(&needle) {+ if let Ok(pid) = cols[cols.len() - 1].parse::<u32>() {+ if pid != 0 && pid != own_pid && !pids.contains(&pid) {+ pids.push(pid);+ }+ }+ }+ }+ for pid in pids {+ println!("[ComfyUI] CORS fix: killing port {} owner pid {}", port, pid);+ let mut kill = Command::new("taskkill");+ kill.args(["/pid", &pid.to_string(), "/T", "/F"]);+ kill.creation_flags(CREATE_NO_WINDOW);+ let _ = kill.output();+ }+ }+ #[cfg(not(target_os = "windows"))]+ {+ if let Ok(out) = Command::new("lsof").args(["-ti", &format!("tcp:{}", port), "-sTCP:LISTEN"]).output() {+ for line in String::from_utf8_lossy(&out.stdout).lines() {+ if let Ok(pid) = line.trim().parse::<u32>() {+ if pid != 0 && pid != own_pid {+ let _ = Command::new("kill").args(["-9", &pid.to_string()]).output();+ }+ }+ }+ }+ }+}++/// One-click fix for the ComfyUI 0.19+ cross-origin block banner (#75/#82+/// follow-up, David 2026-07-17): stop the user-managed ComfyUI on the+/// configured port and relaunch it under LU's management — LU-started+/// ComfyUI always carries `--enable-cors-header`, so direct media loads and+/// the native progress feed work again. Requires a known install path; on a+/// remote host LU can't manage the process at all.+#[tauri::command]+pub fn fix_comfyui_cors(state: State<'_, AppState>) -> Result<serde_json::Value, String> {+ let host = state.comfy_host.lock().unwrap().clone();+ if !is_local_host(&host) {+ return Err(+ "ComfyUI runs on a remote host, so LU can't restart it from here. Add --enable-cors-header http://tauri.localhost to the launch command on that machine instead.".to_string(),+ );+ }+ let path_known = state+ .comfy_path+ .lock()+ .unwrap()+ .clone()+ .or_else(find_comfyui_path)+ .is_some();+ if !path_known {+ return Err(+ "LU doesn't know this ComfyUI's folder yet. Set it under Settings → AI Backends → ComfyUI → Path, then press the button again. Or add --enable-cors-header http://tauri.localhost to your own launch script.".to_string(),+ );+ }+ let port = *state.comfy_port.lock().unwrap();++ // Stop our own child cleanly first (if any), then whatever else owns the port.+ {+ let mut proc = state.comfy_process.lock().unwrap();+ if let Some(ref mut child) = *proc {+ let pid = child.id();+ #[cfg(target_os = "windows")]+ {+ let mut cmd = Command::new("taskkill");+ cmd.args(["/pid", &pid.to_string(), "/T", "/F"]);+ cmd.creation_flags(CREATE_NO_WINDOW);+ let _ = cmd.output();+ }+ #[cfg(not(target_os = "windows"))]+ let _ = child.kill();+ info!(pid = pid, "cors fix: stopped LU-managed comfyui");+ *proc = None;+ }+ }+ kill_port_owner(port);++ // Wait for the port to actually free up — start_comfyui short-circuits+ // with "already_running" while the old process is still winding down.+ for _ in 0..20 {+ if !is_comfyui_running_on_port(port) {+ break;+ }+ std::thread::sleep(std::time::Duration::from_millis(400));+ }++ start_comfyui(state)+}+#[tauri::command]pub fn start_ollama(state: State<'_, AppState>) -> Result<serde_json::Value, String> {// Check if already runningdiff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex a0d4002a..d8c9b91e 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -98,6 +98,7 @@ fn main() {commands::process::start_ollama,commands::process::start_comfyui,commands::process::stop_comfyui,+ commands::process::fix_comfyui_cors,commands::process::comfyui_status,commands::process::find_comfyui,commands::process::detect_all_comfyui_installs,diff --git a/src/components/create/experimental/CreateExperimental.tsx b/src/components/create/experimental/CreateExperimental.tsxindex f3a9440c..3ae21e83 100644--- a/src/components/create/experimental/CreateExperimental.tsx+++ b/src/components/create/experimental/CreateExperimental.tsx@@ -31,6 +31,7 @@ function CreateExperimentalInner() {const backend = useCreateStore((s) => s.backend)const comfyCorsBlocked = useCreateStore((s) => s.comfyCorsBlocked)const setComfyCorsBlocked = useCreateStore((s) => s.setComfyCorsBlocked)+ const isGenerating = useCreateStore((s) => s.isGenerating)const { modelLoadError, connected, comfyOnCpu } = useCreateExp()const [shownId, setShownId] = useState<string | null>(null)@@ -39,6 +40,27 @@ function CreateExperimentalInner() {const [lightbox, setLightbox] = useState<GalleryItem | null>(null)const [panelOpen, setPanelOpen] = useState(false)+ // One-click CORS fix (David 2026-07-17): restart the user-managed ComfyUI+ // under LU's management so it carries --enable-cors-header. On success the+ // banner clears; if LU can't do it (unknown path / remote host) the backend+ // error explains the manual route and stays visible in the banner.+ const [corsFixing, setCorsFixing] = useState(false)+ const [corsFixError, setCorsFixError] = useState<string | null>(null)+ const fixCorsForMe = useCallback(async () => {+ setCorsFixing(true)+ setCorsFixError(null)+ try {+ const { backendCall } = await import('../../../api/backend')+ await backendCall('fix_comfyui_cors')+ // ComfyUI is relaunching with the flag — direct loads work from here on.+ useCreateStore.getState().setComfyCorsBlocked(false)+ } catch (err) {+ setCorsFixError(err instanceof Error ? err.message : String(err))+ } finally {+ setCorsFixing(false)+ }+ }, [])+// David 2026-07-11: the Stage starts EMPTY and never auto-surfaces a persisted// gallery item — not on mount, not on a mode/intent switch. It fills only on an// explicit pick (a gallery tile, or a result's "Edit" action) or a fresh@@ -133,18 +155,32 @@ function CreateExperimentalInner() {{/* Cross-origin block (#75, cinemazverev): a user-managed ComfyUI 0.19+answers the WebView's media/WS requests with a Sec-Fetch 403, so results- couldn't be viewed. LU now proxies the bytes so they still display, but- the live progress bar + native video seeking degrade — point the user at- the one-line launch fix. Local only, dismissible. */}+ couldn't be viewed. LU proxies the bytes so they still display, but the+ live progress bar + native video seeking degrade. David 2026-07-17: keep+ the message short and offer a one-click fix — LU restarts ComfyUI under+ its own management, which always passes the CORS flag. Local only,+ dismissible; the long manual-flag hint only appears if the fix fails. */}{backend === 'local' && comfyCorsBlocked && (<div className="flex items-start gap-2 px-4 py-2 bg-yellow-500/5 border-b border-yellow-500/10 text-yellow-300 text-xs shrink-0"><AlertTriangle size={12} className="shrink-0 mt-0.5" /><span className="flex-1 min-w-0">- Your ComfyUI blocks cross-origin apps (v0.19+), so LU is showing results through a fallback. To restore fast preview and the live progress bar, add{' '}- <code className="px-1 rounded bg-white/10">--enable-cors-header http://tauri.localhost</code>{' '}- to ComfyUI's launch (its run .bat / .sh), then restart ComfyUI.+ {corsFixError+ ? corsFixError+ : corsFixing+ ? 'Restarting ComfyUI with the fix… this takes a moment.'+ : 'Your ComfyUI blocks direct loads (v0.19+), so previews use a slower fallback.'}</span>- <button onClick={() => setComfyCorsBlocked(false)} className="shrink-0 text-yellow-300/70 hover:text-yellow-100" title="Dismiss">+ {!corsFixing && (+ <button+ onClick={() => { void fixCorsForMe() }}+ disabled={isGenerating}+ title={isGenerating ? 'Waiting for the current generation to finish' : 'LU restarts ComfyUI with the CORS flag for you'}+ className="shrink-0 px-2 py-0.5 rounded bg-yellow-500/15 hover:bg-yellow-500/25 text-yellow-200 transition-colors whitespace-nowrap disabled:opacity-40 disabled:cursor-not-allowed"+ >+ Let me do it for you!+ </button>+ )}+ <button onClick={() => { setComfyCorsBlocked(false); setCorsFixError(null) }} className="shrink-0 text-yellow-300/70 hover:text-yellow-100" title="Dismiss"><X size={14} /></button></div>diff --git a/src/components/create/experimental/useComfyMedia.ts b/src/components/create/experimental/useComfyMedia.tsindex 21fa8abe..fb41259a 100644--- a/src/components/create/experimental/useComfyMedia.ts+++ b/src/components/create/experimental/useComfyMedia.ts@@ -1,5 +1,6 @@import { useState, useEffect, useRef, useCallback } from 'react'import { galleryItemUrl, proxiedComfyBlobUrl, recoverGalleryUrl, markGalleryItemAvailable } from './galleryUrl'+import { isComfyLocal } from '../../../api/backend'import { useCreateStore, type GalleryItem } from '../../../stores/createStore'/**@@ -44,9 +45,13 @@ export function useComfyMedia(item: GalleryItem | null) {if (blob) {blobRef.current = blobsetSrc(blob)- // Proxy rescued a /view the direct load couldn't reach → it's a- // cross-origin block, not a down engine. Surface the actionable hint.- useCreateStore.getState().setComfyCorsBlocked(true)+ // Proxy rescued a /view the direct load couldn't reach. On a LOCAL+ // host that means ComfyUI 0.19+ rejected the cross-origin load and+ // the --enable-cors-header hint is actionable. On a REMOTE host+ // (#82, rx422) the block is LU's own CSP — expected, by design — and+ // the CORS hint would be wrong (the flag can't unblock a CSP'd+ // <img>), so the proxy path is simply the normal mode: no banner.+ if (isComfyLocal()) useCreateStore.getState().setComfyCorsBlocked(true)} else {recoverGalleryUrl(item)}diff --git a/src/components/layout/AppShell.tsx b/src/components/layout/AppShell.tsxindex 4e3e56da..e1fdf6fe 100644--- a/src/components/layout/AppShell.tsx+++ b/src/components/layout/AppShell.tsx@@ -63,6 +63,23 @@ export function AppShell() {const appMode = settings.appModeconst cloudAvailable = useCloudAuthStore(deriveCloudAvailable)+ // Boot-sync the configured ComfyUI host/port into the FE URL builder.+ // The backend loads them from config.json at startup, but the only FE+ // mirror lived in SettingsPage's mount effect — so after an app restart+ // every comfyuiUrl() (gallery media, control plane) pointed at localhost+ // until the user happened to open Settings. On a remote-host setup (#82)+ // that made the app look dead after every launch. Found live 2026-07-17.+ useEffect(() => {+ void (async () => {+ try {+ const { backendCall, setComfyPort, setComfyHost } = await import('../../api/backend')+ const s = await backendCall<{ port?: number; host?: string }>('comfyui_status')+ if (typeof s?.port === 'number' && s.port > 0) setComfyPort(s.port)+ if (typeof s?.host === 'string' && s.host.trim()) setComfyHost(s.host)+ } catch { /* backend not up yet — Settings' own mirror still applies later */ }+ })()+ }, [])+// Create renders where the mode says: the global switch owns the axis the// Composer's per-surface toggle used to.useEffect(() => {