Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure screen saver blocker removed when window closed #3557

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions src/renderer/components/ft-video-player/ft-video-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const VHS_BANDWIDTH_VARIANCE = videojs.Vhs.BANDWIDTH_VARIANCE

export default defineComponent({
name: 'FtVideoPlayer',
beforeRouteLeave: function (_to, _from, next) {
window.removeEventListener('beforeunload', this.stopPowerSaveBlocker)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this can/should be moved into beforeDestroy
But this is how it's done currently in Watch view

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be moved to beforeDestroy, the route hooks only get triggered in components that are directly inside the router view. So for us those are the components in the src/renderer/views. Additionally the player gets destroyed and a new instance created when you change formats (maybe we can change that in the future, but for the moment that makes it easier for us), so you want this removed as soon as it's destroyed, so that you get rid of the event handler for all instances of the player.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

next()
},
props: {
format: {
type: String,
Expand Down Expand Up @@ -339,6 +343,8 @@ export default defineComponent({
navigator.mediaSession.setActionHandler('play', () => this.player.play())
navigator.mediaSession.setActionHandler('pause', () => this.player.pause())
}

window.addEventListener('beforeunload', this.stopPowerSaveBlocker)
},
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
Expand All @@ -357,10 +363,7 @@ export default defineComponent({
navigator.mediaSession.playbackState = 'none'
}

if (process.env.IS_ELECTRON && this.powerSaveBlocker !== null) {
const { ipcRenderer } = require('electron')
ipcRenderer.send(IpcChannels.STOP_POWER_SAVE_BLOCKER, this.powerSaveBlocker)
}
this.stopPowerSaveBlocker()
},
methods: {
initializePlayer: async function () {
Expand Down Expand Up @@ -550,11 +553,7 @@ export default defineComponent({
navigator.mediaSession.playbackState = 'none'
}

if (process.env.IS_ELECTRON && this.powerSaveBlocker !== null) {
const { ipcRenderer } = require('electron')
ipcRenderer.send(IpcChannels.STOP_POWER_SAVE_BLOCKER, this.powerSaveBlocker)
this.powerSaveBlocker = null
}
this.stopPowerSaveBlocker()
})

this.player.on('error', (error, message) => {
Expand All @@ -564,11 +563,7 @@ export default defineComponent({
navigator.mediaSession.playbackState = 'none'
}

if (process.env.IS_ELECTRON && this.powerSaveBlocker !== null) {
const { ipcRenderer } = require('electron')
ipcRenderer.send(IpcChannels.STOP_POWER_SAVE_BLOCKER, this.powerSaveBlocker)
this.powerSaveBlocker = null
}
this.stopPowerSaveBlocker()
})

this.player.on('play', async () => {
Expand All @@ -588,11 +583,7 @@ export default defineComponent({
navigator.mediaSession.playbackState = 'paused'
}

if (process.env.IS_ELECTRON && this.powerSaveBlocker !== null) {
const { ipcRenderer } = require('electron')
ipcRenderer.send(IpcChannels.STOP_POWER_SAVE_BLOCKER, this.powerSaveBlocker)
this.powerSaveBlocker = null
}
this.stopPowerSaveBlocker()
})

this.player.on(this.statsModalEventName, () => {
Expand Down Expand Up @@ -2032,6 +2023,14 @@ export default defineComponent({
}
},

stopPowerSaveBlocker: function() {
if (process.env.IS_ELECTRON && this.powerSaveBlocker !== null) {
const { ipcRenderer } = require('electron')
ipcRenderer.send(IpcChannels.STOP_POWER_SAVE_BLOCKER, this.powerSaveBlocker)
this.powerSaveBlocker = null
}
},

...mapActions([
'updateDefaultCaptionSettings',
'parseScreenshotCustomFileName',
Expand Down