Skip to content

Commit 654b8c1

Browse files
author
ryanontheinstide
committedFeb 21, 2025
move to menu system
1 parent 811ccb4 commit 654b8c1

File tree

2 files changed

+90
-74
lines changed

2 files changed

+90
-74
lines changed
 

‎nodes/launcher/launcher_node.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pathlib
77
import logging
88
import aiohttp
9-
from ..server_manager import ComfyStreamServer
9+
from ..server_manager import LocalComfyStreamServer
1010

1111
routes = None
1212
server_manager = None
@@ -22,7 +22,7 @@
2222
routes.static('/extensions/comfystream_inside/static', str(STATIC_DIR))
2323

2424
# Create server manager instance
25-
server_manager = ComfyStreamServer()
25+
server_manager = LocalComfyStreamServer()
2626

2727
@routes.post('/api/offer')
2828
async def proxy_offer(request):

‎nodes/web/js/launcher.js

+88-72
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
// Wait for ComfyUI to be ready
12
const app = window.comfyAPI?.app?.app;
2-
console.log("[ComfyStream] Launcher extension loading, app:", app);
3-
4-
if (!app) {
5-
console.error("[ComfyStream] Failed to get app instance!");
6-
}
3+
console.log("[ComfyStream] Initializing with app:", app);
74

85
async function controlServer(action) {
6+
console.log("[ComfyStream] Controlling server with action:", action);
97
try {
108
const response = await fetch('/comfystream/control', {
119
method: 'POST',
@@ -18,6 +16,7 @@ async function controlServer(action) {
1816

1917
if (!response.ok) {
2018
const errorText = await response.text();
19+
console.error("[ComfyStream] Server returned error response:", response.status, errorText);
2120
try {
2221
const errorData = JSON.parse(errorText);
2322
throw new Error(errorData.error || `Server error: ${response.status}`);
@@ -36,77 +35,94 @@ async function controlServer(action) {
3635
}
3736
}
3837

39-
// Register our custom widget
40-
app.registerExtension({
41-
name: "ComfyStream.LauncherButton",
42-
async beforeRegisterNodeDef(nodeType, nodeData) {
43-
// Only handle our launcher node
44-
if (nodeData.name !== "ComfyStreamLauncher") return;
38+
async function openUI() {
39+
console.log("[ComfyStream] Attempting to open UI");
40+
try {
41+
const response = await fetch('/launch_comfystream', {
42+
method: 'POST',
43+
headers: {
44+
'Content-Type': 'application/json',
45+
'Accept': 'application/json'
46+
},
47+
body: JSON.stringify({})
48+
});
4549

46-
console.log("[ComfyStream] Processing ComfyStreamLauncher node");
47-
48-
// Add launch method to handle server communication
49-
nodeType.prototype.launchComfyStream = async function() {
50-
console.log("[ComfyStream] launchComfyStream called");
50+
if (!response.ok) {
51+
const errorText = await response.text();
52+
console.error("[ComfyStream] UI launch returned error response:", response.status, errorText);
5153
try {
52-
const response = await fetch('/launch_comfystream', {
53-
method: 'POST',
54-
headers: {
55-
'Content-Type': 'application/json',
56-
'Accept': 'application/json'
57-
},
58-
body: JSON.stringify({
59-
node_id: this.id
60-
})
61-
});
62-
63-
if (!response.ok) {
64-
const errorText = await response.text();
65-
try {
66-
const errorData = JSON.parse(errorText);
67-
throw new Error(errorData.error || `Server error: ${response.status}`);
68-
} catch (e) {
69-
throw new Error(`Server error: ${response.status} - ${errorText}`);
70-
}
71-
}
72-
73-
const data = await response.json();
74-
console.log("[ComfyStream] Launch response:", data);
75-
if (!data.success) {
76-
throw new Error(data.error || 'Unknown error launching ComfyStream');
77-
}
78-
} catch (error) {
79-
console.error('[ComfyStream] Error launching ComfyStream:', error);
80-
app.ui.dialog.show('Error', error.message || 'Failed to launch ComfyStream');
54+
const errorData = JSON.parse(errorText);
55+
throw new Error(errorData.error || `Server error: ${response.status}`);
56+
} catch (e) {
57+
throw new Error(`Server error: ${response.status} - ${errorText}`);
8158
}
82-
};
59+
}
8360

84-
// Override the onNodeCreated method
85-
const onNodeCreated = nodeType.prototype.onNodeCreated;
86-
console.log("[ComfyStream] Original onNodeCreated:", onNodeCreated);
87-
88-
nodeType.prototype.onNodeCreated = function() {
89-
console.log("[ComfyStream] onNodeCreated called");
90-
// Call the original onNodeCreated if it exists
91-
if (onNodeCreated) {
92-
console.log("[ComfyStream] Calling original onNodeCreated");
93-
onNodeCreated.apply(this);
61+
const data = await response.json();
62+
console.log("[ComfyStream] Launch response:", data);
63+
if (!data.success) {
64+
throw new Error(data.error || 'Unknown error launching ComfyStream');
65+
}
66+
} catch (error) {
67+
console.error('[ComfyStream] Error launching ComfyStream:', error);
68+
app.ui.dialog.show('Error', error.message || 'Failed to launch ComfyStream');
69+
throw error;
70+
}
71+
}
72+
73+
// Register our extension
74+
const extension = {
75+
name: "ComfyStream.Menu",
76+
77+
// Define commands that will be used by menu items
78+
commands: [
79+
{
80+
id: "ComfyStream.OpenUI",
81+
icon: "pi pi-external-link",
82+
label: "Open ComfyStream UI",
83+
function: openUI
84+
},
85+
{
86+
id: "ComfyStream.StartServer",
87+
icon: "pi pi-play",
88+
label: "Start ComfyStream Server",
89+
function: async () => {
90+
await controlServer('start');
91+
}
92+
},
93+
{
94+
id: "ComfyStream.StopServer",
95+
icon: "pi pi-stop",
96+
label: "Stop ComfyStream Server",
97+
function: async () => {
98+
await controlServer('stop');
99+
}
100+
},
101+
{
102+
id: "ComfyStream.RestartServer",
103+
icon: "pi pi-refresh",
104+
label: "Restart ComfyStream Server",
105+
function: async () => {
106+
await controlServer('restart');
94107
}
108+
}
109+
],
95110

96-
// Add all four buttons
97-
const buttons = [
98-
["Open UI", () => this.launchComfyStream()],
99-
["Start Server", () => controlServer('start')],
100-
["Stop Server", () => controlServer('stop')],
101-
["Restart Server", () => controlServer('restart')]
102-
];
111+
// Define where these commands appear in the menu
112+
menuCommands: [
113+
{
114+
path: ["ComfyStream"],
115+
commands: [
116+
"ComfyStream.OpenUI",
117+
null, // Separator
118+
"ComfyStream.StartServer",
119+
"ComfyStream.StopServer",
120+
"ComfyStream.RestartServer"
121+
]
122+
}
123+
]
124+
};
103125

104-
// Add each button
105-
buttons.forEach(([name, callback]) => {
106-
const widget = this.addWidget("button", name, null, callback);
107-
widget.serialize = false;
108-
});
109-
console.log("[ComfyStream] Node setup complete");
110-
};
111-
}
112-
});
126+
console.log("[ComfyStream] Registering extension:", extension);
127+
app.registerExtension(extension);
128+
console.log("[ComfyStream] Extension registered");

0 commit comments

Comments
 (0)