Skip to content

Commit

Permalink
use core badge feature if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ltdrdata committed Sep 18, 2024
1 parent 0e4b47c commit 3701246
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 34 deletions.
2 changes: 1 addition & 1 deletion glob/manager_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import cm_global
from manager_util import *

version = [2, 50, 3]
version = [2, 51]
version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '')


Expand Down
105 changes: 73 additions & 32 deletions js/comfyui-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,40 @@ docStyle.innerHTML = `
}
`;

function is_legacy_front() {
let compareVersion = '1.2.49';
try {
const frontendVersion = window['__COMFYUI_FRONTEND_VERSION__'];
if (typeof frontendVersion !== 'string') {
return false;
}

function parseVersion(versionString) {
const parts = versionString.split('.').map(Number);
return parts.length === 3 && parts.every(part => !isNaN(part)) ? parts : null;
}

const currentVersion = parseVersion(frontendVersion);
const comparisonVersion = parseVersion(compareVersion);

if (!currentVersion || !comparisonVersion) {
return false;
}

for (let i = 0; i < 3; i++) {
if (currentVersion[i] > comparisonVersion[i]) {
return false;
} else if (currentVersion[i] < comparisonVersion[i]) {
return true;
}
}

return false;
} catch {
return true;
}
}

document.head.appendChild(docStyle);

var update_comfyui_button = null;
Expand Down Expand Up @@ -842,24 +876,27 @@ class ManagerMenuDialog extends ComfyDialog {
});

// nickname
let badge_combo = document.createElement("select");
badge_combo.setAttribute("title", "Configure the content to be displayed on the badge at the top right corner of the node. The ID is the identifier of the node. If 'hide built-in' is selected, both unknown nodes and built-in nodes will be omitted, making them indistinguishable");
badge_combo.className = "cm-menu-combo";
badge_combo.appendChild($el('option', { value: 'none', text: 'Badge: None' }, []));
badge_combo.appendChild($el('option', { value: 'nick', text: 'Badge: Nickname' }, []));
badge_combo.appendChild($el('option', { value: 'nick_hide', text: 'Badge: Nickname (hide built-in)' }, []));
badge_combo.appendChild($el('option', { value: 'id_nick', text: 'Badge: #ID Nickname' }, []));
badge_combo.appendChild($el('option', { value: 'id_nick_hide', text: 'Badge: #ID Nickname (hide built-in)' }, []));

api.fetchApi('/manager/badge_mode')
.then(response => response.text())
.then(data => { badge_combo.value = data; badge_mode = data; });

badge_combo.addEventListener('change', function (event) {
api.fetchApi(`/manager/badge_mode?value=${event.target.value}`);
badge_mode = event.target.value;
app.graph.setDirtyCanvas(true);
});
let badge_combo = "";
if(is_legacy_front()) {
badge_combo = document.createElement("select");
badge_combo.setAttribute("title", "Configure the content to be displayed on the badge at the top right corner of the node. The ID is the identifier of the node. If 'hide built-in' is selected, both unknown nodes and built-in nodes will be omitted, making them indistinguishable");
badge_combo.className = "cm-menu-combo";
badge_combo.appendChild($el('option', { value: 'none', text: 'Badge: None' }, []));
badge_combo.appendChild($el('option', { value: 'nick', text: 'Badge: Nickname' }, []));
badge_combo.appendChild($el('option', { value: 'nick_hide', text: 'Badge: Nickname (hide built-in)' }, []));
badge_combo.appendChild($el('option', { value: 'id_nick', text: 'Badge: #ID Nickname' }, []));
badge_combo.appendChild($el('option', { value: 'id_nick_hide', text: 'Badge: #ID Nickname (hide built-in)' }, []));

api.fetchApi('/manager/badge_mode')
.then(response => response.text())
.then(data => { badge_combo.value = data; badge_mode = data; });

badge_combo.addEventListener('change', function (event) {
api.fetchApi(`/manager/badge_mode?value=${event.target.value}`);
badge_mode = event.target.value;
app.graph.setDirtyCanvas(true);
});
}

// channel
let channel_combo = document.createElement("select");
Expand Down Expand Up @@ -1411,24 +1448,28 @@ app.registerExtension({
},

async nodeCreated(node, app) {
if(!node.badge_enabled) {
node.getNickname = function () { return getNickname(node, node.comfyClass.trim()) };
let orig = node.onDrawForeground;
if(!orig)
orig = node.__proto__.onDrawForeground;

node.onDrawForeground = function (ctx) {
drawBadge(node, orig, arguments)
};
node.badge_enabled = true;
if(is_legacy_front()) {
if(!node.badge_enabled) {
node.getNickname = function () { return getNickname(node, node.comfyClass.trim()) };
let orig = node.onDrawForeground;
if(!orig)
orig = node.__proto__.onDrawForeground;

node.onDrawForeground = function (ctx) {
drawBadge(node, orig, arguments)
};
node.badge_enabled = true;
}
}
},

async loadedGraphNode(node, app) {
if(!node.badge_enabled) {
const orig = node.onDrawForeground;
node.getNickname = function () { return getNickname(node, node.type.trim()) };
node.onDrawForeground = function (ctx) { drawBadge(node, orig, arguments) };
if(is_legacy_front()) {
if(!node.badge_enabled) {
const orig = node.onDrawForeground;
node.getNickname = function () { return getNickname(node, node.type.trim()) };
node.onDrawForeground = function (ctx) { drawBadge(node, orig, arguments) };
}
}
},

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui-manager"
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
version = "2.50.3"
version = "2.51"
license = { file = "LICENSE.txt" }
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]

Expand Down

0 comments on commit 3701246

Please sign in to comment.