feat(plugin): add dispatchAPIEventData
This commit is contained in:
parent
875f7f24d1
commit
5b8dac37fb
@ -13,6 +13,53 @@ function sendEventToCD(event, data) {
|
|||||||
window.parent.postMessage(JSON.stringify(message), "*");
|
window.parent.postMessage(JSON.stringify(message), "*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dispatchAPIEventData(data) {
|
||||||
|
const msg = JSON.parse(data);
|
||||||
|
switch (msg.type) {
|
||||||
|
case "status":
|
||||||
|
if (msg.data.sid) {
|
||||||
|
// this.clientId = msg.data.sid;
|
||||||
|
// window.name = this.clientId; // use window name so it isnt reused when duplicating tabs
|
||||||
|
// sessionStorage.setItem("clientId", this.clientId); // store in session storage so duplicate tab can load correct workflow
|
||||||
|
}
|
||||||
|
api.dispatchEvent(new CustomEvent("status", { detail: msg.data.status }));
|
||||||
|
break;
|
||||||
|
case "progress":
|
||||||
|
api.dispatchEvent(new CustomEvent("progress", { detail: msg.data }));
|
||||||
|
break;
|
||||||
|
case "executing":
|
||||||
|
api.dispatchEvent(
|
||||||
|
new CustomEvent("executing", { detail: msg.data.node }),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "executed":
|
||||||
|
api.dispatchEvent(new CustomEvent("executed", { detail: msg.data }));
|
||||||
|
break;
|
||||||
|
case "execution_start":
|
||||||
|
api.dispatchEvent(
|
||||||
|
new CustomEvent("execution_start", { detail: msg.data }),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "execution_error":
|
||||||
|
api.dispatchEvent(
|
||||||
|
new CustomEvent("execution_error", { detail: msg.data }),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "execution_cached":
|
||||||
|
api.dispatchEvent(
|
||||||
|
new CustomEvent("execution_cached", { detail: msg.data }),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
api.dispatchEvent(new CustomEvent(msg.type, { detail: msg.data }));
|
||||||
|
// default:
|
||||||
|
// if (this.#registered.has(msg.type)) {
|
||||||
|
// } else {
|
||||||
|
// throw new Error(`Unknown message type ${msg.type}`);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @typedef {import('../../../web/types/comfy.js').ComfyExtension} ComfyExtension*/
|
/** @typedef {import('../../../web/types/comfy.js').ComfyExtension} ComfyExtension*/
|
||||||
/** @type {ComfyExtension} */
|
/** @type {ComfyExtension} */
|
||||||
const ext = {
|
const ext = {
|
||||||
@ -33,8 +80,7 @@ const ext = {
|
|||||||
|
|
||||||
sendEventToCD("cd_plugin_onInit");
|
sendEventToCD("cd_plugin_onInit");
|
||||||
|
|
||||||
app.queuePrompt = ((originalFunction) =>
|
app.queuePrompt = ((originalFunction) => async () => {
|
||||||
async () => {
|
|
||||||
// const prompt = await app.graphToPrompt();
|
// const prompt = await app.graphToPrompt();
|
||||||
sendEventToCD("cd_plugin_onQueuePromptTrigger");
|
sendEventToCD("cd_plugin_onQueuePromptTrigger");
|
||||||
})(app.queuePrompt);
|
})(app.queuePrompt);
|
||||||
@ -208,7 +254,12 @@ const ext = {
|
|||||||
} else if (message.type === "queue_prompt") {
|
} else if (message.type === "queue_prompt") {
|
||||||
const prompt = await app.graphToPrompt();
|
const prompt = await app.graphToPrompt();
|
||||||
sendEventToCD("cd_plugin_onQueuePrompt", prompt);
|
sendEventToCD("cd_plugin_onQueuePrompt", prompt);
|
||||||
|
} else if (message.type === "event") {
|
||||||
|
dispatchAPIEventData(message.data);
|
||||||
}
|
}
|
||||||
|
// else if (message.type === "refresh") {
|
||||||
|
// sendEventToCD("cd_plugin_onRefresh");
|
||||||
|
// }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.error("Error processing message:", error);
|
// console.error("Error processing message:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user