Refactor auto-refresh toggle to node widget property

Replaces the local auto-refresh toggle with a node widget property 'auto_refresh_after_generation' in both JS and TS Canvas classes. Updates Python CanvasNode to include this property in the required config and removes 'hidden' from 'trigger' and 'node_id'. This change centralizes auto-refresh state in the node widget for better consistency and UI integration.
This commit is contained in:
Dariusz L
2025-07-21 20:31:46 +02:00
parent db65c0c72e
commit 5419acad27
3 changed files with 26 additions and 31 deletions

View File

@@ -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