diff --git a/web/scripts/app.js b/web/scripts/app.js index a415ba906..820d46db8 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -2081,6 +2081,7 @@ export class ComfyApp { this.#processingQueue = false; } api.dispatchEvent(new CustomEvent("promptQueued", { detail: { number, batchCount } })); + return !this.lastNodeErrors; } /** diff --git a/web/scripts/ui/components/splitButton.js b/web/scripts/ui/components/splitButton.js index e1f97ce90..99ba9b4af 100644 --- a/web/scripts/ui/components/splitButton.js +++ b/web/scripts/ui/components/splitButton.js @@ -13,7 +13,7 @@ export class ComfySplitButton { * horizontal?: "left" | "right", * position?: "relative" | "absolute" * }} param0 - * @param {Array} items + * @param {Array | Array} items */ constructor({ primary, mode, horizontal = "left", position = "relative" }, ...items) { this.arrow = new ComfyButton({ @@ -38,6 +38,6 @@ export class ComfySplitButton { } update() { - this.popup.element.replaceChildren(...this.items.map((b) => b.element)); + this.popup.element.replaceChildren(...this.items.map((b) => b.element ?? b)); } } diff --git a/web/scripts/ui/menu/extraOptions.js b/web/scripts/ui/menu/extraOptions.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/scripts/ui/menu/interruptButton.js b/web/scripts/ui/menu/interruptButton.js index b285005b5..4db3328db 100644 --- a/web/scripts/ui/menu/interruptButton.js +++ b/web/scripts/ui/menu/interruptButton.js @@ -6,6 +6,7 @@ import { ComfyButton } from "../components/button.js"; export function getInteruptButton(visibility) { const btn = new ComfyButton({ icon: "close", + tooltip: "Cancel current generation", enabled: false, action: () => { api.interrupt(); diff --git a/web/scripts/ui/menu/menu.css b/web/scripts/ui/menu/menu.css index d22ad6711..5f97c4fc1 100644 --- a/web/scripts/ui/menu/menu.css +++ b/web/scripts/ui/menu/menu.css @@ -52,13 +52,18 @@ top: var(--top); z-index: 1000; max-height: calc(100vh - var(--top) - 10px); - max-width: calc(100vw - var(--left) - 10px); } .comfyui-popup:not(.open) { display: none; } +.comfyui-popup.right.open { + border-top-left-radius: 4px; + border-bottom-right-radius: 4px; + border-bottom-left-radius: 4px; + overflow: hidden; +} /* Split button */ .comfyui-split-button { position: relative; @@ -303,9 +308,6 @@ display: flex; flex-direction: column; align-items: center; - border-top-left-radius: 4px; - border-bottom-right-radius: 4px; - border-bottom-left-radius: 4px; box-sizing: border-box; } .comfyui-view-list-popup h3 { @@ -361,7 +363,6 @@ .comfyui-queue-button .comfyui-split-primary .comfyui-button { padding-right: 12px; } - .comfyui-queue-count { margin-left: 5px; border-radius: 10px; @@ -371,3 +372,50 @@ min-width: 1em; display: inline-block; } +/* Queue options*/ +.comfyui-queue-options { + padding: 10px; + font-family: Arial, Helvetica, sans-serif; + font-size: 12px; + display: flex; + gap: 10px; +} + +.comfyui-queue-batch { + display: flex; + flex-direction: column; + border-right: 1px solid var(--comfy-menu-bg); + padding-right: 10px; + gap: 5px; +} + +.comfyui-queue-batch input { + width: 145px; +} + +.comfyui-queue-batch .comfyui-queue-batch-value { + width: 70px; +} + +.comfyui-queue-mode { + display: flex; + flex-direction: column; +} + +.comfyui-queue-mode span { + font-weight: bold; + margin-bottom: 2px; +} + +.comfyui-queue-mode label { + display: flex; + flex-direction: row-reverse; + justify-content: start; + gap: 5px; + padding: 2px 0; +} + +.comfyui-queue-mode label input { + padding: 0; + margin: 0; +} diff --git a/web/scripts/ui/menu/queueButton.js b/web/scripts/ui/menu/queueButton.js index 2806a0868..1add584e7 100644 --- a/web/scripts/ui/menu/queueButton.js +++ b/web/scripts/ui/menu/queueButton.js @@ -4,47 +4,93 @@ import { ComfyButton } from "../components/button.js"; import { $el } from "../../ui.js"; import { api } from "../../api.js"; import { ComfySplitButton } from "../components/splitButton.js"; +import { ComfyQueueOptions } from "./queueOptions.js"; +import { prop } from "../../utils.js"; export class ComfyQueueButton { element = $el("div.comfyui-queue-button"); + #internalQueueSize = 0; + + queuePrompt = async () => { + this.#internalQueueSize += this.queueOptions.batchCount; + await this.app.queuePrompt(-1, this.queueOptions.batchCount); + }; constructor(app) { + this.app = app; this.queueSizeElement = $el("span.comfyui-queue-count", { textContent: "?", }); + const queue = new ComfyButton({ + content: $el("div", [ + $el("span", { + textContent: "Queue", + }), + this.queueSizeElement, + ]), + icon: "play", + classList: "comfyui-button", + action: this.queuePrompt, + }); + + this.queueOptions = new ComfyQueueOptions(app); + const btn = new ComfySplitButton( { - primary: new ComfyButton({ - content: $el("div", [ - $el("span", { - textContent: "Queue", - }), - this.queueSizeElement, - ]), - icon: "play", - classList: "comfyui-button", - action: () => { - app.queuePrompt(0, 1); - }, - }), + primary: queue, mode: "click", position: "absolute", horizontal: "right", }, - new ComfyButton({ - content: $el("button", { style: { height: "300px", width: "300px" } }), - }) + this.queueOptions.element ); btn.element.classList.add("primary"); this.element.append(btn.element); - api.addEventListener("status", ({ detail }) => { - const sz = detail?.exec_info?.queue_remaining; - if (sz != null) { - this.queueSizeElement.textContent = sz > 99 ? "99+" : sz; - this.queueSizeElement.title = `${sz} promps in queue`; + this.autoQueueMode = prop(this, "autoQueueMode", "", () => { + switch (this.autoQueueMode) { + case "instant": + queue.icon = "infinity"; + break; + case "change": + queue.icon = "auto-mode"; + break; + default: + queue.icon = "play"; + break; } }); + + this.queueOptions.addEventListener("autoQueueMode", (e) => (this.autoQueueMode = e["detail"])); + + api.addEventListener("graphChanged", () => { + if (this.autoQueueMode === "change") { + if (this.#internalQueueSize) { + this.graphHasChanged = true; + } else { + this.graphHasChanged = false; + this.queuePrompt(); + } + } + }); + + api.addEventListener("status", ({ detail }) => { + this.#internalQueueSize = detail?.exec_info?.queue_remaining; + if (this.#internalQueueSize != null) { + this.queueSizeElement.textContent = this.#internalQueueSize > 99 ? "99+" : this.#internalQueueSize + ""; + this.queueSizeElement.title = `${this.#internalQueueSize} prompts in queue`; + if (!this.#internalQueueSize && !app.lastExecutionError) { + if (this.autoQueueMode === "instant" || (this.autoQueueMode === "change" && this.graphHasChanged)) { + this.graphHasChanged = false; + this.queuePrompt(); + } + } + } + }); + + setTimeout(() => { + btn.popup.open = true; + }, 500); } } diff --git a/web/scripts/ui/menu/queueOptions.js b/web/scripts/ui/menu/queueOptions.js new file mode 100644 index 000000000..f3d34e74e --- /dev/null +++ b/web/scripts/ui/menu/queueOptions.js @@ -0,0 +1,77 @@ +// @ts-check + +import { $el } from "../../ui.js"; +import { prop } from "../../utils.js"; + +export class ComfyQueueOptions extends EventTarget { + element = $el("div.comfyui-queue-options"); + + constructor(app) { + super(); + this.app = app; + + this.batchCountInput = $el("input", { + className: "comfyui-queue-batch-value", + type: "number", + min: "1", + value: "1", + oninput: () => (this.batchCount = +this.batchCountInput.value), + }); + + this.batchCountRange = $el("input", { + type: "range", + min: "1", + max: "100", + value: "1", + oninput: () => (this.batchCount = +this.batchCountRange.value), + }); + + this.element.append( + $el("div.comfyui-queue-batch", [ + $el( + "label", + { + textContent: "Batch count: ", + }, + this.batchCountInput + ), + this.batchCountRange, + ]) + ); + + const createOption = (text, value, checked = false) => + $el( + "label", + { textContent: text }, + $el("input", { + type: "radio", + name: "AutoQueueMode", + checked, + value, + oninput: (e) => (this.autoQueueMode = e.target["value"]), + }) + ); + + this.autoQueueEl = $el("div.comfyui-queue-mode", [ + $el("span", "Auto Queue:"), + createOption("Disabled", "", true), + createOption("Instant", "instant"), + createOption("On Change", "change"), + ]); + + this.element.append(this.autoQueueEl); + + this.batchCount = prop(this, "batchCount", 1, () => { + this.batchCountInput.value = this.batchCount + ""; + this.batchCountRange.value = this.batchCount + ""; + }); + + this.autoQueueMode = prop(this, "autoQueueMode", "Disabled", () => { + this.dispatchEvent( + new CustomEvent("autoQueueMode", { + detail: this.autoQueueMode, + }) + ); + }); + } +} diff --git a/web/scripts/ui/menu/viewHistory.js b/web/scripts/ui/menu/viewHistory.js index e095151fe..de6b343dc 100644 --- a/web/scripts/ui/menu/viewHistory.js +++ b/web/scripts/ui/menu/viewHistory.js @@ -9,7 +9,7 @@ export class ComfyViewHistoryButton extends ComfyViewListButton { button: new ComfyButton({ content: "View History", icon: "history", - tooltip: "View History", + tooltip: "View history", classList: "comfyui-button comfyui-history-button", }), list: ComfyViewHistoryList, diff --git a/web/scripts/ui/menu/viewQueue.js b/web/scripts/ui/menu/viewQueue.js index cef7d15b8..97d012986 100644 --- a/web/scripts/ui/menu/viewQueue.js +++ b/web/scripts/ui/menu/viewQueue.js @@ -2,7 +2,7 @@ import { ComfyButton } from "../components/button.js"; import { ComfyViewList, ComfyViewListButton } from "./viewList.js"; -import { api } from "/scripts/api.js"; +import { api } from "../../api.js"; export class ComfyViewQueueButton extends ComfyViewListButton { constructor(app) { @@ -10,7 +10,7 @@ export class ComfyViewQueueButton extends ComfyViewListButton { button: new ComfyButton({ content: "View Queue", icon: "format-list-numbered", - tooltip: "View Queue", + tooltip: "View queue", classList: "comfyui-button comfyui-queue-button", }), list: ComfyViewQueueList, @@ -20,7 +20,7 @@ export class ComfyViewQueueButton extends ComfyViewListButton { } export class ComfyViewQueueList extends ComfyViewList { - getRow(item, section) { + getRow = (item, section) => { if (section !== "Running") { return super.getRow(item, section); }