diff --git a/__dev__.py b/__dev__.py index c07d27d..0be0657 100644 --- a/__dev__.py +++ b/__dev__.py @@ -2,17 +2,26 @@ import subprocess import os import shutil import glob +import json THIS_DIR=os.path.dirname(os.path.abspath(__file__)) DIR_DEV=os.path.abspath(f'{THIS_DIR}/web') DIR_WEB=os.path.abspath(f'{THIS_DIR}/../../web/extensions/rgthree-comfy') -js_files = glob.glob(os.path.join(THIS_DIR, '*.js')) +js_files = glob.glob(os.path.join(THIS_DIR, 'web/**/*.js')) for file in js_files: os.remove(file) subprocess.run(["./node_modules/typescript/bin/tsc"]) + if os.path.exists(DIR_WEB): shutil.rmtree(DIR_WEB) -shutil.copytree(DIR_DEV, DIR_WEB, dirs_exist_ok=True) \ No newline at end of file +shutil.copytree(DIR_DEV, DIR_WEB, dirs_exist_ok=True) + +CONFIG_FILE = os.path.join(THIS_DIR, 'rgthree_config.json') +with open(CONFIG_FILE, 'r', encoding = 'UTF-8') as file: + rgthree_config = json.load(file) + +with open(os.path.join(DIR_WEB, 'rgthree_config.js'), 'w', encoding = 'UTF-8') as file: + file.write('export const rgthreeConfig = ' + json.dumps(rgthree_config)) diff --git a/__init__.py b/__init__.py index 4810a30..ed1b35a 100644 --- a/__init__.py +++ b/__init__.py @@ -6,7 +6,7 @@ """ import glob -import inspect +import json import os import shutil @@ -66,6 +66,17 @@ os.makedirs(DIR_WEB) shutil.copytree(DIR_DEV_WEB, DIR_WEB, dirs_exist_ok=True) + +CONFIG_FILE = os.path.join(THIS_DIR, 'rgthree_config.json') +with open(CONFIG_FILE, 'r', encoding = 'UTF-8') as file: + rgthree_config = json.load(file) + +with open(os.path.join(DIR_WEB, 'rgthree_config.js'), 'w', encoding = 'UTF-8') as file: + file.write('export const rgthreeConfig = ' + json.dumps(rgthree_config)) + +# shutil.copy(os.path.join(THIS_DIR, 'rgthree_config.json'), os.path.join(DIR_WEB, 'rgthree_config.js')) + + NOT_NODES = ['constants', 'log', 'utils', 'rgthree'] __all__ = ['NODE_CLASS_MAPPINGS'] diff --git a/rgthree_config.json.default b/rgthree_config.json.default index b82bc5f..e630f42 100644 --- a/rgthree_config.json.default +++ b/rgthree_config.json.default @@ -1,4 +1,5 @@ { - "patch_recursive_execution": true + "patch_recursive_execution": true, + "monitor_bad_links": false } diff --git a/ts/link_fixer.ts b/ts/link_fixer.ts index 278d9e0..e15806b 100644 --- a/ts/link_fixer.ts +++ b/ts/link_fixer.ts @@ -376,9 +376,10 @@ export function fixBadLinks( } stale link removals.`, ); - // Let's run it again and check. + let hasBadLinks: boolean = !!(data.patchedNodes.length || data.deletedLinks.length); - if (!silent) { + // If we're fixing, then let's run it again to see if there are no more bad links. + if (fix && !silent) { const rerun = fixBadLinks(graph, false, true); hasBadLinks = rerun.hasBadLinks; } diff --git a/ts/rgthree.ts b/ts/rgthree.ts index ff761f4..2632e35 100644 --- a/ts/rgthree.ts +++ b/ts/rgthree.ts @@ -1,6 +1,8 @@ import type { LGraphNode, SerializedLGraphNode, serializedLGraph } from "litegraph.js"; // @ts-ignore import { app } from "../../scripts/app.js"; +// @ts-ignore +import {rgthreeConfig} from "./rgthree_config.js"; import { fixBadLinks } from "./link_fixer.js"; export enum LogLevel { @@ -86,6 +88,7 @@ class Rgthree { logger = new LogSession("[rgthree]"); monitorBadLinksAlerted = false; + monitorLinkTimeout: number|null = null; constructor() { window.addEventListener("keydown", (e) => { @@ -111,6 +114,10 @@ class Rgthree { }; const loadGraphData = app.loadGraphData; app.loadGraphData = function(graph: serializedLGraph) { + if (this.monitorLinkTimeout) { + clearTimeout(this.monitorLinkTimeout); + this.monitorLinkTimeout = null; + } document.querySelector('.rgthree-bad-links-alerts-container')?.remove(); // Try to make a copy to use, because ComfyUI's loadGraphData will modify it. let graphCopy: serializedLGraph|null; @@ -175,6 +182,11 @@ class Rgthree { alert('Success! It\'s possible some valid links may have been affected. Please check and verify your workflow.'); wasLoadingAborted && app.loadGraphData(fixBadLinksResult.graph); container.remove(); + if (rgthreeConfig['monitor_bad_links']) { + that.monitorLinkTimeout = setTimeout(() => { + that.monitorBadLinks(); + }, 5000); + } } } @@ -184,11 +196,15 @@ class Rgthree { const container = document.querySelector('.rgthree-bad-links-alerts') as HTMLElement; container && (container.style.transform = 'translateY(0%)'); }, 500); - + } else if (rgthreeConfig['monitor_bad_links']) { + that.monitorLinkTimeout = setTimeout(() => { + that.monitorBadLinks(); + }, 5000); } }, 100); loadGraphData && loadGraphData.call(app, ...arguments); } + } setLogLevel(level: LogLevel) { @@ -204,17 +220,17 @@ class Rgthree { } monitorBadLinks() { - this.logger.debug('Starting a monitor for bad links.'); - setInterval(() => { - const badLinksFound = fixBadLinks(app.graph); - // if (badLinksFound && !this.monitorBadLinksAlerted) { - // this.monitorBadLinksAlerted = true; - // alert(`Problematic links just found in data. Can you file a bug with what you've just done at https://github.com/rgthree/rgthree-comfy/issues. Thank you!`) - // } else if (!badLinksFound) { - // // Clear the alert once fixed so we can alert again. - // this.monitorBadLinksAlerted = false; - // } - }, 1000); + const badLinksFound = fixBadLinks(app.graph); + if (badLinksFound.hasBadLinks && !this.monitorBadLinksAlerted) { + this.monitorBadLinksAlerted = true; + alert(`Problematic links just found in live data. Can you save your workflow and file a bug with the last few steps you took to trigger this at https://github.com/rgthree/rgthree-comfy/issues. Thank you!`) + } else if (!badLinksFound.hasBadLinks) { + // Clear the alert once fixed so we can alert again. + this.monitorBadLinksAlerted = false; + } + this.monitorLinkTimeout = setTimeout(() => { + this.monitorBadLinks(); + }, 5000); } } diff --git a/web/link_fixer.js b/web/link_fixer.js index fb6ace2..6c61fc4 100644 --- a/web/link_fixer.js +++ b/web/link_fixer.js @@ -275,7 +275,7 @@ export function fixBadLinks(graph, fix = false, silent = false, logger = console !silent && logger.log(`${fix ? "Made" : "Would make"} ${data.patchedNodes.length || "no"} node link patches, and ${data.deletedLinks.length || "no"} stale link removals.`); let hasBadLinks = !!(data.patchedNodes.length || data.deletedLinks.length); - if (!silent) { + if (fix && !silent) { const rerun = fixBadLinks(graph, false, true); hasBadLinks = rerun.hasBadLinks; } diff --git a/web/rgthree.js b/web/rgthree.js index e086916..fe64df6 100644 --- a/web/rgthree.js +++ b/web/rgthree.js @@ -1,4 +1,5 @@ import { app } from "../../scripts/app.js"; +import { rgthreeConfig } from "./rgthree_config.js"; import { fixBadLinks } from "./link_fixer.js"; export var LogLevel; (function (LogLevel) { @@ -64,6 +65,7 @@ class Rgthree { this.shiftKey = false; this.logger = new LogSession("[rgthree]"); this.monitorBadLinksAlerted = false; + this.monitorLinkTimeout = null; window.addEventListener("keydown", (e) => { this.ctrlKey = !!e.ctrlKey; this.altKey = !!e.altKey; @@ -86,6 +88,10 @@ class Rgthree { const loadGraphData = app.loadGraphData; app.loadGraphData = function (graph) { var _a; + if (this.monitorLinkTimeout) { + clearTimeout(this.monitorLinkTimeout); + this.monitorLinkTimeout = null; + } (_a = document.querySelector('.rgthree-bad-links-alerts-container')) === null || _a === void 0 ? void 0 : _a.remove(); let graphCopy; try { @@ -150,6 +156,11 @@ class Rgthree { alert('Success! It\'s possible some valid links may have been affected. Please check and verify your workflow.'); wasLoadingAborted && app.loadGraphData(fixBadLinksResult.graph); container.remove(); + if (rgthreeConfig['monitor_bad_links']) { + that.monitorLinkTimeout = setTimeout(() => { + that.monitorBadLinks(); + }, 5000); + } } } }); @@ -158,6 +169,11 @@ class Rgthree { container && (container.style.transform = 'translateY(0%)'); }, 500); } + else if (rgthreeConfig['monitor_bad_links']) { + that.monitorLinkTimeout = setTimeout(() => { + that.monitorBadLinks(); + }, 5000); + } }, 100); loadGraphData && loadGraphData.call(app, ...arguments); }; @@ -172,10 +188,17 @@ class Rgthree { return this.logger.newSession(name); } monitorBadLinks() { - this.logger.debug('Starting a monitor for bad links.'); - setInterval(() => { - const badLinksFound = fixBadLinks(app.graph); - }, 1000); + const badLinksFound = fixBadLinks(app.graph); + if (badLinksFound.hasBadLinks && !this.monitorBadLinksAlerted) { + this.monitorBadLinksAlerted = true; + alert(`Problematic links just found in live data. Can you save your workflow and file a bug with the last few steps you took to trigger this at https://github.com/rgthree/rgthree-comfy/issues. Thank you!`); + } + else if (!badLinksFound.hasBadLinks) { + this.monitorBadLinksAlerted = false; + } + this.monitorLinkTimeout = setTimeout(() => { + this.monitorBadLinks(); + }, 5000); } } export const rgthree = new Rgthree();