If a power saver block already exists, do nothing

Before this change, when opening the player, both 'onPlayerOpen' and
'onPlayerPlay' would fire, which enabled, disabled, and re-enabled the
power save blocker in quick succession.

Instead, we just want to activate it once.
This commit is contained in:
Feross Aboukhadijeh
2016-08-19 20:04:18 -07:00
parent 2cc67dbda7
commit 842ee5ca3c

View File

@@ -13,7 +13,10 @@ var blockId = 0
* display.
*/
function enable () {
disable() // Stop the previous power saver block, if one exists.
if (electron.powerSaveBlocker.isStarted(blockId)) {
// If a power saver block already exists, do nothing.
return
}
blockId = electron.powerSaveBlocker.start('prevent-display-sleep')
log(`powerSaveBlocker.enable: ${blockId}`)
}
@@ -23,6 +26,7 @@ function enable () {
*/
function disable () {
if (!electron.powerSaveBlocker.isStarted(blockId)) {
// If a power saver block does not exist, do nothing.
return
}
electron.powerSaveBlocker.stop(blockId)