Merge pull request #16001 from zero41120/feat-prevent-screen-lock
feat: Prevent screen sleep during generation
This commit is contained in:
commit
a30b19dd55
|
@ -76,6 +76,26 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
|||
var dateStart = new Date();
|
||||
var wasEverActive = false;
|
||||
var parentProgressbar = progressbarContainer.parentNode;
|
||||
var wakeLock = null;
|
||||
|
||||
var requestWakeLock = async function() {
|
||||
if (!opts.prevent_screen_sleep_during_generation || wakeLock) return;
|
||||
try {
|
||||
wakeLock = await navigator.wakeLock.request('screen');
|
||||
} catch (err) {
|
||||
console.error('Wake Lock is not supported.');
|
||||
}
|
||||
};
|
||||
|
||||
var releaseWakeLock = async function() {
|
||||
if (!opts.prevent_screen_sleep_during_generation || !wakeLock) return;
|
||||
try {
|
||||
await wakeLock.release();
|
||||
wakeLock = null;
|
||||
} catch (err) {
|
||||
console.error('Wake Lock release failed', err);
|
||||
}
|
||||
};
|
||||
|
||||
var divProgress = document.createElement('div');
|
||||
divProgress.className = 'progressDiv';
|
||||
|
@ -89,6 +109,7 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
|||
var livePreview = null;
|
||||
|
||||
var removeProgressBar = function() {
|
||||
releaseWakeLock();
|
||||
if (!divProgress) return;
|
||||
|
||||
setTitle("");
|
||||
|
@ -100,6 +121,7 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
|||
};
|
||||
|
||||
var funProgress = function(id_task) {
|
||||
requestWakeLock();
|
||||
request("./internal/progress", {id_task: id_task, live_preview: false}, function(res) {
|
||||
if (res.completed) {
|
||||
removeProgressBar();
|
||||
|
|
|
@ -377,6 +377,7 @@ options_templates.update(options_section(('ui', "Live previews", "ui"), {
|
|||
"live_preview_refresh_period": OptionInfo(1000, "Progressbar and preview update period").info("in milliseconds"),
|
||||
"live_preview_fast_interrupt": OptionInfo(False, "Return image with chosen live preview method on interrupt").info("makes interrupts faster"),
|
||||
"js_live_preview_in_modal_lightbox": OptionInfo(False, "Show Live preview in full page image viewer"),
|
||||
"prevent_screen_sleep_during_generation": OptionInfo(True, "Prevent screen sleep during generation"),
|
||||
}))
|
||||
|
||||
options_templates.update(options_section(('sampler-params', "Sampler parameters", "sd"), {
|
||||
|
|
Loading…
Reference in New Issue