File size: 1,805 Bytes
c225a63 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import { app } from '../../scripts/app.js';
import { ComfyWidgets } from '../../scripts/widgets.js';
app.registerExtension({
name: 'Comfy.INSTARAW.APIModelSelector',
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === 'INSTARAW_API_ModelSelector') {
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
onNodeCreated?.apply(this, arguments);
// Create the warning widget for this node
const warningWidget = ComfyWidgets["STRING"](this, "unreliable_provider_warning", ["STRING", { multiline: true }], app).widget;
warningWidget.inputEl.readOnly = true;
warningWidget.inputEl.style.backgroundColor = '#442222';
warningWidget.inputEl.style.color = '#FFCCCC';
warningWidget.inputEl.style.opacity = '0.8';
warningWidget.value = '⚠️ For this model, the fal.ai provider is unreliable for Image-to-Image (Edit) tasks. wavespeed.ai recommended.';
warningWidget.hidden = true; // Initially hidden
const modelWidget = this.widgets.find((w) => w.name === 'model');
if (modelWidget) {
const originalCallback = modelWidget.callback;
// Add our logic to the dropdown's callback
modelWidget.callback = (value) => {
originalCallback?.(value);
this.updateWarningWidget();
};
}
// Add a function to the node to update the widget
this.updateWarningWidget = () => {
const isProblematic = (modelWidget.value === 'Nano Banana');
warningWidget.hidden = !isProblematic;
this.computeSize();
this.setDirtyCanvas(true, true);
};
// Run once on creation to set the initial state
setTimeout(() => this.updateWarningWidget(), 1);
};
}
},
}); |