diff --git a/web-plugin/index.js b/web-plugin/index.js index 95f325b..f335250 100644 --- a/web-plugin/index.js +++ b/web-plugin/index.js @@ -19,11 +19,8 @@ function dispatchAPIEventData(data) { // Custom parse error if (msg.error) { let message = msg.error.message; - if (msg.error.details) - message += ": " + msg.error.details; - for (const [nodeID, nodeError] of Object.entries( - msg.node_errors, - )) { + if (msg.error.details) message += ": " + msg.error.details; + for (const [nodeID, nodeError] of Object.entries(msg.node_errors)) { message += "\n" + nodeError.class_type + ":"; for (const errorReason of nodeError.errors) { message += @@ -261,26 +258,49 @@ const ext = { // const graphCanvas = document.getElementById("graph-canvas"); window.addEventListener("message", async (event) => { + // console.log("message", event); try { const message = JSON.parse(event.data); if (message.type === "graph_load") { const comfyUIWorkflow = message.data; - console.log("recieved: ", comfyUIWorkflow); + // console.log("recieved: ", comfyUIWorkflow); // Assuming there's a method to load the workflow data into the ComfyUI // This part of the code would depend on how the ComfyUI expects to receive and process the workflow data // For demonstration, let's assume there's a loadWorkflow method in the ComfyUI API if (comfyUIWorkflow && app && app.loadGraphData) { + console.log("loadGraphData"); app.loadGraphData(comfyUIWorkflow); } } else if (message.type === "deploy") { // deployWorkflow(); const prompt = await app.graphToPrompt(); + // api.handlePromptGenerated(prompt); sendEventToCD("cd_plugin_onDeployChanges", prompt); } else if (message.type === "queue_prompt") { const prompt = await app.graphToPrompt(); + api.handlePromptGenerated(prompt); sendEventToCD("cd_plugin_onQueuePrompt", prompt); + } else if (message.type === "get_prompt") { + const prompt = await app.graphToPrompt(); + sendEventToCD("cd_plugin_onGetPrompt", prompt); } else if (message.type === "event") { dispatchAPIEventData(message.data); + } else if (message.type === "add_node") { + console.log("add node", message.data); + app.graph.beforeChange(); + var node = LiteGraph.createNode(message.data.type); + node.configure({ + widgets_values: message.data.widgets_values, + }); + + console.log("node", node); + + const graphMouse = app.canvas.graph_mouse; + + node.pos = [graphMouse[0], graphMouse[1]]; + + app.graph.add(node); + app.graph.afterChange(); } // else if (message.type === "refresh") { // sendEventToCD("cd_plugin_onRefresh"); @@ -288,10 +308,6 @@ const ext = { } catch (error) { // console.error("Error processing message:", error); } - - // if (!event.data.flow || Object.entries(event.data.flow).length <= 0) - // return; - // updateBlendshapesPrompts(event.data.flow); }); api.addEventListener("executed", (evt) => { @@ -348,10 +364,10 @@ function createDynamicUIHtml(data) {

Missing Nodes

These nodes are not found with any matching custom_nodes in the ComfyUI Manager Database

${data.missing_nodes - .map((node) => { - return `

${node}

`; - }) - .join("")} + .map((node) => { + return `

${node}

`; + }) + .join("")} `; } @@ -359,17 +375,14 @@ function createDynamicUIHtml(data) { Object.values(data.custom_nodes).forEach((node) => { html += `
- ${ - node.name - } + ${node.name + }

${node.hash}

- ${ - node.warning - ? `

${node.warning}

` - : "" - } + ${node.warning + ? `

${node.warning}

` + : "" + }
`; }); @@ -383,9 +396,8 @@ function createDynamicUIHtml(data) { Object.entries(data.models).forEach(([section, items]) => { html += `
-

${ - section.charAt(0).toUpperCase() + section.slice(1) - }

`; +

${section.charAt(0).toUpperCase() + section.slice(1) + }

`; items.forEach((item) => { html += `

${item.name}

`; }); @@ -401,9 +413,8 @@ function createDynamicUIHtml(data) { Object.entries(data.files).forEach(([section, items]) => { html += `
-

${ - section.charAt(0).toUpperCase() + section.slice(1) - }

`; +

${section.charAt(0).toUpperCase() + section.slice(1) + }

`; items.forEach((item) => { html += `

${item.name}

`; }); @@ -826,14 +837,12 @@ export class LoadingDialog extends ComfyDialog { showLoading(title, message) { this.show(`
-

${title} ${ - this.loadingIcon - }

- ${ - message - ? `` - : "" - } +

${title} ${this.loadingIcon + }

+ ${message + ? `` + : "" + }
`); } @@ -1099,21 +1108,17 @@ export class ConfigDialog extends ComfyDialog {
- API Key: User / Org - + API Key: User / Org +