mobile: fix noSleep usage and use wakeLock api when available
This commit is contained in:
parent
c0face2e2f
commit
0fae72664d
2 changed files with 23 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue