From 5a2adda58007f153a32b57bebeac1d2b2def2e3d Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Tue, 22 Apr 2025 02:06:08 +0900 Subject: [PATCH] fixed: impact switch - compatibility patch with new front https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/964 --- js/common.js | 42 ++++++++++++++++++++++++++++++++++++++++ js/impact-pack.js | 29 ++++++++++++++------------- modules/impact/config.py | 2 +- pyproject.toml | 2 +- 4 files changed, 60 insertions(+), 15 deletions(-) diff --git a/js/common.js b/js/common.js index b60f6c3..561917d 100644 --- a/js/common.js +++ b/js/common.js @@ -3,6 +3,48 @@ import { app } from "../../scripts/app.js"; let original_show = app.ui.dialog.show; +export function customAlert(message) { + try { + app.extensionManager.toast.addAlert(message); + } + catch { + alert(message); + } +} + +export function isBeforeFrontendVersion(compareVersion) { + 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; + } +} + function dialog_show_wrapper(html) { if (typeof html === "string") { if(html.includes("IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE")) { diff --git a/js/impact-pack.js b/js/impact-pack.js index f71b3be..7585b6b 100644 --- a/js/impact-pack.js +++ b/js/impact-pack.js @@ -1,6 +1,13 @@ import { ComfyApp, app } from "../../scripts/app.js"; import { ComfyDialog, $el } from "../../scripts/ui.js"; import { api } from "../../scripts/api.js"; +import { customAlert, isBeforeFrontendVersion } from "./common.js"; + +const is_legacy_front = () => isBeforeFrontendVersion('1.16.9'); + +if(is_legacy_front()) { + customAlert("An outdated version(<1.16.9) of the `comfyui-frontend-package` is installed. It is not compatible with the current version of the Impact Pack."); +} let wildcards_list = []; async function load_wildcards() { @@ -474,6 +481,11 @@ app.registerExtension({ const onConnectionsChange = nodeType.prototype.onConnectionsChange; nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) { + const stackTrace = new Error().stack; + if(stackTrace.includes('LGraph.configure')) { + return; + } + if(!link_info) return; @@ -516,7 +528,7 @@ app.registerExtension({ if(this.inputs[0].type == '*'){ const node = app.graph.getNodeById(link_info.origin_id); let origin_type = node.outputs[link_info.origin_slot]?.type; - if(link_info.target_slot == 0 && this.inputs.length > 1) { + if(link_info.target_slot == 0 && this.inputs.length > 3) { // NOTE: widgets are regarded as input since new front origin_type = this.inputs[1].type; node.connect(link_info.origin_slot, node.id, 'input1'); } @@ -541,13 +553,7 @@ app.registerExtension({ let select_slot = this.inputs.find(x => x.name == "select"); let mode_slot = this.inputs.find(x => x.name == "sel_mode"); - let converted_count = 0; - converted_count += select_slot?1:0; - converted_count += mode_slot?1:0; - - if (!connected && (this.inputs.length > 1+converted_count)) { - const stackTrace = new Error().stack; - + if (!connected && (this.inputs.length > 3)) { if( !stackTrace.includes('LGraphNode.prototype.connect') && // for touch device !stackTrace.includes('LGraphNode.connect') && // for mouse device @@ -557,6 +563,7 @@ app.registerExtension({ } } + let slot_i = 1; for (let i = 0; i < this.inputs.length; i++) { let input_i = this.inputs[i]; @@ -567,11 +574,7 @@ app.registerExtension({ } let last_slot = this.inputs[this.inputs.length - 1]; - if ( - (last_slot.name == 'select' && last_slot.name != 'sel_mode' && this.inputs[this.inputs.length - 2].link != undefined) - || (last_slot.name != 'select' && last_slot.name != 'sel_mode' && last_slot.link != undefined)) { - this.addInput(`${input_name}${slot_i}`, this.outputs[0].type); - } + this.addInput(`${input_name}${slot_i}`, this.outputs[0].type); if(this.widgets?.length) { this.widgets[0].options.max = select_slot?this.inputs.length-1:this.inputs.length; diff --git a/modules/impact/config.py b/modules/impact/config.py index f7efb5d..9d232fe 100644 --- a/modules/impact/config.py +++ b/modules/impact/config.py @@ -1,7 +1,7 @@ import configparser import os -version_code = [8, 11, 1] +version_code = [8, 12] version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') dependency_version = 24 diff --git a/pyproject.toml b/pyproject.toml index a5dce1d..fc9d4e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-impact-pack" description = "This node pack offers various detector nodes and detailer nodes that allow you to configure a workflow that automatically enhances facial details. And provide iterative upscaler." -version = "8.11.1" +version = "8.12" license = { file = "LICENSE.txt" } dependencies = ["segment-anything", "scikit-image", "piexif", "transformers", "opencv-python-headless", "GitPython", "scipy>=1.11.4"]