diff --git a/__init__.py b/__init__.py index 1d18491..b324ff1 100644 --- a/__init__.py +++ b/__init__.py @@ -10,7 +10,7 @@ from .list_utility_nodes import PickFromList, BatchFromImageList, ImageListFromB from .string_utility_nodes import SplitByCommas, StringToFloat, StringToInt, AnyListToString from .mask_utility_nodes import MaskedSection -VERSION = "1.6.5" +VERSION = "1.7" WEB_DIRECTORY = "./js" NODE_CLASS_MAPPINGS= { diff --git a/js/image_filter.js b/js/image_filter.js index 4b62a42..7e7ef16 100644 --- a/js/image_filter.js +++ b/js/image_filter.js @@ -4,7 +4,7 @@ import { api } from "../../scripts/api.js"; import { create } from "./utils.js"; import { popup } from "./popup.js"; import { ComfyWidgets } from "../../scripts/widgets.js"; -import { FloatingWindow } from "./floating_window.js"; +import { unique_to_tab } from "./weak_map.js"; const FILTER_TYPES = ["Image Filter","Text Image Filter","Text Image Filter with Extras","Mask Image Filter"] @@ -13,7 +13,7 @@ app.registerExtension({ settings: [ { id: "Image Filter. Image Filter", - name: "Version 1.6.5", + name: "Version 1.7", type: () => { const x = document.createElement('span') const a = document.createElement('a') @@ -109,16 +109,30 @@ app.registerExtension({ nodeType.prototype.onNodeCreated = function () { this._ni_widget = this.widgets.find((n)=>n.name=='node_identifier') if (!(this._ni_widget)) { - this._ni_widget = ComfyWidgets["INT"](this, "node_identifier", ["INT", { "default":0 }], app).widget + this._ni_widget = ComfyWidgets["STRING"](this, "node_identifier", ["STRING", { "default":"" }], app).widget } this._ni_widget.hidden = true this._ni_widget.computeSize = () => [0,0] - this._ni_widget.value = Math.floor(Math.random() * 1000000) + + return onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined; } } }, + afterConfigureGraph() { + setTimeout( ()=> { + const checked = document.getElementsByClassName('p-togglebutton-checked')[0] + app.graph.nodes.forEach( (node)=> { + const unique_id_widget = node.widgets?.find((n)=>n.name=='node_identifier') + if (unique_id_widget) { + unique_id_widget.value = `${node.graph.id}:${node.id}` + unique_to_tab.set(unique_id_widget.value, checked ) + } + }) + }, 1000) + } + }) \ No newline at end of file diff --git a/js/popup.js b/js/popup.js index 29eb42a..d307caa 100644 --- a/js/popup.js +++ b/js/popup.js @@ -5,6 +5,7 @@ import { mask_editor_listen_for_cancel, mask_editor_showing, hide_mask_editor, p import { Log } from "./log.js"; import { create } from "./utils.js"; import { FloatingWindow } from "./floating_window.js"; +import { unique_to_tab } from "./weak_map.js"; //const EXTENSION_NODES = ["Image Filter", "Text Image Filter", "Mask Image Filter", "Text Image Filter with Extras",] const POPUP_NODES = ["Image Filter", "Text Image Filter", "Text Image Filter with Extras",] @@ -272,9 +273,18 @@ class Popup extends HTMLElement { const the_node = this.find_node(uid) if (this.node!=the_node) this.on_new_node(the_node) + const tab = unique_to_tab.get(message.detail.unique) - if (!this.node) return console.log(`Message was for ${uid} which doesn't exist`) - if (this.node._ni_widget?.value != message.detail.unique) return console.log(`Message unique id wasn't mine`) + if (!this.node || this.node._ni_widget?.value != message.detail.unique) { + if (tab) { + if (!tab.innerHTML.endsWith('! ')) tab.innerHTML += '! ' + } + return console.log(`Message unique id wasn't mine`) + } else { + if (tab) { + if (tab.innerHTML.endsWith('! ')) tab.innerHTML = tab.innerHTML.substring(0, tab.innerHTML.length-7) + } + } if (detail.tick) { this.counter_text.innerText = `${detail.tick}s` diff --git a/js/weak_map.js b/js/weak_map.js new file mode 100644 index 0000000..7b585c9 --- /dev/null +++ b/js/weak_map.js @@ -0,0 +1,16 @@ + +class WeakMap { + constructor() { + this.map = {} + } + + set(key, value) { + this.map[key] = new WeakRef(value) + } + + get(key) { + return this.map[key]?.deref() + } +} + +export const unique_to_tab = new WeakMap() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 9f3d605..6c03157 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "cg-image-filter" description = "A set of custom nodes that pause a workflow while you select images, add masks, or edit text." -version = "1.6.5" +version = "1.7" license = { file = "LICENSE" } [project.urls]