From c6e3075b86a43abab1481dc8443c1a6ce56e9ff9 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Mon, 15 May 2023 14:00:17 +0800 Subject: [PATCH 1/3] $ Extract method for stopping screen saver blocker --- .../ft-video-player/ft-video-player.js | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/renderer/components/ft-video-player/ft-video-player.js b/src/renderer/components/ft-video-player/ft-video-player.js index 6185f87e8c7f7..e726edeb8664f 100644 --- a/src/renderer/components/ft-video-player/ft-video-player.js +++ b/src/renderer/components/ft-video-player/ft-video-player.js @@ -357,10 +357,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 () { @@ -550,11 +547,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) => { @@ -564,11 +557,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 () => { @@ -588,11 +577,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, () => { @@ -2032,6 +2017,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', From d14636f632b7cd1cf63c547f37b20287e14d69f0 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Mon, 15 May 2023 14:10:19 +0800 Subject: [PATCH 2/3] ! Ensure screen saver blocker removed when window closed --- src/renderer/components/ft-video-player/ft-video-player.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/renderer/components/ft-video-player/ft-video-player.js b/src/renderer/components/ft-video-player/ft-video-player.js index e726edeb8664f..cfad3806e8e4e 100644 --- a/src/renderer/components/ft-video-player/ft-video-player.js +++ b/src/renderer/components/ft-video-player/ft-video-player.js @@ -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) + next() + }, props: { format: { type: String, @@ -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) From 1085dcbc07d4d5ae74766a9ddb6f68f15db894c5 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Tue, 16 May 2023 15:58:33 +0800 Subject: [PATCH 3/3] * Move beforeunload event listener removal to beforeDestroy --- src/renderer/components/ft-video-player/ft-video-player.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/renderer/components/ft-video-player/ft-video-player.js b/src/renderer/components/ft-video-player/ft-video-player.js index cfad3806e8e4e..d875472ebbf0a 100644 --- a/src/renderer/components/ft-video-player/ft-video-player.js +++ b/src/renderer/components/ft-video-player/ft-video-player.js @@ -42,10 +42,6 @@ const VHS_BANDWIDTH_VARIANCE = videojs.Vhs.BANDWIDTH_VARIANCE export default defineComponent({ name: 'FtVideoPlayer', - beforeRouteLeave: function (_to, _from, next) { - window.removeEventListener('beforeunload', this.stopPowerSaveBlocker) - next() - }, props: { format: { type: String, @@ -364,6 +360,7 @@ export default defineComponent({ } this.stopPowerSaveBlocker() + window.removeEventListener('beforeunload', this.stopPowerSaveBlocker) }, methods: { initializePlayer: async function () {