Prevent display from sleeping when video is playing

This commit is contained in:
Preston 2021-01-11 15:45:46 -05:00
parent ce7e568c7b
commit 6c9e176249
1 changed files with 21 additions and 0 deletions

View File

@ -61,6 +61,7 @@ export default Vue.extend({
data: function () {
return {
id: '',
powerSaveBlocker: null,
volume: 1,
player: null,
useDash: false,
@ -115,6 +116,10 @@ export default Vue.extend({
}
},
computed: {
usingElectron: function () {
return this.$store.getters.getUsingElectron
},
defaultPlayback: function () {
return this.$store.getters.getDefaultPlayback
},
@ -235,6 +240,22 @@ export default Vue.extend({
this.player.on('error', function (error, message) {
v.$emit('error', error.target.player.error_)
})
this.player.on('play', function () {
if (this.usingElectron) {
const { powerSaveBlocker } = require('electron')
this.powerSaveBlocker = powerSaveBlocker.start('prevent-display-sleep')
}
})
this.player.on('pause', function () {
if (this.usingElectron && this.powerSaveBlocker !== null) {
const { powerSaveBlocker } = require('electron')
powerSaveBlocker.stop(this.powerSaveBlocker)
this.powerSaveBlocker = null
}
})
}
},