SponsorBlock: Prevent multiple notifications at the end of a video

Closes: #1299

Previously, the app would notified the user (with a toast) of a
sponsor segment skip repeatedly if the segment lasted
until the end of a video.
This commit fixes that behavior so that it's displayed only once.
This commit is contained in:
Svallinn 2021-05-20 04:00:39 +01:00
parent f6fb6c67c9
commit 089cd5845b
No known key found for this signature in database
GPG Key ID: 09FB527F34037CCA
1 changed files with 18 additions and 9 deletions

View File

@ -241,6 +241,10 @@ export default Vue.extend({
}, 200) }, 200)
} }
if (this.useSponsorBlock) {
this.initializeSponsorBlock()
}
$(document).on('keydown', this.keyboardShortcutHandler) $(document).on('keydown', this.keyboardShortcutHandler)
this.player.on('mousemove', this.hideMouseTimeout) this.player.on('mousemove', this.hideMouseTimeout)
@ -286,18 +290,22 @@ export default Vue.extend({
} }
}) })
} }
setTimeout(() => { this.fetchSponsorBlockInfo() }, 100)
}, },
fetchSponsorBlockInfo() { initializeSponsorBlock() {
if (this.useSponsorBlock) { this.$store.dispatch('sponsorBlockSkipSegments', {
this.$store.dispatch('sponsorBlockSkipSegments', { videoId: this.videoId,
videoId: this.videoId, categories: ['sponsor']
categories: ['sponsor'] }).then((skipSegments) => {
}).then((skipSegments) => { if (skipSegments.length === 0) {
return
}
this.player.ready(() => {
this.player.on('timeupdate', () => { this.player.on('timeupdate', () => {
this.skipSponsorBlocks(skipSegments) this.skipSponsorBlocks(skipSegments)
}) })
skipSegments.forEach(({ skipSegments.forEach(({
category, category,
segment: [startTime, endTime] segment: [startTime, endTime]
@ -309,11 +317,12 @@ export default Vue.extend({
}) })
}) })
}) })
} })
}, },
skipSponsorBlocks(skipSegments) { skipSponsorBlocks(skipSegments) {
const currentTime = this.player.currentTime() const currentTime = this.player.currentTime()
const duration = this.player.duration()
let newTime = null let newTime = null
let skippedCategory = null let skippedCategory = null
skipSegments.forEach(({ category, segment: [startTime, endTime] }) => { skipSegments.forEach(({ category, segment: [startTime, endTime] }) => {
@ -322,7 +331,7 @@ export default Vue.extend({
skippedCategory = category skippedCategory = category
} }
}) })
if (newTime !== null) { if (newTime !== null && Math.abs(duration - currentTime) > 0.500) {
if (this.sponsorBlockShowSkippedToast) { if (this.sponsorBlockShowSkippedToast) {
this.showSkippedSponsorSegmentInformation(skippedCategory) this.showSkippedSponsorSegmentInformation(skippedCategory)
} }