mirror of https://github.com/vladmandic/automatic
Add auto-update setting and functionality
parent
f84cb6ac64
commit
ade7c2e5f9
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue