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
},
beforeRouteLeave: function (to, from, next) {
this.handleRouteChange()
this.handleRouteChange(this.videoId)
window.removeEventListener('beforeunload', this.handleWatchProgress)
next()
},
@ -150,7 +150,7 @@ export default Vue.extend({
},
watch: {
$route() {
this.handleRouteChange()
this.handleRouteChange(this.videoId)
// react to route changes...
this.videoId = this.$route.params.id
@ -967,7 +967,11 @@ export default Vue.extend({
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)
clearInterval(this.playNextCountDownIntervalId)
@ -977,14 +981,13 @@ export default Vue.extend({
const player = this.$refs.videoPlayer.player
if (player !== null && !player.paused() && player.isInPictureInPicture()) {
const playerId = this.videoId
setTimeout(() => {
player.play()
player.on('leavepictureinpicture', (event) => {
const watchTime = player.currentTime()
if (this.$route.fullPath.includes('/watch')) {
const routeId = this.$route.params.id
if (routeId === playerId) {
if (routeId === videoId) {
const activePlayer = $('.ftVideoPlayer video').get(0)
activePlayer.currentTime = watchTime
}
@ -1000,23 +1003,23 @@ export default Vue.extend({
if (this.removeVideoMetaFiles) {
const userData = await this.getUserDataPath()
if (this.isDev) {
const dashFileLocation = `static/dashFiles/${this.videoId}.xml`
const vttFileLocation = `static/storyboards/${this.videoId}.vtt`
const dashFileLocation = `static/dashFiles/${videoId}.xml`
const vttFileLocation = `static/storyboards/${videoId}.vtt`
// only delete the file it actually exists
if (fs.existsSync('static/dashFiles/') && fs.existsSync(dashFileLocation)) {
if (fs.existsSync(dashFileLocation)) {
fs.rmSync(dashFileLocation)
}
if (fs.existsSync('static/storyboards/') && fs.existsSync(vttFileLocation)) {
if (fs.existsSync(vttFileLocation)) {
fs.rmSync(vttFileLocation)
}
} else {
const dashFileLocation = `${userData}/dashFiles/${this.videoId}.xml`
const vttFileLocation = `${userData}/storyboards/${this.videoId}.vtt`
const dashFileLocation = `${userData}/dashFiles/${videoId}.xml`
const vttFileLocation = `${userData}/storyboards/${videoId}.vtt`
if (fs.existsSync(`${userData}/dashFiles/`) && fs.existsSync(dashFileLocation)) {
if (fs.existsSync(dashFileLocation)) {
fs.rmSync(dashFileLocation)
}
if (fs.existsSync(`${userData}/storyboards/`) && fs.existsSync(vttFileLocation)) {
if (fs.existsSync(vttFileLocation)) {
fs.rmSync(vttFileLocation)
}
}