mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-25 14:25:44 -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:
@@ -175,8 +175,9 @@ class CanvasNode:
|
|||||||
"required": {
|
"required": {
|
||||||
"fit_on_add": ("BOOLEAN", {"default": False, "label_on": "Fit on Add/Paste", "label_off": "Default Behavior"}),
|
"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"}),
|
"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}),
|
"auto_refresh_after_generation": ("BOOLEAN", {"default": False, "label_on": "True", "label_off": "False"}),
|
||||||
"node_id": ("STRING", {"default": "0", "hidden": True}),
|
"trigger": ("INT", {"default": 0, "min": 0, "max": 99999999, "step": 1}),
|
||||||
|
"node_id": ("STRING", {"default": "0"}),
|
||||||
},
|
},
|
||||||
"hidden": {
|
"hidden": {
|
||||||
"prompt": ("PROMPT",),
|
"prompt": ("PROMPT",),
|
||||||
@@ -238,7 +239,7 @@ class CanvasNode:
|
|||||||
|
|
||||||
_processing_lock = threading.Lock()
|
_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:
|
try:
|
||||||
|
|
||||||
|
|||||||
21
js/Canvas.js
21
js/Canvas.js
@@ -155,7 +155,7 @@ export class Canvas {
|
|||||||
log.debug('Initializing Canvas modules...');
|
log.debug('Initializing Canvas modules...');
|
||||||
// Stwórz opóźnioną wersję funkcji zapisu stanu
|
// Stwórz opóźnioną wersję funkcji zapisu stanu
|
||||||
this.requestSaveState = debounce(() => this.saveState(), 500);
|
this.requestSaveState = debounce(() => this.saveState(), 500);
|
||||||
this._addAutoRefreshToggle();
|
this._setupAutoRefreshHandlers();
|
||||||
log.debug('Canvas modules initialized successfully');
|
log.debug('Canvas modules initialized successfully');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -321,11 +321,15 @@ export class Canvas {
|
|||||||
async importLatestImage() {
|
async importLatestImage() {
|
||||||
return this.canvasIO.importLatestImage();
|
return this.canvasIO.importLatestImage();
|
||||||
}
|
}
|
||||||
_addAutoRefreshToggle() {
|
_setupAutoRefreshHandlers() {
|
||||||
let autoRefreshEnabled = false;
|
|
||||||
let lastExecutionStartTime = 0;
|
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 = () => {
|
const handleExecutionStart = () => {
|
||||||
if (autoRefreshEnabled) {
|
if (getAutoRefreshValue()) {
|
||||||
lastExecutionStartTime = Date.now();
|
lastExecutionStartTime = Date.now();
|
||||||
// Store a snapshot of the context for the upcoming batch
|
// Store a snapshot of the context for the upcoming batch
|
||||||
this.pendingBatchContext = {
|
this.pendingBatchContext = {
|
||||||
@@ -347,7 +351,7 @@ export class Canvas {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const handleExecutionSuccess = async () => {
|
const handleExecutionSuccess = async () => {
|
||||||
if (autoRefreshEnabled) {
|
if (getAutoRefreshValue()) {
|
||||||
log.info('Auto-refresh triggered, importing latest images.');
|
log.info('Auto-refresh triggered, importing latest images.');
|
||||||
if (!this.pendingBatchContext) {
|
if (!this.pendingBatchContext) {
|
||||||
log.warn("execution_start did not fire, cannot process batch. Awaiting next execution.");
|
log.warn("execution_start did not fire, cannot process batch. Awaiting next execution.");
|
||||||
@@ -366,12 +370,6 @@ export class Canvas {
|
|||||||
this.render();
|
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_start', handleExecutionStart);
|
||||||
api.addEventListener('execution_success', handleExecutionSuccess);
|
api.addEventListener('execution_success', handleExecutionSuccess);
|
||||||
this.node.onRemoved = useChainCallback(this.node.onRemoved, () => {
|
this.node.onRemoved = useChainCallback(this.node.onRemoved, () => {
|
||||||
@@ -379,6 +377,7 @@ export class Canvas {
|
|||||||
api.removeEventListener('execution_start', handleExecutionStart);
|
api.removeEventListener('execution_start', handleExecutionStart);
|
||||||
api.removeEventListener('execution_success', handleExecutionSuccess);
|
api.removeEventListener('execution_success', handleExecutionSuccess);
|
||||||
});
|
});
|
||||||
|
log.debug('Auto-refresh handlers setup complete, reading from node widget: auto_refresh_after_generation');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Uruchamia edytor masek
|
* Uruchamia edytor masek
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ export class Canvas {
|
|||||||
// Stwórz opóźnioną wersję funkcji zapisu stanu
|
// Stwórz opóźnioną wersję funkcji zapisu stanu
|
||||||
this.requestSaveState = debounce(() => this.saveState(), 500);
|
this.requestSaveState = debounce(() => this.saveState(), 500);
|
||||||
|
|
||||||
this._addAutoRefreshToggle();
|
this._setupAutoRefreshHandlers();
|
||||||
|
|
||||||
log.debug('Canvas modules initialized successfully');
|
log.debug('Canvas modules initialized successfully');
|
||||||
}
|
}
|
||||||
@@ -411,12 +411,17 @@ export class Canvas {
|
|||||||
return this.canvasIO.importLatestImage();
|
return this.canvasIO.importLatestImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
_addAutoRefreshToggle() {
|
_setupAutoRefreshHandlers() {
|
||||||
let autoRefreshEnabled = false;
|
|
||||||
let lastExecutionStartTime = 0;
|
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 = () => {
|
const handleExecutionStart = () => {
|
||||||
if (autoRefreshEnabled) {
|
if (getAutoRefreshValue()) {
|
||||||
lastExecutionStartTime = Date.now();
|
lastExecutionStartTime = Date.now();
|
||||||
// Store a snapshot of the context for the upcoming batch
|
// Store a snapshot of the context for the upcoming batch
|
||||||
this.pendingBatchContext = {
|
this.pendingBatchContext = {
|
||||||
@@ -439,7 +444,7 @@ export class Canvas {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleExecutionSuccess = async () => {
|
const handleExecutionSuccess = async () => {
|
||||||
if (autoRefreshEnabled) {
|
if (getAutoRefreshValue()) {
|
||||||
log.info('Auto-refresh triggered, importing latest images.');
|
log.info('Auto-refresh triggered, importing latest images.');
|
||||||
|
|
||||||
if (!this.pendingBatchContext) {
|
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_start', handleExecutionStart);
|
||||||
api.addEventListener('execution_success', handleExecutionSuccess);
|
api.addEventListener('execution_success', handleExecutionSuccess);
|
||||||
|
|
||||||
@@ -490,6 +483,8 @@ export class Canvas {
|
|||||||
api.removeEventListener('execution_start', handleExecutionStart);
|
api.removeEventListener('execution_start', handleExecutionStart);
|
||||||
api.removeEventListener('execution_success', handleExecutionSuccess);
|
api.removeEventListener('execution_success', handleExecutionSuccess);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
log.debug('Auto-refresh handlers setup complete, reading from node widget: auto_refresh_after_generation');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user