From 9726b4d23cb63779964e1d4edff49dd2c9c11e51 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sun, 4 Jun 2023 13:21:52 -0400 Subject: [PATCH] fix gallery view when preview is disabled --- installer.py | 2 +- javascript/progressbar.js | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/installer.py b/installer.py index 67245cf0a..6eb6d7640 100644 --- a/installer.py +++ b/installer.py @@ -402,7 +402,7 @@ def run_extension_installer(folder): if not os.path.isfile(path_installer): return try: - log.debug(f"Running extension installer: {folder} / {path_installer}") + log.debug(f"Running extension installer: {path_installer}") env = os.environ.copy() env['PYTHONPATH'] = os.path.abspath(".") result = subprocess.run(f'"{sys.executable}" "{path_installer}"', shell=True, env=env, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=folder) diff --git a/javascript/progressbar.js b/javascript/progressbar.js index 24e7f50ac..bd93a9a7d 100644 --- a/javascript/progressbar.js +++ b/javascript/progressbar.js @@ -87,23 +87,27 @@ function requestProgress(id_task, progressEl, galleryEl, atEnd = null, onProgres const prevProgress = null; const parentGallery = galleryEl ? galleryEl.parentNode : null; let livePreview; - const img = new Image(); - if (parentGallery) { - livePreview = document.createElement('div'); - livePreview.className = 'livePreview'; - parentGallery.insertBefore(livePreview, galleryEl); - const rect = galleryEl.getBoundingClientRect(); - if (rect.width) { - livePreview.style.width = `${rect.width}px`; - livePreview.style.height = `${rect.height}px`; + let img; + + const init = () => { + img = new Image(); + if (parentGallery) { + livePreview = document.createElement('div'); + livePreview.className = 'livePreview'; + parentGallery.insertBefore(livePreview, galleryEl); + const rect = galleryEl.getBoundingClientRect(); + if (rect.width) { + livePreview.style.width = `${rect.width}px`; + livePreview.style.height = `${rect.height}px`; + } + img.onload = function () { + livePreview.appendChild(img); + if (livePreview.childElementCount > 2) livePreview.removeChild(livePreview.firstElementChild); + }; } - img.onload = function () { - livePreview.appendChild(img); - if (livePreview.childElementCount > 2) livePreview.removeChild(livePreview.firstElementChild); - }; } - const done = function () { + const done = () => { console.debug('task end: ', id_task); localStorage.removeItem('task'); setProgress(); @@ -112,7 +116,7 @@ function requestProgress(id_task, progressEl, galleryEl, atEnd = null, onProgres if (atEnd) atEnd(); }; - const start = function (id_task, id_live_preview) { + const start = (id_task, id_live_preview) => { request('./internal/progress', { id_task, id_live_preview }, (res) => { lastState = res; const elapsedFromStart = (new Date() - dateStart) / 1000; @@ -122,6 +126,7 @@ function requestProgress(id_task, progressEl, galleryEl, atEnd = null, onProgres return; } setProgress(res); + if (res.live_preview && !livePreview) init(); if (res.live_preview && galleryEl) img.src = res.live_preview; if (onProgress) onProgress(res); setTimeout(() => start(id_task, res.id_live_preview), opts.live_preview_refresh_period || 250);