diff --git a/modules/ui_definitions.py b/modules/ui_definitions.py index ec497f9e9..679bcb4fc 100644 --- a/modules/ui_definitions.py +++ b/modules/ui_definitions.py @@ -570,6 +570,7 @@ def create_settings(cmd_opts): "live_preview_refresh_period": OptionInfo(500, "Progress update period", gr.Slider, {"minimum": 0, "maximum": 5000, "step": 25}), "taesd_variant": OptionInfo(shared_items.sd_taesd_items()[0], "TAESD variant", gr.Dropdown, {"choices": shared_items.sd_taesd_items()}), "taesd_layers": OptionInfo(3, "TAESD decode layers", gr.Slider, {"minimum": 1, "maximum": 3, "step": 1}), + "live_preview_require_focus": OptionInfo(True, "Pause live previews when tab is not focused"), "live_preview_downscale": OptionInfo(True, "Downscale high resolution live previews"), "notification_audio_enable": OptionInfo(False, "Play a notification upon completion"), diff --git a/ui/progressBar.ts b/ui/progressBar.ts index 831822ead..6b10292bc 100644 --- a/ui/progressBar.ts +++ b/ui/progressBar.ts @@ -11,7 +11,7 @@ export function setRefreshInterval() { refreshInterval = window.opts.live_preview_refresh_period || 500; log('refreshInterval', document.visibilityState, refreshInterval); document.addEventListener('visibilitychange', () => { - if (document.hidden) refreshInterval = Math.max(2500, window.opts.live_preview_refresh_period || 1000); + if (window.opts.live_preview_require_focus !== false && document.hidden) refreshInterval = Math.max(2500, window.opts.live_preview_refresh_period || 1000); else refreshInterval = window.opts.live_preview_refresh_period || 1000; // log('refreshInterval', document.visibilityState, refreshInterval); }); @@ -148,7 +148,7 @@ export function requestProgress(id_task = 'undefined', progressEl = null, galler const startLivePreview = (taskId: string, id_live_preview: number) => { if (window.opts.live_preview_refresh_period === 0) return; - const request_id = document.hidden ? -1 : id_live_preview; + const request_id = (window.opts.live_preview_require_focus !== false && document.hidden) ? -1 : id_live_preview; const onProgressHandler = (res) => { if (res?.debug) debug('progress:', { start: dateStart, id: request_id, res });