Merge branch 'comfyanonymous:master' into cleanup_if_idle

This commit is contained in:
Liu Sida 2024-04-19 09:33:27 +08:00 committed by GitHub
commit 97c3f2b681
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 14 deletions

View File

@ -204,7 +204,7 @@ export class EzWidget {
convertToWidget() { convertToWidget() {
if (!this.isConvertedToInput) if (!this.isConvertedToInput)
throw new Error(`Widget ${this.widget.name} cannot be converted as it is already a widget.`); throw new Error(`Widget ${this.widget.name} cannot be converted as it is already a widget.`);
var menu = this.node.menu["Convert 🔘 to widget.."].item.submenu.options; var menu = this.node.menu["Convert Input to Widget"].item.submenu.options;
var index = menu.findIndex(a => a.content == `Convert ${this.widget.name} to widget`); var index = menu.findIndex(a => a.content == `Convert ${this.widget.name} to widget`);
menu[index].callback.call(); menu[index].callback.call();
} }
@ -212,7 +212,7 @@ export class EzWidget {
convertToInput() { convertToInput() {
if (this.isConvertedToInput) if (this.isConvertedToInput)
throw new Error(`Widget ${this.widget.name} cannot be converted as it is already an input.`); throw new Error(`Widget ${this.widget.name} cannot be converted as it is already an input.`);
var menu = this.node.menu["Convert input to 🔘.."].item.submenu.options; var menu = this.node.menu["Convert Widget to Input"].item.submenu.options;
var index = menu.findIndex(a => a.content == `Convert ${this.widget.name} to input`); var index = menu.findIndex(a => a.content == `Convert ${this.widget.name} to input`);
menu[index].callback.call(); menu[index].callback.call();
} }

View File

@ -256,8 +256,18 @@ export function mergeIfValid(output, config2, forceUpdate, recreateWidget, confi
return { customConfig }; return { customConfig };
} }
let useConversionSubmenusSetting;
app.registerExtension({ app.registerExtension({
name: "Comfy.WidgetInputs", name: "Comfy.WidgetInputs",
init() {
useConversionSubmenusSetting = app.ui.settings.addSetting({
id: "Comfy.NodeInputConversionSubmenus",
name: "Node widget/input conversion sub-menus",
tooltip: "In the node context menu, place the entries that convert between input/widget in sub-menus.",
type: "boolean",
defaultValue: true,
});
},
async beforeRegisterNodeDef(nodeType, nodeData, app) { async beforeRegisterNodeDef(nodeType, nodeData, app) {
// Add menu options to conver to/from widgets // Add menu options to conver to/from widgets
const origGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions; const origGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions;
@ -295,20 +305,28 @@ app.registerExtension({
//Convert.. main menu //Convert.. main menu
if (toInput.length) { if (toInput.length) {
if (useConversionSubmenusSetting.value) {
options.push({ options.push({
content: `Convert input to 🔘..`, content: "Convert Widget to Input",
submenu: { submenu: {
options: toInput, options: toInput,
}, },
}); });
} else {
options.push(...toInput, null);
}
} }
if (toWidget.length) { if (toWidget.length) {
if (useConversionSubmenusSetting.value) {
options.push({ options.push({
content: `Convert 🔘 to widget..`, content: "Convert Input to Widget",
submenu: { submenu: {
options: toWidget, options: toWidget,
}, },
}); });
} else {
options.push(...toWidget, null);
}
} }
} }