45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
import { app } from "../../../scripts/app.js";
|
|
import { ComfyWidgets } from "../../../scripts/widgets.js";
|
|
|
|
app.registerExtension({
|
|
name: "Comfy.FastPreviewImage",
|
|
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
|
if (nodeData.name === "FastPreviewImage") {
|
|
const onExecuted = nodeType.prototype.onExecuted;
|
|
|
|
nodeType.prototype.onExecuted = function(message) {
|
|
const r = onExecuted ? onExecuted.apply(this, arguments) : undefined;
|
|
|
|
if (message?.file_sizes) {
|
|
let widget = this.widgets?.find((w) => w.name === "file_size_display");
|
|
|
|
if (!widget) {
|
|
const widgetObj = ComfyWidgets["STRING"](this, "file_size_display", ["STRING", { multiline: false }], app);
|
|
widget = widgetObj.widget || widgetObj;
|
|
|
|
if (widget && widget.inputEl) {
|
|
widget.inputEl.readOnly = true;
|
|
widget.inputEl.style.opacity = "0.8";
|
|
widget.inputEl.style.textAlign = "center";
|
|
}
|
|
|
|
// Force resize to fit new widget
|
|
if (this.computeSize) {
|
|
this.setSize(this.computeSize());
|
|
}
|
|
}
|
|
|
|
if (widget) {
|
|
widget.value = `Size: ${message.file_sizes.join(" | ")}`;
|
|
if (widget.inputEl) {
|
|
widget.inputEl.value = widget.value;
|
|
}
|
|
}
|
|
}
|
|
|
|
return r;
|
|
};
|
|
}
|
|
}
|
|
});
|