diff --git a/canvas_node.py b/canvas_node.py index 2b4f031..ece5585 100644 --- a/canvas_node.py +++ b/canvas_node.py @@ -175,8 +175,9 @@ class CanvasNode: "required": { "fit_on_add": ("BOOLEAN", {"default": False, "label_on": "Fit on Add/Paste", "label_off": "Default Behavior"}), "show_preview": ("BOOLEAN", {"default": False, "label_on": "Show Preview", "label_off": "Hide Preview"}), - "trigger": ("INT", {"default": 0, "min": 0, "max": 99999999, "step": 1, "hidden": True}), - "node_id": ("STRING", {"default": "0", "hidden": True}), + "auto_refresh_after_generation": ("BOOLEAN", {"default": False, "label_on": "True", "label_off": "False"}), + "trigger": ("INT", {"default": 0, "min": 0, "max": 99999999, "step": 1}), + "node_id": ("STRING", {"default": "0"}), }, "hidden": { "prompt": ("PROMPT",), @@ -238,7 +239,7 @@ class CanvasNode: _processing_lock = threading.Lock() - def process_canvas_image(self, fit_on_add, show_preview, trigger, node_id, prompt=None, unique_id=None): + def process_canvas_image(self, fit_on_add, show_preview, auto_refresh_after_generation, trigger, node_id, prompt=None, unique_id=None): try: diff --git a/js/Canvas.js b/js/Canvas.js index 85042b3..c077851 100644 --- a/js/Canvas.js +++ b/js/Canvas.js @@ -155,7 +155,7 @@ export class Canvas { log.debug('Initializing Canvas modules...'); // Stwórz opóźnioną wersję funkcji zapisu stanu this.requestSaveState = debounce(() => this.saveState(), 500); - this._addAutoRefreshToggle(); + this._setupAutoRefreshHandlers(); log.debug('Canvas modules initialized successfully'); } /** @@ -321,11 +321,15 @@ export class Canvas { async importLatestImage() { return this.canvasIO.importLatestImage(); } - _addAutoRefreshToggle() { - let autoRefreshEnabled = false; + _setupAutoRefreshHandlers() { let lastExecutionStartTime = 0; + // Helper function to get auto-refresh value from node widget + const getAutoRefreshValue = () => { + const widget = this.node.widgets.find((w) => w.name === 'auto_refresh_after_generation'); + return widget ? widget.value : false; + }; const handleExecutionStart = () => { - if (autoRefreshEnabled) { + if (getAutoRefreshValue()) { lastExecutionStartTime = Date.now(); // Store a snapshot of the context for the upcoming batch this.pendingBatchContext = { @@ -347,7 +351,7 @@ export class Canvas { } }; const handleExecutionSuccess = async () => { - if (autoRefreshEnabled) { + if (getAutoRefreshValue()) { log.info('Auto-refresh triggered, importing latest images.'); if (!this.pendingBatchContext) { log.warn("execution_start did not fire, cannot process batch. Awaiting next execution."); @@ -366,12 +370,6 @@ export class Canvas { this.render(); } }; - this.node.addWidget('toggle', 'Auto-refresh after generation', false, (value) => { - autoRefreshEnabled = value; - log.debug('Auto-refresh toggled:', value); - }, { - serialize: false - }); api.addEventListener('execution_start', handleExecutionStart); api.addEventListener('execution_success', handleExecutionSuccess); this.node.onRemoved = useChainCallback(this.node.onRemoved, () => { @@ -379,6 +377,7 @@ export class Canvas { api.removeEventListener('execution_start', handleExecutionStart); api.removeEventListener('execution_success', handleExecutionSuccess); }); + log.debug('Auto-refresh handlers setup complete, reading from node widget: auto_refresh_after_generation'); } /** * Uruchamia edytor masek diff --git a/src/Canvas.ts b/src/Canvas.ts index 2e9a13a..9cadfc3 100644 --- a/src/Canvas.ts +++ b/src/Canvas.ts @@ -212,7 +212,7 @@ export class Canvas { // Stwórz opóźnioną wersję funkcji zapisu stanu this.requestSaveState = debounce(() => this.saveState(), 500); - this._addAutoRefreshToggle(); + this._setupAutoRefreshHandlers(); log.debug('Canvas modules initialized successfully'); } @@ -411,12 +411,17 @@ export class Canvas { return this.canvasIO.importLatestImage(); } - _addAutoRefreshToggle() { - let autoRefreshEnabled = false; + _setupAutoRefreshHandlers() { let lastExecutionStartTime = 0; + // Helper function to get auto-refresh value from node widget + const getAutoRefreshValue = (): boolean => { + const widget = this.node.widgets.find((w: any) => w.name === 'auto_refresh_after_generation'); + return widget ? widget.value : false; + }; + const handleExecutionStart = () => { - if (autoRefreshEnabled) { + if (getAutoRefreshValue()) { lastExecutionStartTime = Date.now(); // Store a snapshot of the context for the upcoming batch this.pendingBatchContext = { @@ -439,7 +444,7 @@ export class Canvas { }; const handleExecutionSuccess = async () => { - if (autoRefreshEnabled) { + if (getAutoRefreshValue()) { log.info('Auto-refresh triggered, importing latest images.'); if (!this.pendingBatchContext) { @@ -470,18 +475,6 @@ export class Canvas { } }; - this.node.addWidget( - 'toggle', - 'Auto-refresh after generation', - false, - (value: boolean) => { - autoRefreshEnabled = value; - log.debug('Auto-refresh toggled:', value); - }, { - serialize: false - } - ); - api.addEventListener('execution_start', handleExecutionStart); api.addEventListener('execution_success', handleExecutionSuccess); @@ -490,6 +483,8 @@ export class Canvas { api.removeEventListener('execution_start', handleExecutionStart); api.removeEventListener('execution_success', handleExecutionSuccess); }); + + log.debug('Auto-refresh handlers setup complete, reading from node widget: auto_refresh_after_generation'); }