Use new frontend ComfyButton API for menu button
Adds button via app.menu.settingsGroup using ComfyButton with bar-chart-2 icon. Falls back to legacy .comfy-menu DOM for older ComfyUI versions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,28 +4,34 @@ app.registerExtension({
|
|||||||
name: "comfyui.nodes_stats",
|
name: "comfyui.nodes_stats",
|
||||||
|
|
||||||
async setup() {
|
async setup() {
|
||||||
|
try {
|
||||||
|
const { ComfyButton } = await import(
|
||||||
|
"../../scripts/ui/components/button.js"
|
||||||
|
);
|
||||||
|
|
||||||
|
const btn = new ComfyButton({
|
||||||
|
icon: "bar-chart-2",
|
||||||
|
content: "Node Stats",
|
||||||
|
tooltip: "Show node and package usage statistics",
|
||||||
|
action: () => showStatsDialog(),
|
||||||
|
classList: "comfyui-button comfyui-menu-mobile-collapse",
|
||||||
|
});
|
||||||
|
|
||||||
|
app.menu?.settingsGroup.element.before(btn.element);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(
|
||||||
|
"[nodes-stats] New menu API unavailable, falling back to legacy menu",
|
||||||
|
e
|
||||||
|
);
|
||||||
|
|
||||||
const btn = document.createElement("button");
|
const btn = document.createElement("button");
|
||||||
btn.textContent = "Node Stats";
|
btn.textContent = "Node Stats";
|
||||||
btn.style.cssText =
|
btn.onclick = () => showStatsDialog();
|
||||||
"font-size:14px;padding:4px 12px;cursor:pointer;border:none;border-radius:4px;background:#333;color:#fff;";
|
|
||||||
btn.addEventListener("click", () => showStatsDialog());
|
|
||||||
|
|
||||||
// Insert into ComfyUI menu bar
|
const menu = document.querySelector(".comfy-menu");
|
||||||
const menu = document.querySelector(".comfy-menu .comfy-menu-btns") ||
|
|
||||||
document.querySelector(".comfy-menu");
|
|
||||||
if (menu) {
|
if (menu) {
|
||||||
menu.appendChild(btn);
|
menu.append(btn);
|
||||||
} else {
|
|
||||||
// Fallback: wait for menu to appear
|
|
||||||
const observer = new MutationObserver(() => {
|
|
||||||
const m = document.querySelector(".comfy-menu .comfy-menu-btns") ||
|
|
||||||
document.querySelector(".comfy-menu");
|
|
||||||
if (m) {
|
|
||||||
m.appendChild(btn);
|
|
||||||
observer.disconnect();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
observer.observe(document.body, { childList: true, subtree: true });
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user