Various fixes

This commit is contained in:
pythongosssss 2024-06-19 20:18:08 +01:00
parent 9f5eb4b59d
commit 4643e37599
5 changed files with 67 additions and 39 deletions

View File

@ -1539,8 +1539,6 @@ export class ComfyApp {
*/ */
async setup() { async setup() {
await this.#setUser(); await this.#setUser();
await Promise.all([this.workflowManager.loadWorkflows(), this.ui.settings.load()]);
await this.#loadExtensions();
// Create and mount the LiteGraph in the DOM // Create and mount the LiteGraph in the DOM
const mainCanvas = document.createElement("canvas") const mainCanvas = document.createElement("canvas")
@ -1548,6 +1546,10 @@ export class ComfyApp {
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.append(canvasEl); document.body.append(canvasEl);
this.resizeCanvas();
await Promise.all([this.workflowManager.loadWorkflows(), this.ui.settings.load()]);
await this.#loadExtensions();
addDomClippingSetting(); addDomClippingSetting();
this.#addProcessMouseHandler(); this.#addProcessMouseHandler();
@ -1634,7 +1636,7 @@ export class ComfyApp {
this.canvasEl.width = Math.round(width * scale); this.canvasEl.width = Math.round(width * scale);
this.canvasEl.height = Math.round(height * scale); this.canvasEl.height = Math.round(height * scale);
this.canvasEl.getContext("2d").scale(scale, scale); this.canvasEl.getContext("2d").scale(scale, scale);
this.canvas.draw(true, true); this.canvas?.draw(true, true);
} }
/** /**

View File

@ -173,7 +173,7 @@ export class ChangeTracker {
// Store node outputs // Store node outputs
api.addEventListener("executed", ({ detail }) => { api.addEventListener("executed", ({ detail }) => {
const prompt = app.workflowManager.queuedPrompts[detail.prompt_id]; const prompt = app.workflowManager.queuedPrompts[detail.prompt_id];
if (!prompt.workflow) return; if (!prompt?.workflow) return;
const nodeOutputs = (prompt.workflow.changeTracker.nodeOutputs ??= {}); const nodeOutputs = (prompt.workflow.changeTracker.nodeOutputs ??= {});
const output = nodeOutputs[detail.node]; const output = nodeOutputs[detail.node];
if (detail.merge && output) { if (detail.merge && output) {

View File

@ -196,6 +196,8 @@ function dragElement(dragEl, settings) {
document.onmouseup = null; document.onmouseup = null;
document.onmousemove = null; document.onmousemove = null;
} }
return restorePos;
} }
class ComfyList { class ComfyList {
@ -632,7 +634,7 @@ export class ComfyUI {
onChange: function(value) { document.getElementById("comfy-dev-save-api-button").style.display = value ? "flex" : "none"}, onChange: function(value) { document.getElementById("comfy-dev-save-api-button").style.display = value ? "flex" : "none"},
}); });
dragElement(this.menuContainer, this.settings); this.restoreMenuPosition = dragElement(this.menuContainer, this.settings);
this.setStatus({exec_info: {queue_remaining: "X"}}); this.setStatus({exec_info: {queue_remaining: "X"}});
} }

View File

@ -21,6 +21,17 @@ const showOnMobile = (t) => {
}; };
export class ComfyAppMenu { export class ComfyAppMenu {
#sizeBreak = "lg";
#lastSizeBreaks = {
lg: null,
md: null,
sm: null,
xs: null,
};
#sizeBreaks = Object.keys(this.#lastSizeBreaks);
#cachedInnerSize = null;
#cacheTimeout = null;
/** /**
* @param { import("../../app.js").ComfyApp } app * @param { import("../../app.js").ComfyApp } app
*/ */
@ -41,7 +52,7 @@ export class ComfyAppMenu {
{ {
primary: getSaveButton(), primary: getSaveButton(),
mode: "hover", mode: "hover",
position: "absolute" position: "absolute",
}, },
getSaveButton("Save"), getSaveButton("Save"),
new ComfyButton({ new ComfyButton({
@ -54,7 +65,7 @@ export class ComfyAppMenu {
icon: "download", icon: "download",
content: "Export", content: "Export",
tooltip: "Export the current workflow as JSON", tooltip: "Export the current workflow as JSON",
action: () => this.exportWorkflow( "workflow", "workflow"), action: () => this.exportWorkflow("workflow", "workflow"),
}), }),
new ComfyButton({ new ComfyButton({
icon: "api", icon: "api",
@ -82,7 +93,7 @@ export class ComfyAppMenu {
icon: "fit-to-page-outline", icon: "fit-to-page-outline",
content: "Reset View", content: "Reset View",
tooltip: "Reset the canvas view", tooltip: "Reset the canvas view",
action: () => app.resetView() action: () => app.resetView(),
}), }),
new ComfyButton({ new ComfyButton({
icon: "cancel", icon: "cancel",
@ -134,47 +145,49 @@ export class ComfyAppMenu {
showOnMobile(this.mobileMenuButton).element, showOnMobile(this.mobileMenuButton).element,
]); ]);
app.ui.settings.addSetting({ let resizeHandler;
this.menuPositionSetting = app.ui.settings.addSetting({
id: "Comfy.UseNewMenu", id: "Comfy.UseNewMenu",
defaultValue: false, defaultValue: "Disabled",
name: "[Beta] Use new menu and workflow management", name: "[Beta] Use new menu and workflow management. Note: On small screens the menu will always be at the top.",
type: "combo", type: "combo",
options: ["Disabled", "Top", "Bottom"], options: ["Disabled", "Top", "Bottom"],
onChange: async (v) => { onChange: async (v) => {
if (v) { if (v && v !== "Disabled") {
document.body.style.display = "grid"; if (!resizeHandler) {
app.ui.menuContainer.style.display = "none"; resizeHandler = () => {
this.element.style.removeProperty("display"); this.calculateSizeBreak();
if (v === "Bottom") { };
app.bodyBottom.append(this.element); window.addEventListener("resize", resizeHandler);
} else {
app.bodyTop.prepend(this.element);
} }
this.calculateSizeBreak(); this.updatePosition(v);
} else { } else {
if (resizeHandler) {
window.removeEventListener("resize", resizeHandler);
resizeHandler = null;
}
document.body.style.removeProperty("display"); document.body.style.removeProperty("display");
app.ui.menuContainer.style.removeProperty("display"); app.ui.menuContainer.style.removeProperty("display");
this.element.style.display = "none"; this.element.style.display = "none";
app.ui.restoreMenuPosition();
} }
window.dispatchEvent(new Event("resize")); window.dispatchEvent(new Event("resize"));
}, },
}); });
window.addEventListener("resize", () => {
this.calculateSizeBreak();
});
} }
#sizeBreak = "lg"; updatePosition(v) {
#lastSizeBreaks = { document.body.style.display = "grid";
lg: null, this.app.ui.menuContainer.style.display = "none";
md: null, this.element.style.removeProperty("display");
sm: null, this.position = v;
xs: null, if (v === "Bottom") {
}; this.app.bodyBottom.append(this.element);
#sizeBreaks = Object.keys(this.#lastSizeBreaks); } else {
#cachedInnerSize = null; this.app.bodyTop.prepend(this.element);
#cacheTimeout = null; }
this.calculateSizeBreak();
}
updateSizeBreak(idx, prevIdx, direction) { updateSizeBreak(idx, prevIdx, direction) {
const newSize = this.#sizeBreaks[idx]; const newSize = this.#sizeBreaks[idx];
@ -197,7 +210,17 @@ export class ComfyAppMenu {
} }
} }
// Allow multiple updates, but prevent bouncing if (idx) {
// We're on a small screen, force the menu at the top
if (this.position !== "Top") {
this.updatePosition("Top");
}
} else if (this.position != this.menuPositionSetting.value) {
// Restore user position
this.updatePosition(this.menuPositionSetting.value);
}
// Allow multiple updates, but prevent bouncing
if (!direction) { if (!direction) {
direction = prevIdx - idx; direction = prevIdx - idx;
} else if (direction != prevIdx - idx) { } else if (direction != prevIdx - idx) {
@ -266,14 +289,14 @@ export class ComfyAppMenu {
* @param { "workflow" | "output" } [promptProperty] * @param { "workflow" | "output" } [promptProperty]
*/ */
async exportWorkflow(filename, promptProperty) { async exportWorkflow(filename, promptProperty) {
if(this.app.workflowManager.activeWorkflow?.path) { if (this.app.workflowManager.activeWorkflow?.path) {
filename = this.app.workflowManager.activeWorkflow.name; filename = this.app.workflowManager.activeWorkflow.name;
} }
const p = await this.app.graphToPrompt(); const p = await this.app.graphToPrompt();
const json = JSON.stringify(p[promptProperty], null, 2); const json = JSON.stringify(p[promptProperty], null, 2);
const blob = new Blob([json], { type: "application/json" }); const blob = new Blob([json], { type: "application/json" });
const file = this.getFilename(filename); const file = this.getFilename(filename);
if(!file) return; if (!file) return;
downloadBlob(file, blob); downloadBlob(file, blob);
} }
} }

View File

@ -11,9 +11,10 @@ export class ComfyQueueButton {
element = $el("div.comfyui-queue-button"); element = $el("div.comfyui-queue-button");
#internalQueueSize = 0; #internalQueueSize = 0;
queuePrompt = async () => { queuePrompt = async (e) => {
this.#internalQueueSize += this.queueOptions.batchCount; this.#internalQueueSize += this.queueOptions.batchCount;
await this.app.queuePrompt(-1, this.queueOptions.batchCount); // Hold shift to queue front
await this.app.queuePrompt(-e.shiftKey, this.queueOptions.batchCount);
}; };
constructor(app) { constructor(app) {