Save watch progress when closing window (#1217)

This commit is contained in:
Svallinn 2021-04-21 18:38:46 +00:00 committed by GitHub
parent 5f4ea74c16
commit c8d96d38b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 12 deletions

View File

@ -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