mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-24 22:12:17 -03:00
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:
21
js/Canvas.js
21
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
|
||||
|
||||
Reference in New Issue
Block a user