From c4af745b2aa8386dd554d6553eb0d3139be98db6 Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Thu, 3 Jul 2025 02:44:07 +0200 Subject: [PATCH] Add addLayers method to BatchPreviewManager Introduces an addLayers method to BatchPreviewManager for adding new layers to an active batch preview or showing the UI if inactive. Updates Canvas to use addLayers instead of show, and fixes a bug where new layers were only added if more than one was present. --- js/BatchPreviewManager.js | 16 ++++++++++++++++ js/Canvas.js | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/js/BatchPreviewManager.js b/js/BatchPreviewManager.js index 7bd79c7..8989fef 100644 --- a/js/BatchPreviewManager.js +++ b/js/BatchPreviewManager.js @@ -134,6 +134,22 @@ export class BatchPreviewManager { this.canvas.render(); } + addLayers(newLayers) { + if (!newLayers || newLayers.length === 0) { + return; + } + + if (this.active) { + // UI is already open, just add the new layers + log.info(`Adding ${newLayers.length} new layers to active batch preview.`); + this.layers.push(...newLayers); + this._update(); + } else { + // UI is not open, show it with the new layers + this.show(newLayers); + } + } + navigate(direction) { this.currentIndex += direction; if (this.currentIndex < 0) { diff --git a/js/Canvas.js b/js/Canvas.js index 20bd719..d95e6b9 100644 --- a/js/Canvas.js +++ b/js/Canvas.js @@ -493,8 +493,8 @@ export class Canvas { log.info('Auto-refresh triggered, importing latest images.'); const newLayers = await this.canvasIO.importLatestImages(lastExecutionStartTime); - if (newLayers && newLayers.length > 1) { - this.batchPreviewManager.show(newLayers); + if (newLayers && newLayers.length > 0) { + this.batchPreviewManager.addLayers(newLayers); } } };