From 8b2048e5c343a7a74be78d9837df9cfe5a1ed080 Mon Sep 17 00:00:00 2001 From: thecooltechguy Date: Thu, 26 Oct 2023 14:37:47 -0700 Subject: [PATCH] Added dropdown under workflow gallery button for sharing, added a comfyui setting for showing/hiding share button in the main menu --- js/comfyui-manager.js | 98 ++++++++++++++++++++++++++++++++++++++++++- js/comfyui-share.js | 20 ++++----- 2 files changed, 106 insertions(+), 12 deletions(-) diff --git a/js/comfyui-manager.js b/js/comfyui-manager.js index d37bd771..bac6b4c6 100644 --- a/js/comfyui-manager.js +++ b/js/comfyui-manager.js @@ -9,6 +9,39 @@ var fetch_updates_button = null; var update_all_button = null; var badge_mode = "none"; +// copied style from https://github.com/pythongosssss/ComfyUI-Custom-Scripts +const style = ` +#comfyworkflows-button { + position: relative; + overflow: hidden; + } +.pysssss-workflow-arrow-2 { + position: absolute; + top: 0; + bottom: 0; + right: 0; + font-size: 12px; + display: flex; + align-items: center; + width: 24px; + justify-content: center; + background: rgba(255,255,255,0.1); + content: "▼"; +} +.pysssss-workflow-arrow-2:after { + content: "▼"; + } + .pysssss-workflow-arrow-2:hover { + filter: brightness(1.6); + background-color: var(--comfy-menu-bg); + } +.pysssss-workflow-popup-2 ~ .litecontextmenu { + transform: scale(1.3); +} +`; + + + async function init_badge_mode() { api.fetchApi('/manager/badge_mode') .then(response => response.text()) @@ -1940,10 +1973,49 @@ class ManagerMenuDialog extends ComfyDialog { onclick: () => { window.open("https://blenderneko.github.io/ComfyUI-docs/", "comfyui-community-manual"); } }), $el("button", { + id: 'comfyworkflows-button', type: "button", textContent: "ComfyUI Workflow Gallery", onclick: () => { window.open("https://comfyworkflows.com/", "comfyui-workflow-gallery"); } - }), + }, [ + $el("div.pysssss-workflow-arrow-2", { + id: `comfyworkflows-button-arrow`, + // parent: document.getElementById(`comfyworkflows-button`), + onclick: (e) => { + e.preventDefault(); + e.stopPropagation(); + + LiteGraph.closeAllContextMenus(); + const menu = new LiteGraph.ContextMenu( + [ + { + title: "Share your art", + callback: () => { + this.close(); + if (!ShareDialog.instance) { + ShareDialog.instance = new ShareDialog(); + } + ShareDialog.instance.show(); + }, + }, + { + title: "Close", + callback: () => { + this.close(); + }, + } + ], + { + event: e, + scale: 1.3, + }, + window + ); + menu.root.classList.add("pysssss-workflow-popup-2"); + menu.root.classList.add(`pysssss-workflow-comfyworkflows-button`); + }, + }) + ]), $el("button", { type: "button", @@ -1989,7 +2061,12 @@ class ManagerMenuDialog extends ComfyDialog { app.registerExtension({ name: "Comfy.ManagerMenu", - + init() { + $el("style", { + textContent: style, + parent: document.head, + }); + }, async setup() { const menu = document.querySelector(".comfy-menu"); const separator = document.createElement("hr"); @@ -2019,6 +2096,23 @@ app.registerExtension({ // make the background color a gradient of blue to green shareButton.style.background = "linear-gradient(90deg, #00C9FF 0%, #92FE9D 100%)"; shareButton.style.color = "black"; + + app.ui.settings.addSetting({ + id: "ComfyUIManager.ShowShareButtonInMainMenu", + name: "Show 'Share' button in the main menu", + type: "boolean", + defaultValue: true, + onChange: (value) => { + if (value) { + // show the button + shareButton.style.display = "inline-block"; + } else { + // hide the button + shareButton.style.display = "none"; + } + } + }); + menu.append(shareButton); }, diff --git a/js/comfyui-share.js b/js/comfyui-share.js index 81892891..f060ecac 100644 --- a/js/comfyui-share.js +++ b/js/comfyui-share.js @@ -9,16 +9,16 @@ export class ShareDialog extends ComfyDialog { constructor() { super(); - - this.element = $el("div.comfy-modal", { parent: document.body }, - [$el("div.comfy-modal-content", - { - style: { - overflowY: "auto", - } - }, - [...this.createButtons()]), - ]); + + this.element = $el("div.comfy-modal", { parent: document.body }, + [$el("div.comfy-modal-content", + { + style: { + overflowY: "auto", + } + }, + [...this.createButtons()]), + ]); } createButtons() {