From c8d96d38b635dd1e851d88e8afcd2c8011736fd7 Mon Sep 17 00:00:00 2001 From: Svallinn <41585298+Svallinn@users.noreply.github.com> Date: Wed, 21 Apr 2021 18:38:46 +0000 Subject: [PATCH] Save watch progress when closing window (#1217) --- src/renderer/views/Watch/Watch.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/renderer/views/Watch/Watch.js b/src/renderer/views/Watch/Watch.js index ea97a86bf..95ae6cdd1 100644 --- a/src/renderer/views/Watch/Watch.js +++ b/src/renderer/views/Watch/Watch.js @@ -32,6 +32,7 @@ export default Vue.extend({ }, beforeRouteLeave: function (to, from, next) { this.handleRouteChange() + window.removeEventListener('beforeunload', this.handleWatchProgress) next() }, data: function() { @@ -195,6 +196,8 @@ export default Vue.extend({ break } } + + window.addEventListener('beforeunload', this.handleWatchProgress) }, methods: { changeTimestamp: function(timestamp) { @@ -688,6 +691,21 @@ export default Vue.extend({ this.updateHistory(videoData) }, + handleWatchProgress: function () { + if (this.rememberHistory && !this.isUpcoming && !this.isLoading && !this.isLive) { + const player = this.$refs.videoPlayer.player + + if (player !== null && this.saveWatchedProgress) { + const currentTime = this.getWatchedProgress() + const payload = { + videoId: this.videoId, + watchProgress: currentTime + } + this.updateWatchProgress(payload) + } + } + }, + checkIfWatched: function () { const historyIndex = this.historyCache.findIndex((video) => { return video.videoId === this.videoId @@ -900,18 +918,7 @@ export default Vue.extend({ handleRouteChange: function () { clearTimeout(this.playNextTimeout) - if (this.rememberHistory && !this.isUpcoming && !this.isLoading && !this.isLive) { - const player = this.$refs.videoPlayer.player - - if (player !== null && this.saveWatchedProgress) { - const currentTime = this.getWatchedProgress() - const payload = { - videoId: this.videoId, - watchProgress: currentTime - } - this.updateWatchProgress(payload) - } - } + this.handleWatchProgress() if (!this.isUpcoming && !this.isLoading) { const player = this.$refs.videoPlayer.player