mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-22 00:47:01 +08:00
progress on progress
This commit is contained in:
parent
a3fe94513f
commit
bb5605d43a
@ -1172,7 +1172,7 @@ export class GroupNodeHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static isGroupNode(node) {
|
static isGroupNode(node) {
|
||||||
return !!node.constructor?.nodeData?.[GROUP];
|
return !!node?.constructor?.nodeData?.[GROUP];
|
||||||
}
|
}
|
||||||
|
|
||||||
static async fromNodes(nodes) {
|
static async fromNodes(nodes) {
|
||||||
|
|||||||
@ -1247,11 +1247,15 @@ export class ComfyApp {
|
|||||||
});
|
});
|
||||||
|
|
||||||
api.addEventListener("progress", ({ detail }) => {
|
api.addEventListener("progress", ({ detail }) => {
|
||||||
|
if (this.workflowManager.activePrompt?.workflow
|
||||||
|
&& this.workflowManager.activePrompt.workflow !== this.workflowManager.activeWorkflow) return console.log(this.workflowManager.activePrompt?.workflow, this.workflowManager.activeWorkflow);
|
||||||
this.progress = detail;
|
this.progress = detail;
|
||||||
this.graph.setDirtyCanvas(true, false);
|
this.graph.setDirtyCanvas(true, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
api.addEventListener("executing", ({ detail }) => {
|
api.addEventListener("executing", ({ detail }) => {
|
||||||
|
if (this.workflowManager.activePrompt ?.workflow
|
||||||
|
&& this.workflowManager.activePrompt.workflow !== this.workflowManager.activeWorkflow) return console.log(this.workflowManager.activePrompt?.workflow, this.workflowManager.activeWorkflow);
|
||||||
this.progress = null;
|
this.progress = null;
|
||||||
this.runningNodeId = detail;
|
this.runningNodeId = detail;
|
||||||
this.graph.setDirtyCanvas(true, false);
|
this.graph.setDirtyCanvas(true, false);
|
||||||
@ -1259,6 +1263,8 @@ export class ComfyApp {
|
|||||||
});
|
});
|
||||||
|
|
||||||
api.addEventListener("executed", ({ detail }) => {
|
api.addEventListener("executed", ({ detail }) => {
|
||||||
|
if (this.workflowManager.activePrompt ?.workflow
|
||||||
|
&& this.workflowManager.activePrompt.workflow !== this.workflowManager.activeWorkflow) return console.log(this.workflowManager.activePrompt?.workflow, this.workflowManager.activeWorkflow);
|
||||||
const output = this.nodeOutputs[detail.node];
|
const output = this.nodeOutputs[detail.node];
|
||||||
if (detail.merge && output) {
|
if (detail.merge && output) {
|
||||||
for (const k in detail.output ?? {}) {
|
for (const k in detail.output ?? {}) {
|
||||||
@ -1462,7 +1468,7 @@ export class ComfyApp {
|
|||||||
mainCanvas.style.touchAction = "none"
|
mainCanvas.style.touchAction = "none"
|
||||||
const canvasEl = (this.canvasEl = Object.assign(mainCanvas, { id: "graph-canvas" }));
|
const canvasEl = (this.canvasEl = Object.assign(mainCanvas, { id: "graph-canvas" }));
|
||||||
canvasEl.tabIndex = "1";
|
canvasEl.tabIndex = "1";
|
||||||
document.body.prepend(canvasEl);
|
document.body.append(canvasEl);
|
||||||
|
|
||||||
addDomClippingSetting();
|
addDomClippingSetting();
|
||||||
this.#addProcessMouseHandler();
|
this.#addProcessMouseHandler();
|
||||||
@ -1736,6 +1742,11 @@ export class ComfyApp {
|
|||||||
* @param { import("./workflows.js").ComfyWorkflowInstance | null } name The workflow
|
* @param { import("./workflows.js").ComfyWorkflowInstance | null } name The workflow
|
||||||
*/
|
*/
|
||||||
async loadGraphData(graphData, clean = true, workflow = null) {
|
async loadGraphData(graphData, clean = true, workflow = null) {
|
||||||
|
try {
|
||||||
|
this.workflowManager.activeWorkflow?.changeTracker?.store()
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
|
||||||
if (clean !== false) {
|
if (clean !== false) {
|
||||||
this.clean();
|
this.clean();
|
||||||
}
|
}
|
||||||
@ -1753,12 +1764,7 @@ export class ComfyApp {
|
|||||||
{
|
{
|
||||||
graphData = structuredClone(graphData);
|
graphData = structuredClone(graphData);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
this.workflowManager.activeWorkflow?.changeTracker?.storeViewport()
|
|
||||||
} catch (error) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.workflowManager.setWorkflow(workflow);
|
this.workflowManager.setWorkflow(workflow);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -2071,6 +2077,14 @@ export class ComfyApp {
|
|||||||
this.lastNodeErrors = res.node_errors;
|
this.lastNodeErrors = res.node_errors;
|
||||||
if (this.lastNodeErrors.length > 0) {
|
if (this.lastNodeErrors.length > 0) {
|
||||||
this.canvas.draw(true, true);
|
this.canvas.draw(true, true);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
this.workflowManager.storePrompt({
|
||||||
|
id: res.prompt_id,
|
||||||
|
nodes: Object.keys(p.output)
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const formattedError = this.#formatPromptError(error)
|
const formattedError = this.#formatPromptError(error)
|
||||||
|
|||||||
@ -14,6 +14,7 @@ export class ChangeTracker {
|
|||||||
workflow;
|
workflow;
|
||||||
|
|
||||||
ds;
|
ds;
|
||||||
|
nodeOutputs;
|
||||||
|
|
||||||
get app() {
|
get app() {
|
||||||
return this.workflow.manager.app;
|
return this.workflow.manager.app;
|
||||||
@ -23,14 +24,19 @@ export class ChangeTracker {
|
|||||||
this.workflow = workflow;
|
this.workflow = workflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
storeViewport() {
|
store() {
|
||||||
|
this.nodeOutputs = clone(this.app.nodeOutputs);
|
||||||
this.ds = { scale: this.app.canvas.ds.scale, offset: [...this.app.canvas.ds.offset] };
|
this.ds = { scale: this.app.canvas.ds.scale, offset: [...this.app.canvas.ds.offset] };
|
||||||
}
|
}
|
||||||
|
|
||||||
restoreViewport() {
|
restore() {
|
||||||
if (!this.ds) return;
|
if (this.ds) {
|
||||||
this.app.canvas.ds.scale = this.ds.scale;
|
this.app.canvas.ds.scale = this.ds.scale;
|
||||||
this.app.canvas.ds.offset = this.ds.offset;
|
this.app.canvas.ds.offset = this.ds.offset;
|
||||||
|
}
|
||||||
|
if (this.nodeOutputs) {
|
||||||
|
this.app.nodeOutputs = this.nodeOutputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkState() {
|
checkState() {
|
||||||
|
|||||||
@ -253,7 +253,7 @@ LGraphNode.prototype.addDOMWidget = function (name, type, element, options) {
|
|||||||
const transform = new DOMMatrix()
|
const transform = new DOMMatrix()
|
||||||
.scaleSelf(elRect.width / ctx.canvas.width, elRect.height / ctx.canvas.height)
|
.scaleSelf(elRect.width / ctx.canvas.width, elRect.height / ctx.canvas.height)
|
||||||
.multiplySelf(ctx.getTransform())
|
.multiplySelf(ctx.getTransform())
|
||||||
.translateSelf(margin, margin + y);
|
.translateSelf(margin, margin + y + elRect.top);
|
||||||
|
|
||||||
const scale = new DOMMatrix().scaleSelf(transform.a, transform.d);
|
const scale = new DOMMatrix().scaleSelf(transform.a, transform.d);
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export class ComfyAppMenu {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.logo = $el("h1.comfyui-logo.sm-hide", { title: "ComfyUI" }, "ComfyUI");
|
this.logo = $el("h1.comfyui-logo.sm-hide", { title: "ComfyUI" }, "ComfyUI");
|
||||||
this.element = $el("nav.comfyui-menu", { style: { display: "none" }, parent: document.body }, [
|
this.element = $el("nav.comfyui-menu", { style: { display: "none" } }, [
|
||||||
this.logo,
|
this.logo,
|
||||||
this.workflows.element,
|
this.workflows.element,
|
||||||
new ComfySplitButton(
|
new ComfySplitButton(
|
||||||
@ -126,6 +126,8 @@ export class ComfyAppMenu {
|
|||||||
).element,
|
).element,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
document.body.prepend(this.element);
|
||||||
|
|
||||||
app.ui.settings.addSetting({
|
app.ui.settings.addSetting({
|
||||||
id: "Comfy.UseNewMenu",
|
id: "Comfy.UseNewMenu",
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
|
|||||||
@ -37,12 +37,14 @@
|
|||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
.primary .comfyui-button, .primary.comfyui-button {
|
.primary .comfyui-button,
|
||||||
|
.primary.comfyui-button {
|
||||||
background-color: var(--primary-bg) !important;
|
background-color: var(--primary-bg) !important;
|
||||||
color: var(--primary-fg) !important;
|
color: var(--primary-fg) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.primary .comfyui-button:not(:disabled):hover, .primary.comfyui-button:not(:disabled):hover {
|
.primary .comfyui-button:not(:disabled):hover,
|
||||||
|
.primary.comfyui-button:not(:disabled):hover {
|
||||||
background-color: var(--primary-hover-bg) !important;
|
background-color: var(--primary-hover-bg) !important;
|
||||||
color: var(--primary-hover-fg) !important;
|
color: var(--primary-hover-fg) !important;
|
||||||
}
|
}
|
||||||
@ -126,9 +128,6 @@
|
|||||||
|
|
||||||
/* Menu */
|
/* Menu */
|
||||||
.comfyui-menu {
|
.comfyui-menu {
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
background: var(--comfy-menu-bg);
|
background: var(--comfy-menu-bg);
|
||||||
color: var(--fg-color);
|
color: var(--fg-color);
|
||||||
@ -273,6 +272,8 @@
|
|||||||
.comfyui-workflows-button {
|
.comfyui-workflows-button {
|
||||||
flex-direction: row-reverse;
|
flex-direction: row-reverse;
|
||||||
max-width: 200px;
|
max-width: 200px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfyui-workflows-button.popup-open {
|
.comfyui-workflows-button.popup-open {
|
||||||
@ -282,8 +283,17 @@
|
|||||||
.comfyui-workflows-button.unsaved {
|
.comfyui-workflows-button.unsaved {
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
.comfyui-workflows-button-progress {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
background-color: green;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 4px;
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
|
||||||
.comfyui-workflows-button>span {
|
.comfyui-workflows-button > span {
|
||||||
flex: auto;
|
flex: auto;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@ -292,7 +302,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 7px;
|
gap: 7px;
|
||||||
width: 130px;
|
width: 150px;
|
||||||
}
|
}
|
||||||
.comfyui-workflows-label {
|
.comfyui-workflows-label {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@ -318,7 +328,7 @@
|
|||||||
|
|
||||||
.comfyui-workflows-popup {
|
.comfyui-workflows-popup {
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
background-color: var(--border-color);
|
background-color: var(--border-color);
|
||||||
@ -337,6 +347,13 @@
|
|||||||
left: 50%;
|
left: 50%;
|
||||||
top: 75px;
|
top: 75px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comfyui-workflows-panel h3 {
|
||||||
|
margin: 10px 0 10px 0;
|
||||||
|
font-size: 11px;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
.comfyui-workflows-actions {
|
.comfyui-workflows-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
@ -353,7 +370,8 @@
|
|||||||
color: var(--primary-fg);
|
color: var(--primary-fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfyui-workflows-favorites, .comfyui-workflows-open {
|
.comfyui-workflows-favorites,
|
||||||
|
.comfyui-workflows-open {
|
||||||
border-bottom: 1px solid var(--comfy-input-bg);
|
border-bottom: 1px solid var(--comfy-input-bg);
|
||||||
padding-bottom: 5px;
|
padding-bottom: 5px;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
@ -373,22 +391,22 @@
|
|||||||
display: block;
|
display: block;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.comfyui-workflows-tree>ul {
|
.comfyui-workflows-tree > ul {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfyui-workflows-tree>ul ul {
|
.comfyui-workflows-tree > ul ul {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0 0 0 25px;
|
padding: 0 0 0 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfyui-workflows-tree .closed>ul {
|
.comfyui-workflows-tree .closed > ul {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfyui-workflows-tree li,
|
.comfyui-workflows-tree li,
|
||||||
.comfyui-workflows-tree-file {
|
.comfyui-workflows-tree-file {
|
||||||
--item-height: 31px;
|
--item-height: 32px;
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
height: var(--item-height);
|
height: var(--item-height);
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -409,30 +427,43 @@
|
|||||||
z-index: -1;
|
z-index: -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comfyui-workflows-tree-file.running:not(:hover)::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
width: var(--progress, 0);
|
||||||
|
left: 0;
|
||||||
|
height: var(--item-height);
|
||||||
|
background-color: green;
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comfyui-workflows-tree-file.unsaved span {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
.comfyui-workflows-tree-file span {
|
.comfyui-workflows-tree-file span {
|
||||||
flex: auto;
|
flex: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfyui-workflows-tree-file span+.comfyui-workflows-file-action {
|
.comfyui-workflows-tree-file span + .comfyui-workflows-file-action {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfyui-workflows-tree-file .comfyui-workflows-file-action {
|
.comfyui-workflows-tree-file .comfyui-workflows-file-action {
|
||||||
opacity: 0;
|
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
color: var(--fg-color);
|
color: var(--fg-color);
|
||||||
padding: 2px 4px;
|
padding: 2px 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comfyui-workflows-tree-file:not(:hover) .comfyui-workflows-file-action {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.comfyui-workflows-tree-file .comfyui-workflows-file-action:hover {
|
.comfyui-workflows-tree-file .comfyui-workflows-file-action:hover {
|
||||||
background-color: var(--primary-bg);
|
background-color: var(--primary-bg);
|
||||||
color: var(--primary-fg);
|
color: var(--primary-fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
.comfyui-workflows-tree-file:hover .comfyui-workflows-file-action {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comfyui-workflows-tree-file .comfyui-workflows-file-action-primary {
|
.comfyui-workflows-tree-file .comfyui-workflows-file-action-primary {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
color: var(--fg-color);
|
color: var(--fg-color);
|
||||||
@ -441,7 +472,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.comfyui-workflows-file-action-favorite .mdi-star {
|
.comfyui-workflows-file-action-favorite .mdi-star {
|
||||||
color: orange
|
color: orange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* View List */
|
/* View List */
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import { createSpinner } from "../spinner.js";
|
|||||||
import { ComfyWorkflow } from "../../workflows.js";
|
import { ComfyWorkflow } from "../../workflows.js";
|
||||||
|
|
||||||
export class ComfyWorkflowsMenu {
|
export class ComfyWorkflowsMenu {
|
||||||
|
#first = true;
|
||||||
element = $el("div.comfyui-workflows");
|
element = $el("div.comfyui-workflows");
|
||||||
|
|
||||||
get open() {
|
get open() {
|
||||||
@ -24,34 +25,18 @@ export class ComfyWorkflowsMenu {
|
|||||||
*/
|
*/
|
||||||
constructor(app) {
|
constructor(app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
this.#bindEvents();
|
||||||
const updateActive = () => {
|
|
||||||
const active = app.workflowManager.activeWorkflow;
|
|
||||||
this.button.tooltip = active.path;
|
|
||||||
this.workflowLabel.textContent = active.name;
|
|
||||||
this.unsaved = active.unsaved;
|
|
||||||
};
|
|
||||||
|
|
||||||
app.workflowManager.addEventListener("changeWorkflow", updateActive);
|
|
||||||
app.workflowManager.addEventListener("rename", updateActive);
|
|
||||||
app.workflowManager.addEventListener("delete", updateActive);
|
|
||||||
|
|
||||||
app.workflowManager.addEventListener("save", () => {
|
|
||||||
this.unsaved = app.workflowManager.activeWorkflow.unsaved;
|
|
||||||
});
|
|
||||||
|
|
||||||
api.addEventListener("graphChanged", () => {
|
|
||||||
this.unsaved = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
const classList = {
|
const classList = {
|
||||||
"comfyui-workflows-button": true,
|
"comfyui-workflows-button": true,
|
||||||
"comfyui-button": true,
|
"comfyui-button": true,
|
||||||
unsaved: getStorageValue("Comfy.PreviousWorkflowUnsaved") === "true",
|
unsaved: getStorageValue("Comfy.PreviousWorkflowUnsaved") === "true",
|
||||||
|
running: false,
|
||||||
};
|
};
|
||||||
|
this.buttonProgress = $el("div.comfyui-workflows-button-progress");
|
||||||
this.workflowLabel = $el("span.comfyui-workflows-label", "");
|
this.workflowLabel = $el("span.comfyui-workflows-label", "");
|
||||||
this.button = new ComfyButton({
|
this.button = new ComfyButton({
|
||||||
content: $el("div.comfyui-workflows-button-inner", [$el("i.mdi.mdi-graph"), this.workflowLabel]),
|
content: $el("div.comfyui-workflows-button-inner", [$el("i.mdi.mdi-graph"), this.workflowLabel, this.buttonProgress]),
|
||||||
icon: "chevron-down",
|
icon: "chevron-down",
|
||||||
classList,
|
classList,
|
||||||
});
|
});
|
||||||
@ -72,12 +57,59 @@ export class ComfyWorkflowsMenu {
|
|||||||
setStorageValue("Comfy.PreviousWorkflowUnsaved", v);
|
setStorageValue("Comfy.PreviousWorkflowUnsaved", v);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#updateProgress = () => {
|
||||||
|
const prompt = this.app.workflowManager.activePrompt;
|
||||||
|
let percent = 0;
|
||||||
|
if (this.app.workflowManager.activeWorkflow === prompt?.workflow) {
|
||||||
|
const total = Object.values(prompt.nodes);
|
||||||
|
const done = total.filter(Boolean);
|
||||||
|
percent = (done.length / total.length) * 100;
|
||||||
|
}
|
||||||
|
this.buttonProgress.style.width = percent + "%";
|
||||||
|
};
|
||||||
|
|
||||||
|
#updateActive = () => {
|
||||||
|
const active = this.app.workflowManager.activeWorkflow;
|
||||||
|
this.button.tooltip = active.path;
|
||||||
|
this.workflowLabel.textContent = active.name;
|
||||||
|
this.unsaved = active.unsaved;
|
||||||
|
|
||||||
|
if (this.#first) {
|
||||||
|
this.#first = false;
|
||||||
|
this.content.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#updateProgress();
|
||||||
|
};
|
||||||
|
|
||||||
|
#bindEvents() {
|
||||||
|
this.app.workflowManager.addEventListener("changeWorkflow", this.#updateActive);
|
||||||
|
this.app.workflowManager.addEventListener("rename", this.#updateActive);
|
||||||
|
this.app.workflowManager.addEventListener("delete", this.#updateActive);
|
||||||
|
|
||||||
|
this.app.workflowManager.addEventListener("save", () => {
|
||||||
|
this.unsaved = this.app.workflowManager.activeWorkflow.unsaved;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.app.workflowManager.addEventListener("execute", (e) => {
|
||||||
|
this.#updateProgress();
|
||||||
|
});
|
||||||
|
|
||||||
|
api.addEventListener("graphChanged", () => {
|
||||||
|
this.unsaved = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ComfyWorkflowsContent {
|
export class ComfyWorkflowsContent {
|
||||||
element = $el("div.comfyui-workflows-panel");
|
element = $el("div.comfyui-workflows-panel");
|
||||||
treeState = {};
|
treeState = {};
|
||||||
treeFiles = {};
|
treeFiles = {};
|
||||||
|
/** @type { Map<ComfyWorkflow, WorkflowElement> } */
|
||||||
|
openFiles = new Map();
|
||||||
|
/** @type {WorkflowElement} */
|
||||||
|
activeElement = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import("../../app.js").ComfyApp} app
|
* @param {import("../../app.js").ComfyApp} app
|
||||||
@ -128,22 +160,19 @@ export class ComfyWorkflowsContent {
|
|||||||
|
|
||||||
this.app.workflowManager.addEventListener("favorite", (e) => {
|
this.app.workflowManager.addEventListener("favorite", (e) => {
|
||||||
const workflow = e["detail"];
|
const workflow = e["detail"];
|
||||||
const button = this.treeFiles[workflow.path]?.primaryButton;
|
const button = this.treeFiles[workflow.path]?.primary;
|
||||||
if (!button) return; // Can happen when a workflow is renamed
|
if (!button) return; // Can happen when a workflow is renamed
|
||||||
button.icon = this.#getFavoriteIcon(workflow);
|
button.icon = this.#getFavoriteIcon(workflow);
|
||||||
button.overIcon = this.#getFavoriteOverIcon(workflow);
|
button.overIcon = this.#getFavoriteOverIcon(workflow);
|
||||||
this.updateFavorites();
|
this.updateFavorites();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.app.workflowManager.addEventListener("open", (e) => {
|
for (const e of ["save", "open", "close", "changeWorkflow"]) {
|
||||||
this.updateOpen();
|
// TODO: dont be lazy and just update the specific element
|
||||||
});
|
app.workflowManager.addEventListener(e, () => this.updateOpen());
|
||||||
this.app.workflowManager.addEventListener("close", (e) => {
|
}
|
||||||
this.updateOpen();
|
this.app.workflowManager.addEventListener("rename", () => this.load());
|
||||||
});
|
this.app.workflowManager.addEventListener("execute", (e) => this.#updateActive());
|
||||||
this.app.workflowManager.addEventListener("rename", (e) => {
|
|
||||||
this.load();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
@ -156,18 +185,45 @@ export class ComfyWorkflowsContent {
|
|||||||
|
|
||||||
updateOpen() {
|
updateOpen() {
|
||||||
const current = this.openElement;
|
const current = this.openElement;
|
||||||
|
this.openFiles.clear();
|
||||||
|
|
||||||
this.openElement = $el("div.comfyui-workflows-open", [
|
this.openElement = $el("div.comfyui-workflows-open", [
|
||||||
$el("h3", "Open Workflows"),
|
$el("h3", "Open"),
|
||||||
...this.app.workflowManager.openWorkflows.map((w) => {
|
...this.app.workflowManager.openWorkflows.map((w) => {
|
||||||
const wrapper = new WorkflowElement(this, w, {
|
const wrapper = new WorkflowElement(this, w, {
|
||||||
buttons: [],
|
primary: { element: $el("i.mdi.mdi-18px.mdi-circle-small") },
|
||||||
|
buttons: [
|
||||||
|
new ComfyButton({
|
||||||
|
icon: "content-save",
|
||||||
|
iconSize: 18,
|
||||||
|
classList: "comfyui-button comfyui-workflows-file-action",
|
||||||
|
enabled: w.unsaved,
|
||||||
|
action: (e) => {
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
w.save();
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new ComfyButton({
|
||||||
|
icon: "close",
|
||||||
|
iconSize: 18,
|
||||||
|
classList: "comfyui-button comfyui-workflows-file-action",
|
||||||
|
action: (e) => {
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
this.app.workflowManager.closeWorkflow(w);
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
if (w.unsaved) {
|
||||||
|
wrapper.element.classList.add("unsaved");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.openFiles.set(w, wrapper);
|
||||||
return wrapper.element;
|
return wrapper.element;
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
this.#updateActive();
|
||||||
current?.replaceWith(this.openElement);
|
current?.replaceWith(this.openElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,14 +231,14 @@ export class ComfyWorkflowsContent {
|
|||||||
const current = this.favoritesElement;
|
const current = this.favoritesElement;
|
||||||
const favorites = [...this.app.workflowManager.workflows.filter((w) => w.isFavorite)];
|
const favorites = [...this.app.workflowManager.workflows.filter((w) => w.isFavorite)];
|
||||||
|
|
||||||
this.favoritesElement = $el(
|
this.favoritesElement = $el("div.comfyui-workflows-favorites", [
|
||||||
"div.comfyui-workflows-favorites",
|
$el("h3", "Favorites"),
|
||||||
favorites
|
...favorites
|
||||||
.map((w) => {
|
.map((w) => {
|
||||||
return this.#getWorkflowElement(w).element;
|
return this.#getWorkflowElement(w).element;
|
||||||
})
|
})
|
||||||
.filter(Boolean)
|
.filter(Boolean),
|
||||||
);
|
]);
|
||||||
|
|
||||||
current?.replaceWith(this.favoritesElement);
|
current?.replaceWith(this.favoritesElement);
|
||||||
}
|
}
|
||||||
@ -192,13 +248,14 @@ export class ComfyWorkflowsContent {
|
|||||||
const nodes = {};
|
const nodes = {};
|
||||||
|
|
||||||
this.treeFiles = {};
|
this.treeFiles = {};
|
||||||
this.treeElement = $el("ul.comfyui-workflows-tree");
|
const tree = $el("ul.comfyui-workflows-tree");
|
||||||
|
this.treeElement = $el("section", [$el("h3", "Browse"), tree]);
|
||||||
|
|
||||||
for (const workflow of this.app.workflowManager.workflows) {
|
for (const workflow of this.app.workflowManager.workflows) {
|
||||||
if (!workflow.pathParts) continue;
|
if (!workflow.pathParts) continue;
|
||||||
|
|
||||||
let currentPath = "";
|
let currentPath = "";
|
||||||
let currentRoot = this.treeElement;
|
let currentRoot = tree;
|
||||||
|
|
||||||
for (let i = 0; i < workflow.pathParts.length; i++) {
|
for (let i = 0; i < workflow.pathParts.length; i++) {
|
||||||
currentPath += (currentPath ? "\\" : "") + workflow.pathParts[i];
|
currentPath += (currentPath ? "\\" : "") + workflow.pathParts[i];
|
||||||
@ -230,6 +287,34 @@ export class ComfyWorkflowsContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#updateActive() {
|
||||||
|
this.#removeActive();
|
||||||
|
|
||||||
|
const active = this.app.workflowManager.activePrompt;
|
||||||
|
if (!active?.workflow) return;
|
||||||
|
|
||||||
|
const open = this.openFiles.get(active.workflow);
|
||||||
|
if (!open) return;
|
||||||
|
|
||||||
|
this.activeElement = open;
|
||||||
|
|
||||||
|
const total = Object.values(active.nodes);
|
||||||
|
const done = total.filter(Boolean);
|
||||||
|
const percent = done.length / total.length;
|
||||||
|
open.element.classList.add("running");
|
||||||
|
open.element.style.setProperty("--progress", percent * 100 + "%");
|
||||||
|
open.primary.element.classList.remove("mdi-circle-small");
|
||||||
|
open.primary.element.classList.add("mdi-play");
|
||||||
|
}
|
||||||
|
|
||||||
|
#removeActive() {
|
||||||
|
if (!this.activeElement) return;
|
||||||
|
this.activeElement.element.classList.remove("running");
|
||||||
|
this.activeElement.element.style.removeProperty("--progress");
|
||||||
|
this.activeElement.primary.element.classList.add("mdi-circle-small");
|
||||||
|
this.activeElement.primary.element.classList.remove("mdi-play");
|
||||||
|
}
|
||||||
|
|
||||||
/** @param {ComfyWorkflow} workflow */
|
/** @param {ComfyWorkflow} workflow */
|
||||||
#getFavoriteIcon(workflow) {
|
#getFavoriteIcon(workflow) {
|
||||||
return workflow.isFavorite ? "star" : "file-outline";
|
return workflow.isFavorite ? "star" : "file-outline";
|
||||||
@ -321,7 +406,7 @@ export class ComfyWorkflowsContent {
|
|||||||
/** @param {ComfyWorkflow} workflow */
|
/** @param {ComfyWorkflow} workflow */
|
||||||
#getWorkflowElement(workflow) {
|
#getWorkflowElement(workflow) {
|
||||||
return new WorkflowElement(this, workflow, {
|
return new WorkflowElement(this, workflow, {
|
||||||
primaryButton: this.#getFavoriteButton(workflow, true),
|
primary: this.#getFavoriteButton(workflow, true),
|
||||||
buttons: [this.#getInsertButton(workflow), this.#getRenameButton(workflow), this.#getDeleteButton(workflow)],
|
buttons: [this.#getInsertButton(workflow), this.#getRenameButton(workflow), this.#getDeleteButton(workflow)],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -364,10 +449,10 @@ class WorkflowElement {
|
|||||||
* @param { ComfyWorkflowsContent } parent
|
* @param { ComfyWorkflowsContent } parent
|
||||||
* @param { ComfyWorkflow } workflow
|
* @param { ComfyWorkflow } workflow
|
||||||
*/
|
*/
|
||||||
constructor(parent, workflow, { tagName = "li", primaryButton, buttons }) {
|
constructor(parent, workflow, { tagName = "li", primary, buttons }) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.workflow = workflow;
|
this.workflow = workflow;
|
||||||
this.primaryButton = primaryButton;
|
this.primary = primary;
|
||||||
this.buttons = buttons;
|
this.buttons = buttons;
|
||||||
|
|
||||||
this.element = $el(
|
this.element = $el(
|
||||||
@ -379,7 +464,7 @@ class WorkflowElement {
|
|||||||
},
|
},
|
||||||
title: this.workflow.path,
|
title: this.workflow.path,
|
||||||
},
|
},
|
||||||
[this.primaryButton?.element, $el("span", workflow.name), ...buttons.map((b) => b.element)]
|
[this.primary?.element, $el("span", workflow.name), ...buttons.map((b) => b.element)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,20 +12,30 @@ function appendJson(path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ComfyWorkflowManager extends EventTarget {
|
export class ComfyWorkflowManager extends EventTarget {
|
||||||
|
/** @type {string | null} */
|
||||||
|
#activePromptId = null;
|
||||||
#unsavedCount = 0;
|
#unsavedCount = 0;
|
||||||
|
|
||||||
/** @type {Record<string, ComfyWorkflow>} */
|
/** @type {Record<string, ComfyWorkflow>} */
|
||||||
workflowLookup = {};
|
workflowLookup = {};
|
||||||
|
|
||||||
/** @type {Array<ComfyWorkflow>} */
|
/** @type {Array<ComfyWorkflow>} */
|
||||||
workflows = [];
|
workflows = [];
|
||||||
/** @type {Array<ComfyWorkflow>} */
|
/** @type {Array<ComfyWorkflow>} */
|
||||||
openWorkflows = [];
|
openWorkflows = [];
|
||||||
|
/** @type {Record<string, {workflow?: ComfyWorkflow, nodes?: Record<string, boolean>}>} */
|
||||||
|
queuedPrompts = {};
|
||||||
|
|
||||||
get activeWorkflow() {
|
get activeWorkflow() {
|
||||||
return this.openWorkflows[0];
|
return this.openWorkflows[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get activePromptId() {
|
||||||
|
return this.#activePromptId;
|
||||||
|
}
|
||||||
|
|
||||||
|
get activePrompt() {
|
||||||
|
return this.queuedPrompts[this.#activePromptId];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import("./app.js").ComfyApp} app
|
* @param {import("./app.js").ComfyApp} app
|
||||||
*/
|
*/
|
||||||
@ -33,6 +43,48 @@ export class ComfyWorkflowManager extends EventTarget {
|
|||||||
super();
|
super();
|
||||||
this.app = app;
|
this.app = app;
|
||||||
ChangeTracker.init(app);
|
ChangeTracker.init(app);
|
||||||
|
|
||||||
|
this.#bindExecutionEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
#bindExecutionEvents() {
|
||||||
|
// TODO: on reload, set active prompt based on the latest ws message
|
||||||
|
|
||||||
|
const emit = () => this.dispatchEvent(new CustomEvent("execute", { detail: this.activePrompt }));
|
||||||
|
let executing = null;
|
||||||
|
api.addEventListener("execution_start", (e) => {
|
||||||
|
this.#activePromptId = e.detail.prompt_id;
|
||||||
|
|
||||||
|
// This event can fire before the event is stored, so put a placeholder
|
||||||
|
this.queuedPrompts[this.#activePromptId] ??= { nodes: {} };
|
||||||
|
emit();
|
||||||
|
});
|
||||||
|
api.addEventListener("execution_cached", (e) => {
|
||||||
|
if (!this.activePrompt) return;
|
||||||
|
for (const n of e.detail.nodes) {
|
||||||
|
this.activePrompt.nodes[n] = true;
|
||||||
|
}
|
||||||
|
emit();
|
||||||
|
});
|
||||||
|
api.addEventListener("executed", (e) => {
|
||||||
|
if (!this.activePrompt) return;
|
||||||
|
this.activePrompt.nodes[e.detail.node] = true;
|
||||||
|
emit();
|
||||||
|
});
|
||||||
|
api.addEventListener("executing", (e) => {
|
||||||
|
if (!this.activePrompt) return;
|
||||||
|
|
||||||
|
if (executing) {
|
||||||
|
// Seems sometimes nodes that are cached fire executing but not executed
|
||||||
|
this.activePrompt.nodes[executing] = true;
|
||||||
|
}
|
||||||
|
executing = e.detail;
|
||||||
|
if (!executing) {
|
||||||
|
delete this.queuedPrompts[this.#activePromptId];
|
||||||
|
this.#activePromptId = null;
|
||||||
|
}
|
||||||
|
emit();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadWorkflows() {
|
async loadWorkflows() {
|
||||||
@ -99,6 +151,35 @@ export class ComfyWorkflowManager extends EventTarget {
|
|||||||
setStorageValue("Comfy.PreviousWorkflow", this.activeWorkflow.path ?? "");
|
setStorageValue("Comfy.PreviousWorkflow", this.activeWorkflow.path ?? "");
|
||||||
this.dispatchEvent(new CustomEvent("changeWorkflow"));
|
this.dispatchEvent(new CustomEvent("changeWorkflow"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storePrompt({ nodes, id }) {
|
||||||
|
this.queuedPrompts[id] ??= {};
|
||||||
|
this.queuedPrompts[id].nodes = {
|
||||||
|
...nodes.reduce((p, n) => {
|
||||||
|
p[n] = false;
|
||||||
|
return p;
|
||||||
|
}, {}),
|
||||||
|
...this.queuedPrompts[id].nodes,
|
||||||
|
};
|
||||||
|
this.queuedPrompts[id].workflow = this.activeWorkflow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ComfyWorkflow} workflow
|
||||||
|
*/
|
||||||
|
async closeWorkflow(workflow) {
|
||||||
|
if (!workflow.isOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
workflow.changeTracker = null;
|
||||||
|
this.openWorkflows.splice(this.openWorkflows.indexOf(workflow), 1);
|
||||||
|
if (this.openWorkflows.length) {
|
||||||
|
await this.openWorkflows[0].load();
|
||||||
|
} else {
|
||||||
|
// Load default
|
||||||
|
await this.app.loadGraphData();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ComfyWorkflow {
|
export class ComfyWorkflow {
|
||||||
@ -188,7 +269,6 @@ export class ComfyWorkflow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
load = async () => {
|
load = async () => {
|
||||||
debugger;
|
|
||||||
if (this.isOpen) {
|
if (this.isOpen) {
|
||||||
await this.manager.app.loadGraphData(this.changeTracker.activeState, true, this);
|
await this.manager.app.loadGraphData(this.changeTracker.activeState, true, this);
|
||||||
} else {
|
} else {
|
||||||
@ -282,7 +362,7 @@ export class ComfyWorkflow {
|
|||||||
|
|
||||||
track() {
|
track() {
|
||||||
if (this.changeTracker) {
|
if (this.changeTracker) {
|
||||||
this.changeTracker.restoreViewport();
|
this.changeTracker.restore();
|
||||||
} else {
|
} else {
|
||||||
this.changeTracker = new ChangeTracker(this);
|
this.changeTracker = new ChangeTracker(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,8 @@ body {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: var(--bg-color);
|
background-color: var(--bg-color);
|
||||||
color: var(--fg-color);
|
color: var(--fg-color);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
#graph-canvas {
|
#graph-canvas {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user