Add auto-update setting and functionality

pull/4625/head
awsr 2026-02-06 00:50:04 -08:00
parent f84cb6ac64
commit ade7c2e5f9
No known key found for this signature in database
2 changed files with 38 additions and 0 deletions

View File

@ -1271,6 +1271,43 @@ async function galleryClearInit() {
}, 1000);
}
async function initGalleryAutoRefresh() {
const isModern = opts.theme_type?.toLowerCase() === 'modern';
let galleryTab = isModern ? document.getElementById('gallery_tabitem') : document.getElementById('tab_gallery');
let timeout = 0;
while (!galleryTab && timeout++ < 60) {
await new Promise((resolve) => { setTimeout(resolve, 1000); });
galleryTab = isModern ? document.getElementById('gallery_tabitem') : document.getElementById('tab_gallery');
}
if (!galleryTab) {
throw new Error('Timed out waiting for gallery tab element');
}
const displayNoneRegEx = /display:\s*none/;
async function galleryAutoRefresh(mutations) {
if (!opts.browser_gallery_autoupdate) return;
for (const mutation of mutations) {
switch (mutation.attributeName) {
case 'class':
if (mutation.oldValue.includes('hidden') && !mutation.target.classList.contains('hidden')) {
await updateFolders();
GalleryFolder.getActive()?.click();
}
break;
case 'style':
if (displayNoneRegEx.test(mutation.oldValue) && !displayNoneRegEx.test(mutation.target.style.display)) {
await updateFolders();
GalleryFolder.getActive()?.click();
}
break;
default:
break;
}
}
}
const galleryVisObserver = new MutationObserver(galleryAutoRefresh);
galleryVisObserver.observe(galleryTab, { attributeFilter: ['class', 'style'], attributeOldValue: true });
}
async function blockQueueUntilReady() {
// Add block to maintenanceQueue until cache is ready
maintenanceQueue.enqueue({

View File

@ -535,6 +535,7 @@ options_templates.update(options_section(('saving-images', "Image Options"), {
"image_sep_browser": OptionInfo("<h2>Image Gallery</h2>", "", gr.HTML),
"browser_cache": OptionInfo(True, "Use image gallery cache"),
"browser_folders": OptionInfo("", "Additional image browser folders"),
"browser_gallery_autoupdate": OptionInfo(False, "Automatically update when switching to the gallery"),
"browser_fixed_width": OptionInfo(False, "Use fixed width thumbnails"),
"viewer_show_metadata": OptionInfo(True, "Show metadata in full screen image browser"),