From fb847a52251540a7cbe66f6f575b89b4bd1bd064 Mon Sep 17 00:00:00 2001 From: Acly Date: Wed, 2 Oct 2024 17:56:19 +0200 Subject: [PATCH] Publish workflows only if there's a related sink node in the graph --- js/external_tooling_nodes.js | 48 +++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/js/external_tooling_nodes.js b/js/external_tooling_nodes.js index 288c78f..69516ee 100644 --- a/js/external_tooling_nodes.js +++ b/js/external_tooling_nodes.js @@ -1,20 +1,40 @@ import { app } from "/scripts/app.js"; import { api } from "/scripts/api.js"; +(function() { + +let publisherRegistered = false; + +async function publishWorkflow(e) { + const prompt = await app.graphToPrompt(); + await api.fetchApi("/api/etn/workflow/publish", { + method: "POST", + body: JSON.stringify({ + name: "ComfyUI Web", + client_id: api.clientId, + workflow: prompt["output"] + }, null, 2) + }); +} + app.registerExtension({ name: "external_tooling_nodes", - init() { - api.addEventListener('graphChanged', async (e) => { - const prompt = await app.graphToPrompt(); - console.log('graphChanged', prompt); - api.fetchApi("/api/etn/workflow/publish", { - method: "POST", - body: JSON.stringify({ - name: "ComfyUI Web", - client_id: api.clientId, - workflow: prompt["output"] - }, null, 2) - }); - }); - } + + nodeCreated(node /*: ComfyNode */, app /*: ComfyApp */) { + if (publisherRegistered || node.comfyClass !== "ETN_KritaOutput") { + return; + } + console.log("nodeCreated"); + api.addEventListener('graphChanged', publishWorkflow); + publisherRegistered = true; + }, + + setup(app) { + if (publisherRegistered) { + publishWorkflow(null); + } + }, + }); + +})(); \ No newline at end of file