This commit is contained in:
pythongosssss 2024-02-18 11:41:20 +00:00
parent 7f4276dd2c
commit 895141e1ae
9 changed files with 205 additions and 32 deletions

View File

@ -2081,6 +2081,7 @@ export class ComfyApp {
this.#processingQueue = false; this.#processingQueue = false;
} }
api.dispatchEvent(new CustomEvent("promptQueued", { detail: { number, batchCount } })); api.dispatchEvent(new CustomEvent("promptQueued", { detail: { number, batchCount } }));
return !this.lastNodeErrors;
} }
/** /**

View File

@ -13,7 +13,7 @@ export class ComfySplitButton {
* horizontal?: "left" | "right", * horizontal?: "left" | "right",
* position?: "relative" | "absolute" * position?: "relative" | "absolute"
* }} param0 * }} param0
* @param {Array<ComfyButton>} items * @param {Array<ComfyButton> | Array<HTMLElement>} items
*/ */
constructor({ primary, mode, horizontal = "left", position = "relative" }, ...items) { constructor({ primary, mode, horizontal = "left", position = "relative" }, ...items) {
this.arrow = new ComfyButton({ this.arrow = new ComfyButton({
@ -38,6 +38,6 @@ export class ComfySplitButton {
} }
update() { update() {
this.popup.element.replaceChildren(...this.items.map((b) => b.element)); this.popup.element.replaceChildren(...this.items.map((b) => b.element ?? b));
} }
} }

View File

@ -6,6 +6,7 @@ import { ComfyButton } from "../components/button.js";
export function getInteruptButton(visibility) { export function getInteruptButton(visibility) {
const btn = new ComfyButton({ const btn = new ComfyButton({
icon: "close", icon: "close",
tooltip: "Cancel current generation",
enabled: false, enabled: false,
action: () => { action: () => {
api.interrupt(); api.interrupt();

View File

@ -52,13 +52,18 @@
top: var(--top); top: var(--top);
z-index: 1000; z-index: 1000;
max-height: calc(100vh - var(--top) - 10px); max-height: calc(100vh - var(--top) - 10px);
max-width: calc(100vw - var(--left) - 10px);
} }
.comfyui-popup:not(.open) { .comfyui-popup:not(.open) {
display: none; 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 */ /* Split button */
.comfyui-split-button { .comfyui-split-button {
position: relative; position: relative;
@ -303,9 +308,6 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
border-top-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px;
box-sizing: border-box; box-sizing: border-box;
} }
.comfyui-view-list-popup h3 { .comfyui-view-list-popup h3 {
@ -361,7 +363,6 @@
.comfyui-queue-button .comfyui-split-primary .comfyui-button { .comfyui-queue-button .comfyui-split-primary .comfyui-button {
padding-right: 12px; padding-right: 12px;
} }
.comfyui-queue-count { .comfyui-queue-count {
margin-left: 5px; margin-left: 5px;
border-radius: 10px; border-radius: 10px;
@ -371,3 +372,50 @@
min-width: 1em; min-width: 1em;
display: inline-block; 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;
}

View File

@ -4,47 +4,93 @@ import { ComfyButton } from "../components/button.js";
import { $el } from "../../ui.js"; import { $el } from "../../ui.js";
import { api } from "../../api.js"; import { api } from "../../api.js";
import { ComfySplitButton } from "../components/splitButton.js"; import { ComfySplitButton } from "../components/splitButton.js";
import { ComfyQueueOptions } from "./queueOptions.js";
import { prop } from "../../utils.js";
export class ComfyQueueButton { export class ComfyQueueButton {
element = $el("div.comfyui-queue-button"); 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) { constructor(app) {
this.app = app;
this.queueSizeElement = $el("span.comfyui-queue-count", { this.queueSizeElement = $el("span.comfyui-queue-count", {
textContent: "?", 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( const btn = new ComfySplitButton(
{ {
primary: new ComfyButton({ primary: queue,
content: $el("div", [
$el("span", {
textContent: "Queue",
}),
this.queueSizeElement,
]),
icon: "play",
classList: "comfyui-button",
action: () => {
app.queuePrompt(0, 1);
},
}),
mode: "click", mode: "click",
position: "absolute", position: "absolute",
horizontal: "right", horizontal: "right",
}, },
new ComfyButton({ this.queueOptions.element
content: $el("button", { style: { height: "300px", width: "300px" } }),
})
); );
btn.element.classList.add("primary"); btn.element.classList.add("primary");
this.element.append(btn.element); this.element.append(btn.element);
api.addEventListener("status", ({ detail }) => { this.autoQueueMode = prop(this, "autoQueueMode", "", () => {
const sz = detail?.exec_info?.queue_remaining; switch (this.autoQueueMode) {
if (sz != null) { case "instant":
this.queueSizeElement.textContent = sz > 99 ? "99+" : sz; queue.icon = "infinity";
this.queueSizeElement.title = `${sz} promps in queue`; 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);
} }
} }

View File

@ -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,
})
);
});
}
}

View File

@ -9,7 +9,7 @@ export class ComfyViewHistoryButton extends ComfyViewListButton {
button: new ComfyButton({ button: new ComfyButton({
content: "View History", content: "View History",
icon: "history", icon: "history",
tooltip: "View History", tooltip: "View history",
classList: "comfyui-button comfyui-history-button", classList: "comfyui-button comfyui-history-button",
}), }),
list: ComfyViewHistoryList, list: ComfyViewHistoryList,

View File

@ -2,7 +2,7 @@
import { ComfyButton } from "../components/button.js"; import { ComfyButton } from "../components/button.js";
import { ComfyViewList, ComfyViewListButton } from "./viewList.js"; import { ComfyViewList, ComfyViewListButton } from "./viewList.js";
import { api } from "/scripts/api.js"; import { api } from "../../api.js";
export class ComfyViewQueueButton extends ComfyViewListButton { export class ComfyViewQueueButton extends ComfyViewListButton {
constructor(app) { constructor(app) {
@ -10,7 +10,7 @@ export class ComfyViewQueueButton extends ComfyViewListButton {
button: new ComfyButton({ button: new ComfyButton({
content: "View Queue", content: "View Queue",
icon: "format-list-numbered", icon: "format-list-numbered",
tooltip: "View Queue", tooltip: "View queue",
classList: "comfyui-button comfyui-queue-button", classList: "comfyui-button comfyui-queue-button",
}), }),
list: ComfyViewQueueList, list: ComfyViewQueueList,
@ -20,7 +20,7 @@ export class ComfyViewQueueButton extends ComfyViewListButton {
} }
export class ComfyViewQueueList extends ComfyViewList { export class ComfyViewQueueList extends ComfyViewList {
getRow(item, section) { getRow = (item, section) => {
if (section !== "Running") { if (section !== "Running") {
return super.getRow(item, section); return super.getRow(item, section);
} }