Skip to content

Commit 4d435a4

Browse files
committed
better stdout, model and sampler options
1 parent f4a9d4e commit 4d435a4

File tree

5 files changed

+76
-63
lines changed

5 files changed

+76
-63
lines changed

packages/stablestudio-ui/src-tauri/src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

44
use std::collections::HashMap;
5+
use std::fmt::format;
56
use std::fs::File;
67
use std::sync::OnceLock;
78
use tauri::api::process::CommandEvent;
@@ -97,7 +98,7 @@ fn emit_event(event: &str, data: Option<String>) {
9798
.unwrap_or_else(|_| println!("[!!] event failed"));
9899
}
99100
None => {
100-
println!("[!!] window locked");
101+
println!("[!!] window not set");
101102
}
102103
}
103104
}
@@ -109,20 +110,21 @@ async fn watch_comfy(
109110
// check if output starts with "To see the GUI go to:"
110111
match i {
111112
Stdout(line) if line.len() > 1 => {
113+
println!("[ComfyUI] stdout: {}", line);
114+
emit_event("comfy-output", Some(format!("stdout:{line}")));
115+
112116
if line.starts_with("To see the GUI go to:") {
113117
println!("Comfy launched successfully!");
114118
return (rx, Ok("completed".to_string()));
115119
}
116-
println!("[ComfyUI] stdout: {}", line);
117-
emit_event("comfy-stdout", Some(line));
118120
}
119121
Stderr(line) => {
120122
println!("[ComfyUI] stderr: {}", line);
121-
emit_event("comfy-stderr", Some(line));
123+
emit_event("comfy-output", Some(format!("stderr:{line}")));
122124
}
123125
Error(line) => {
124126
println!("[ComfyUI] error: {}", line);
125-
emit_event("comfy-error", Some(line));
127+
emit_event("comfy-output", Some(format!("error:{line}")));
126128
}
127129
Terminated(_) => {
128130
println!("Comfy terminated!");

packages/stablestudio-ui/src/App/index.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { listen } from "@tauri-apps/api/event";
12
import {
23
BaseDirectory,
34
exists,
@@ -8,6 +9,7 @@ import {
89
import { appDataDir } from "@tauri-apps/api/path";
910
import { invoke } from "@tauri-apps/api/tauri";
1011
import { download } from "tauri-plugin-upload";
12+
import { shallow } from "zustand/shallow";
1113
import { Comfy } from "~/Comfy";
1214
import { Router } from "~/Router";
1315
import { Shortcut } from "~/Shortcut";
@@ -105,6 +107,10 @@ export namespace App {
105107
const [isSetup, setIsSetup] = useState<SetupState>(SetupState.NotStarted);
106108
const [message, setMessage] = useState<string>("");
107109
const [progress, setProgress] = useState<number | null>(null);
110+
const [setRunning, setUnlisteners, print] = Comfy.use(
111+
(state) => [state.setRunning, state.setUnlisteners, state.print],
112+
shallow
113+
);
108114
const nonce = useRef<number>(0);
109115

110116
const check = useCallback(async () => {
@@ -196,6 +202,14 @@ export namespace App {
196202
setMessage("Starting ComfyUI...");
197203
setProgress(null);
198204

205+
// add listener
206+
const unlisten = await listen("comfy-output", (event) => {
207+
const [t, ...d] = `${event.payload}`.split(":");
208+
console.log("[COMFYUI]", t, d);
209+
print(t, d.join(":"));
210+
});
211+
setUnlisteners([unlisten]);
212+
199213
// start comfy
200214
const result = await invoke("launch_comfy", {
201215
path: `${appDataPath}/comfyui`,
@@ -206,8 +220,9 @@ export namespace App {
206220
throw new Error("Failed to launch ComfyUI");
207221
}
208222

223+
setRunning(true);
209224
setIsSetup(SetupState.ComfyRunning);
210-
}, [isSetup]);
225+
}, [isSetup, print, setRunning, setUnlisteners]);
211226

212227
useEffect(() => {
213228
check();

packages/stablestudio-ui/src/Comfy/index.tsx

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { listen } from "@tauri-apps/api/event";
21
import { useLocation } from "react-router-dom";
32
import { create } from "zustand";
43

@@ -60,37 +59,6 @@ export type Graph = {
6059

6160
export function Comfy() {
6261
const location = useLocation();
63-
const { print } = Comfy.use();
64-
65-
useEffect(() => {
66-
let mounted = true;
67-
const unlisteners = [] as (() => void)[];
68-
(async () => {
69-
if (mounted) {
70-
unlisteners.push(
71-
await listen("comfy-stdout", (event) => {
72-
console.log("stdout", `${event.payload}`);
73-
print("stdout", `${event.payload}`);
74-
})
75-
);
76-
unlisteners.push(
77-
await listen("comfy-stderr", (event) => {
78-
console.log("stderr", `${event.payload}`);
79-
print("stderr", `${event.payload}`);
80-
})
81-
);
82-
83-
mounted = false;
84-
}
85-
})();
86-
87-
return () => {
88-
mounted = false;
89-
90-
for (const unlistener of unlisteners) unlistener();
91-
};
92-
// eslint-disable-next-line react-hooks/exhaustive-deps
93-
}, []);
9462

9563
return (
9664
<iframe
@@ -105,15 +73,21 @@ export function Comfy() {
10573
);
10674
}
10775

108-
const MAX_STDOUT_LENGTH = 35;
76+
const MAX_STDOUT_LENGTH = 500;
10977

11078
type State = {
11179
output: {
112-
type: "stdout" | "stderr";
80+
type: string;
11381
data: string;
11482
}[];
11583
max_lines: number;
116-
print: (type: "stdout" | "stderr", data: string) => void;
84+
print: (type: string, data: string) => void;
85+
86+
running: boolean;
87+
setRunning: (running: boolean) => void;
88+
89+
unlisteners: (() => void)[];
90+
setUnlisteners: (unlisteners: (() => void)[]) => void;
11791
};
11892

11993
export namespace Comfy {
@@ -134,5 +108,11 @@ export namespace Comfy {
134108
if (output.length > MAX_STDOUT_LENGTH) output.shift();
135109
return { output };
136110
}),
111+
112+
running: false,
113+
setRunning: (running) => set({ running }),
114+
115+
unlisteners: [],
116+
setUnlisteners: (unlisteners) => set({ unlisteners }),
137117
}));
138118
}

packages/stablestudio-ui/src/Comfy/plugin.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,32 @@ export const createPlugin = StableStudio.createPlugin<any>(({ set, get }) => ({
5353
};
5454
},
5555

56+
getStableDiffusionModels: async () => {
57+
const resp = await fetch("/object_info", { cache: "no-cache" });
58+
const jsonResp = await resp.json();
59+
60+
console.log(jsonResp);
61+
62+
return jsonResp?.CheckpointLoader?.input?.required?.ckpt_name?.[0]?.map(
63+
(fileName: string) => ({
64+
id: fileName,
65+
name: fileName,
66+
})
67+
);
68+
},
69+
70+
getStableDiffusionSamplers: async () => {
71+
const resp = await fetch("/object_info", { cache: "no-cache" });
72+
const jsonResp = await resp.json();
73+
74+
return jsonResp?.KSampler?.input?.required?.scheduler?.[0]?.map(
75+
(name: string) => ({
76+
id: name,
77+
name,
78+
})
79+
);
80+
},
81+
5682
getStatus: () => {
5783
fetch("/comfyui", { cache: "no-cache" }).then((resp) => {
5884
set({

packages/stablestudio-ui/src/Settings/Manifest.tsx

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ import {
66
import { shallow } from "zustand/shallow";
77
import { Comfy } from "~/Comfy";
88

9-
import { Plugin } from "~/Plugin";
109
import { Theme } from "~/Theme";
1110

1211
import { Panel } from "./Panel";
1312
import { Setting } from "./Setting";
1413

1514
export function Manifest({
16-
id,
1715
manifest,
1816
pluginStatus,
1917
settings,
@@ -87,9 +85,18 @@ export function Manifest({
8785
</div>
8886
{output.length > 0 && (
8987
<>
90-
<div className="whitespace-pre-wrap rounded bg-black/25 p-2 font-mono text-sm">
91-
{output.map((line, index) => (
92-
<p key={`${index}-${line}`}>{line.data}</p>
88+
<div className="flex max-h-[25rem] flex-col-reverse overflow-y-auto whitespace-pre-wrap rounded bg-black/25 p-2 font-mono text-sm">
89+
{[...output].reverse().map((line, index) => (
90+
<p
91+
key={`${index}-${line}`}
92+
className={classes(
93+
"text-white",
94+
line.type === "stdout" && "text-green-200",
95+
line.type === "stderr" && "text-red-200"
96+
)}
97+
>
98+
{line.data}
99+
</p>
93100
))}
94101
</div>
95102
</>
@@ -112,20 +119,3 @@ export function Manifest({
112119
</Panel>
113120
);
114121
}
115-
116-
function MiniManifestField({
117-
label,
118-
value,
119-
className,
120-
}: {
121-
label: string;
122-
value: string | undefined;
123-
className?: string;
124-
}) {
125-
return (
126-
<p className={classes("opacity-muted text-sm", className)}>
127-
<span className="select-none opacity-50">{label} </span>
128-
{value}
129-
</p>
130-
);
131-
}

0 commit comments

Comments
 (0)