Fix removing the meta files when navigating to a new video (#2344)

This commit is contained in:
absidue 2022-06-21 04:33:42 +02:00 committed by GitHub
parent 10f0af1efa
commit 35dcdbac10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 19 deletions

View File

@ -29,7 +29,7 @@ export default Vue.extend({
'watch-video-recommendations': WatchVideoRecommendations 'watch-video-recommendations': WatchVideoRecommendations
}, },
beforeRouteLeave: function (to, from, next) { beforeRouteLeave: function (to, from, next) {
this.handleRouteChange() this.handleRouteChange(this.videoId)
window.removeEventListener('beforeunload', this.handleWatchProgress) window.removeEventListener('beforeunload', this.handleWatchProgress)
next() next()
}, },
@ -150,7 +150,7 @@ export default Vue.extend({
}, },
watch: { watch: {
$route() { $route() {
this.handleRouteChange() this.handleRouteChange(this.videoId)
// react to route changes... // react to route changes...
this.videoId = this.$route.params.id this.videoId = this.$route.params.id
@ -967,7 +967,11 @@ export default Vue.extend({
this.playNextCountDownIntervalId = setInterval(showCountDownMessage, 1000) this.playNextCountDownIntervalId = setInterval(showCountDownMessage, 1000)
}, },
handleRouteChange: async function () { handleRouteChange: async function (videoId) {
// if the user navigates to another video, the ipc call for the userdata path
// takes long enough for the video id to have already changed to the new one
// receiving it as an arg instead of accessing it ourselves means we always have the right one
clearTimeout(this.playNextTimeout) clearTimeout(this.playNextTimeout)
clearInterval(this.playNextCountDownIntervalId) clearInterval(this.playNextCountDownIntervalId)
@ -977,14 +981,13 @@ export default Vue.extend({
const player = this.$refs.videoPlayer.player const player = this.$refs.videoPlayer.player
if (player !== null && !player.paused() && player.isInPictureInPicture()) { if (player !== null && !player.paused() && player.isInPictureInPicture()) {
const playerId = this.videoId
setTimeout(() => { setTimeout(() => {
player.play() player.play()
player.on('leavepictureinpicture', (event) => { player.on('leavepictureinpicture', (event) => {
const watchTime = player.currentTime() const watchTime = player.currentTime()
if (this.$route.fullPath.includes('/watch')) { if (this.$route.fullPath.includes('/watch')) {
const routeId = this.$route.params.id const routeId = this.$route.params.id
if (routeId === playerId) { if (routeId === videoId) {
const activePlayer = $('.ftVideoPlayer video').get(0) const activePlayer = $('.ftVideoPlayer video').get(0)
activePlayer.currentTime = watchTime activePlayer.currentTime = watchTime
} }
@ -1000,23 +1003,23 @@ export default Vue.extend({
if (this.removeVideoMetaFiles) { if (this.removeVideoMetaFiles) {
const userData = await this.getUserDataPath() const userData = await this.getUserDataPath()
if (this.isDev) { if (this.isDev) {
const dashFileLocation = `static/dashFiles/${this.videoId}.xml` const dashFileLocation = `static/dashFiles/${videoId}.xml`
const vttFileLocation = `static/storyboards/${this.videoId}.vtt` const vttFileLocation = `static/storyboards/${videoId}.vtt`
// only delete the file it actually exists // only delete the file it actually exists
if (fs.existsSync('static/dashFiles/') && fs.existsSync(dashFileLocation)) { if (fs.existsSync(dashFileLocation)) {
fs.rmSync(dashFileLocation) fs.rmSync(dashFileLocation)
} }
if (fs.existsSync('static/storyboards/') && fs.existsSync(vttFileLocation)) { if (fs.existsSync(vttFileLocation)) {
fs.rmSync(vttFileLocation) fs.rmSync(vttFileLocation)
} }
} else { } else {
const dashFileLocation = `${userData}/dashFiles/${this.videoId}.xml` const dashFileLocation = `${userData}/dashFiles/${videoId}.xml`
const vttFileLocation = `${userData}/storyboards/${this.videoId}.vtt` const vttFileLocation = `${userData}/storyboards/${videoId}.vtt`
if (fs.existsSync(`${userData}/dashFiles/`) && fs.existsSync(dashFileLocation)) { if (fs.existsSync(dashFileLocation)) {
fs.rmSync(dashFileLocation) fs.rmSync(dashFileLocation)
} }
if (fs.existsSync(`${userData}/storyboards/`) && fs.existsSync(vttFileLocation)) { if (fs.existsSync(vttFileLocation)) {
fs.rmSync(vttFileLocation) fs.rmSync(vttFileLocation)
} }
} }