mobile: fix noSleep usage and use wakeLock api when available

This commit is contained in:
jean-emmanuel 2023-04-05 23:52:26 +02:00
parent c0face2e2f
commit 0fae72664d
2 changed files with 23 additions and 3 deletions

View file

@ -5,6 +5,7 @@
- bug fixes
- widgets: circular value feedback issues
- editor: `ctrl + e` not working when hitm multiple times without releasing `ctrl`
- mobile: "prevent sleep" feature not working
- widgets
- patchbay: add `in`, `out` and `both` modes to `exclusive` property

View file

@ -219,15 +219,34 @@ if (navigator.userAgent.match(/Android|iPhone|iPad|iPod/i)) {
var NoSleep = require('nosleep.js'),
noSleep = new NoSleep(),
noSleepState = false
noSleepState = false,
wakeLock = null
menuEntries.push({
label: locales('nosleep'),
class: ()=>{return 'toggle ' + (noSleepState ? 'on' : 'off')},
action:()=>{
noSleepState = !noSleepState
if (noSleepState) noSleep.disable()
else noSleep.enable()
if (noSleepState) {
if ("wakeLock" in navigator) {
navigator.wakeLock.request("screen").then((l)=>{
wakeLock = l
}).catch((err)=>{
console.error(`Could not acquire wake lock:\n${err.name}, ${err.message}`)
console.info(`Falling back name}, ${err.message}`)
wakeLock = null
})
}
if (wakeLock === null) noSleep.enable()
} else {
if ("wakeLock" in navigator && wakeLock !== null) {
wakeLock.release().then(()=>{
wakeLock = null
})
} else {
noSleep.disable()
}
}
}
})