feat: complete notification cycle for automatic UI refresh

This commit is contained in:
Thomas
2026-05-09 21:38:22 +02:00
parent 45c0ff9992
commit a4fc0f23a6
4 changed files with 290 additions and 107 deletions
@@ -113,12 +113,27 @@ public class DefaultDownloadManager implements IDownloadManager {
} finally {
if (finishedCalled.compareAndSet(false, true)) {
notifyComfyUI(); // NEU: Ping abfeuern
onFinished.run();
}
}
}).start();
}
// NEU: Benachrichtigt ComfyUI
private void notifyComfyUI() {
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://127.0.0.1:8188/kippster/model-downloaded"))
.POST(HttpRequest.BodyPublishers.noBody())
.build();
// Fire and forget
httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding());
} catch (Exception e) {
// Wenn ComfyUI nicht läuft, ignorieren wir das leise
}
}
private boolean isSelected(int index) {
return currentSelection == null || (index < currentSelection.length && currentSelection[index]);
}
@@ -4,14 +4,13 @@ from aiohttp import web
print("\033[95m[Model-Downloader] UI Extension Bridge active\033[0m")
# NEU: Der API-Endpunkt für den Java-Ping
@server.PromptServer.instance.routes.post("/kippster/model-downloaded")
async def model_downloaded(request):
try:
# Broadcast event to all connected clients
server.PromptServer.instance.send_sync("kippster-refresh-ui", {"message": "New models available!"})
return web.json_response({"status": "success", "message": "UI refresh triggered"})
except Exception as e:
return web.json_response({"status": "error", "message": str(e)}, status=500)
print("[Model-Downloader] Download finished trigger received from Java!")
# Sendet das Signal ans Frontend
server.PromptServer.instance.send_sync("kippster-refresh-ui", {"message": "New models available!"})
return web.json_response({"status": "success", "message": "UI refresh triggered"})
WEB_DIRECTORY = "web"
NODE_CLASS_MAPPINGS = {}
@@ -310,6 +310,33 @@ const initializeExtension = async () => {
addFAB(); addClassic(); addV2Action();
};
// NEU: Wir laden die API
const setupListener = async () => {
try {
const { api } = await import("../../scripts/api.js");
api.addEventListener("kippster-refresh-ui", (event) => {
console.log("%c[Model-Downloader] Triggering UI Refresh!", "background: green; color: white;");
if (app && app.refresh) {
app.refresh(); // Magischer Reload-Befehl
// Kleines Popup für den User
const notify = (msg) => {
if (app.ui?.dialog?.show) app.ui.dialog.show(msg);
else if (window.comfyAPI?.dialog?.show) window.comfyAPI.dialog.show(msg);
else alert(msg);
};
notify("✅ Downloads abgeschlossen! Modelle sind jetzt in ComfyUI verfügbar.");
}
});
console.log("[Model-Downloader] WebSocket Listener aktiv.");
} catch (e) {
console.error("[Model-Downloader] Konnte API nicht für Listener laden.", e);
}
};
setupListener();
if (app) {
app.registerExtension({ name: "TKI.ModelDownloader", async setup() { await initializeExtension(); } });
} else if (document.readyState === "complete") {