Only swap seed widget values if ComfyUI is currently processing a queue. Fixes #62

This commit is contained in:
rgthree
2023-12-01 22:20:25 -05:00
parent 65832bcc83
commit 981a5eb275
4 changed files with 29 additions and 6 deletions
+9 -3
View File
@@ -102,6 +102,8 @@ class Rgthree {
monitorBadLinksAlerted = false;
monitorLinkTimeout: number|null = null;
processingQueue = false;
async clearAllMessages() {
let container = document.querySelector('.rgthree-top-messages-container');
container && (container.innerHTML = '');
@@ -194,9 +196,13 @@ class Rgthree {
const queuePrompt = app.queuePrompt as Function;
app.queuePrompt = async function() {
that.fireEvent('queue', {});
let promise = queuePrompt.apply(app, [...arguments]);
that.fireEvent('queue-end', {});
return promise;
that.processingQueue = true;
try {
await queuePrompt.apply(app, [...arguments])
} finally {
that.processingQueue = false;
that.fireEvent('queue-end', {});
}
}
const graphToPrompt = app.graphToPrompt as Function;
+7
View File
@@ -14,6 +14,7 @@ import type {
} from "./typings/litegraph.js";
import type { ComfyApp, ComfyObjectInfo, ComfyWidget, ComfyGraphNode } from "./typings/comfy.js";
import { RgthreeBaseNode } from "./base_node.js";
import { rgthree } from "./rgthree.js";
declare const LiteGraph: typeof TLiteGraph;
declare const LGraphNode: typeof TLGraphNode;
@@ -121,6 +122,12 @@ class SeedControl {
*/
this.seedWidget.serializeValue = async (node: SerializedLGraphNode, index: number) => {
const inputSeed = this.seedWidget.value;
// Only actually swap and set the value when we're currently queuing. Some other nodes, like
// cg-use-everywhere, serializes the graph even when not queing, and we don't want to swap
// widget values in these cases.
if (!rgthree.processingQueue) {
return inputSeed;
}
this.serializedCtx = {
inputSeed: this.seedWidget.value,
};
+9 -3
View File
@@ -125,6 +125,7 @@ class Rgthree {
this.logger = new LogSession("[rgthree]");
this.monitorBadLinksAlerted = false;
this.monitorLinkTimeout = null;
this.processingQueue = false;
this.eventsToFns = new Map();
window.addEventListener("keydown", (e) => {
this.ctrlKey = !!e.ctrlKey;
@@ -142,9 +143,14 @@ class Rgthree {
const queuePrompt = app.queuePrompt;
app.queuePrompt = async function () {
that.fireEvent('queue', {});
let promise = queuePrompt.apply(app, [...arguments]);
that.fireEvent('queue-end', {});
return promise;
that.processingQueue = true;
try {
await queuePrompt.apply(app, [...arguments]);
}
finally {
that.processingQueue = false;
that.fireEvent('queue-end', {});
}
};
const graphToPrompt = app.graphToPrompt;
app.graphToPrompt = async function () {
+4
View File
@@ -1,5 +1,6 @@
import { app } from "../../scripts/app.js";
import { ComfyWidgets } from "../../scripts/widgets.js";
import { rgthree } from "./rgthree.js";
const LAST_SEED_BUTTON_LABEL = "♻️ (Use Last Queued Seed)";
const SPECIAL_SEED_RANDOM = -1;
const SPECIAL_SEED_INCREMENT = -2;
@@ -54,6 +55,9 @@ class SeedControl {
this.lastSeedButton.disabled = true;
this.seedWidget.serializeValue = async (node, index) => {
const inputSeed = this.seedWidget.value;
if (!rgthree.processingQueue) {
return inputSeed;
}
this.serializedCtx = {
inputSeed: this.seedWidget.value,
};