From 3356c631bb01eae9a42389478536807d275e2784 Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Sun, 3 Aug 2025 22:25:25 +0200 Subject: [PATCH] Fix toggle mask switch UI sync with auto refresh Ensured the toggle mask switch UI stays in sync with mask visibility when auto_refresh_after_generation hides or shows the mask. The checkbox and switch now correctly reflect the current mask state, preventing UI desynchronization and improving user experience. --- js/BatchPreviewManager.js | 24 ++++++++++++++++-------- src/BatchPreviewManager.ts | 24 ++++++++++++++++-------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/js/BatchPreviewManager.js b/js/BatchPreviewManager.js index d6fb68a..857b1e6 100644 --- a/js/BatchPreviewManager.js +++ b/js/BatchPreviewManager.js @@ -123,10 +123,14 @@ export class BatchPreviewManager { this.maskWasVisible = this.canvas.maskTool.isOverlayVisible; if (this.maskWasVisible) { this.canvas.maskTool.toggleOverlayVisibility(); - const toggleBtn = document.getElementById(`toggle-mask-btn-${this.canvas.node.id}`); - if (toggleBtn) { - toggleBtn.classList.remove('primary'); - const iconContainer = toggleBtn.querySelector('.mask-icon-container'); + const toggleSwitch = document.getElementById(`toggle-mask-switch-${this.canvas.node.id}`); + if (toggleSwitch) { + const checkbox = toggleSwitch.querySelector('input[type="checkbox"]'); + if (checkbox) { + checkbox.checked = false; + } + toggleSwitch.classList.remove('primary'); + const iconContainer = toggleSwitch.querySelector('.switch-icon'); if (iconContainer) { iconContainer.style.opacity = '0.5'; } @@ -165,10 +169,14 @@ export class BatchPreviewManager { this.canvas.render(); if (this.maskWasVisible && !this.canvas.maskTool.isOverlayVisible) { this.canvas.maskTool.toggleOverlayVisibility(); - const toggleBtn = document.getElementById(`toggle-mask-btn-${String(this.canvas.node.id)}`); - if (toggleBtn) { - toggleBtn.classList.add('primary'); - const iconContainer = toggleBtn.querySelector('.mask-icon-container'); + const toggleSwitch = document.getElementById(`toggle-mask-switch-${String(this.canvas.node.id)}`); + if (toggleSwitch) { + const checkbox = toggleSwitch.querySelector('input[type="checkbox"]'); + if (checkbox) { + checkbox.checked = true; + } + toggleSwitch.classList.add('primary'); + const iconContainer = toggleSwitch.querySelector('.switch-icon'); if (iconContainer) { iconContainer.style.opacity = '1'; } diff --git a/src/BatchPreviewManager.ts b/src/BatchPreviewManager.ts index 0de5267..657e961 100644 --- a/src/BatchPreviewManager.ts +++ b/src/BatchPreviewManager.ts @@ -166,10 +166,14 @@ export class BatchPreviewManager { this.maskWasVisible = this.canvas.maskTool.isOverlayVisible; if (this.maskWasVisible) { this.canvas.maskTool.toggleOverlayVisibility(); - const toggleBtn = document.getElementById(`toggle-mask-btn-${this.canvas.node.id}`); - if (toggleBtn) { - toggleBtn.classList.remove('primary'); - const iconContainer = toggleBtn.querySelector('.mask-icon-container') as HTMLElement; + const toggleSwitch = document.getElementById(`toggle-mask-switch-${this.canvas.node.id}`); + if (toggleSwitch) { + const checkbox = toggleSwitch.querySelector('input[type="checkbox"]') as HTMLInputElement; + if (checkbox) { + checkbox.checked = false; + } + toggleSwitch.classList.remove('primary'); + const iconContainer = toggleSwitch.querySelector('.switch-icon') as HTMLElement; if (iconContainer) { iconContainer.style.opacity = '0.5'; } @@ -218,10 +222,14 @@ export class BatchPreviewManager { if (this.maskWasVisible && !this.canvas.maskTool.isOverlayVisible) { this.canvas.maskTool.toggleOverlayVisibility(); - const toggleBtn = document.getElementById(`toggle-mask-btn-${String(this.canvas.node.id)}`); - if (toggleBtn) { - toggleBtn.classList.add('primary'); - const iconContainer = toggleBtn.querySelector('.mask-icon-container') as HTMLElement; + const toggleSwitch = document.getElementById(`toggle-mask-switch-${String(this.canvas.node.id)}`); + if (toggleSwitch) { + const checkbox = toggleSwitch.querySelector('input[type="checkbox"]') as HTMLInputElement; + if (checkbox) { + checkbox.checked = true; + } + toggleSwitch.classList.add('primary'); + const iconContainer = toggleSwitch.querySelector('.switch-icon') as HTMLElement; if (iconContainer) { iconContainer.style.opacity = '1'; }