Skip to content

Commit 607ab73

Browse files
add restart comfyui to comfystream menu
1 parent 50c9bb2 commit 607ab73

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

nodes/api/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import aiohttp
99
from ..server_manager import LocalComfyStreamServer
1010
from .. import settings_storage
11+
import subprocess
1112

1213
routes = None
1314
server_manager = None
@@ -215,3 +216,7 @@ async def manage_configuration(request):
215216
logging.error(f"Error managing configuration: {str(e)}")
216217
return web.json_response({"error": str(e)}, status=500)
217218

219+
@routes.post('/comfyui/restart')
220+
async def manage_configuration(request):
221+
subprocess.run(["supervisorctl", "restart", "comfyui"])
222+
return web.json_response({"success": True}, status=200)

nodes/web/js/launcher.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,38 @@ document.addEventListener('comfy-extension-registered', (event) => {
9898
}
9999
});
100100

101+
async function restartComfyUI() {
102+
try {
103+
const response = await fetch('/comfyui/restart', {
104+
method: 'POST',
105+
headers: {
106+
'Content-Type': 'application/json',
107+
'Accept': 'application/json'
108+
},
109+
body: "" // No body needed
110+
});
111+
112+
if (!response.ok) {
113+
const errorText = await response.text();
114+
console.error("[ComfyStream] ComfyUI restart returned error response:", response.status, errorText);
115+
try {
116+
const errorData = JSON.parse(errorText);
117+
throw new Error(errorData.error || `Server error: ${response.status}`);
118+
} catch (e) {
119+
throw new Error(`Server error: ${response.status} - ${errorText}`);
120+
}
121+
}
122+
123+
const data = await response.json();
124+
125+
return data;
126+
} catch (error) {
127+
console.error('[ComfyStream] Error restarting ComfyUI:', error);
128+
app.ui.dialog.show('Error', error.message || 'Failed to restart ComfyUI');
129+
throw error;
130+
}
131+
}
132+
101133
async function controlServer(action) {
102134
try {
103135
// Get settings from the settings manager
@@ -256,6 +288,12 @@ const extension = {
256288
icon: "pi pi-cog",
257289
label: "Server Settings",
258290
function: openSettings
291+
},
292+
{
293+
id: "ComfyStream.RestartComfyUI",
294+
icon: "pi pi-refresh",
295+
label: "Restart ComfyUI",
296+
function: restartComfyUI
259297
}
260298
],
261299

@@ -270,7 +308,9 @@ const extension = {
270308
"ComfyStream.StopServer",
271309
"ComfyStream.RestartServer",
272310
null, // Separator
273-
"ComfyStream.Settings"
311+
"ComfyStream.Settings",
312+
null, // Separator
313+
"ComfyStream.RestartComfyUI"
274314
]
275315
}
276316
],
@@ -300,6 +340,8 @@ const extension = {
300340
comfyStreamMenu.addItem("Restart Server", () => controlServer('restart'), { icon: "pi pi-refresh" });
301341
comfyStreamMenu.addSeparator();
302342
comfyStreamMenu.addItem("Server Settings", openSettings, { icon: "pi pi-cog" });
343+
comfyStreamMenu.addSeparator();
344+
comfyStreamMenu.addItem("Restart Server", () => restartComfyUI(), { icon: "pi pi-refresh" });
303345
}
304346
// New menu system is handled automatically by the menuCommands registration
305347

0 commit comments

Comments
 (0)