Skip to content

Commit

Permalink
Autoplay time limit (#5871)
Browse files Browse the repository at this point in the history
* Implement timer for next video to not play automatically

* Update implementation to block next video autoplay

i.e., instead of 'start video automatically' autoplay

* Update variable name and add keyboard handling for ending timeout

* Change autoplay timeout message to be more descriptive, and increase duration to 1 hr
  • Loading branch information
kommunarr authored Dec 6, 2024
1 parent bcf63c2 commit b4217ef
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default defineComponent({
vrProjection: {
type: String,
default: null
}
},
},
emits: [
'error',
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/player-settings/player-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export default defineComponent({
return this.backendPreference !== 'invidious' && !this.backendFallback
},

defaultAutoplayInterruptionIntervalHours: function () {
return parseInt(this.$store.getters.getDefaultAutoplayInterruptionIntervalHours)
},

defaultSkipInterval: function () {
return parseInt(this.$store.getters.getDefaultSkipInterval)
},
Expand Down Expand Up @@ -286,6 +290,7 @@ export default defineComponent({
...mapActions([
'updateAutoplayVideos',
'updateAutoplayPlaylists',
'updateDefaultAutoplayInterruptionIntervalHours',
'updatePlayNextVideo',
'updateEnableSubtitlesByDefault',
'updateProxyVideos',
Expand Down
27 changes: 18 additions & 9 deletions src/renderer/components/player-settings/player-settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@
</div>
</div>
<ft-flex-box>
<ft-slider
:label="$t('Settings.Player Settings.Fast-Forward / Rewind Interval')"
:default-value="defaultSkipInterval"
:min-value="1"
:max-value="70"
:step="1"
value-extension="s"
@change="updateDefaultSkipInterval"
/>
<ft-slider
:label="$t('Settings.Player Settings.Next Video Interval')"
:default-value="defaultInterval"
Expand All @@ -100,6 +91,24 @@
value-extension="s"
@change="updateDefaultInterval"
/>
<ft-slider
:label="$t('Settings.Player Settings.Autoplay Interruption Timer')"
:default-value="defaultAutoplayInterruptionIntervalHours"
:min-value="1"
:max-value="12"
:step="1"
value-extension="h"
@change="updateDefaultAutoplayInterruptionIntervalHours"
/>
<ft-slider
:label="$t('Settings.Player Settings.Fast-Forward / Rewind Interval')"
:default-value="defaultSkipInterval"
:min-value="1"
:max-value="70"
:step="1"
value-extension="s"
@change="updateDefaultSkipInterval"
/>
<ft-slider
:label="$t('Settings.Player Settings.Default Volume')"
:default-value="defaultVolume"
Expand Down
1 change: 1 addition & 0 deletions src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const state = {
baseTheme: 'system',
mainColor: 'Red',
secColor: 'Blue',
defaultAutoplayInterruptionIntervalHours: 3,
defaultCaptionSettings: '{}',
defaultInterval: 5,
defaultPlayback: 1,
Expand Down
31 changes: 31 additions & 0 deletions src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default defineComponent({
beforeRouteLeave: async function (to, from, next) {
this.handleRouteChange()
window.removeEventListener('beforeunload', this.handleWatchProgress)
document.removeEventListener('keydown', this.resetAutoplayInterruptionTimeout)
document.removeEventListener('click', this.resetAutoplayInterruptionTimeout)

if (this.$refs.player) {
await this.$refs.player.destroyPlayer()
Expand Down Expand Up @@ -119,6 +121,8 @@ export default defineComponent({
playNextTimeout: null,
playNextCountDownIntervalId: null,
infoAreaSticky: true,
blockVideoAutoplay: false,
autoplayInterruptionTimeout: null,

onMountedRun: false,

Expand Down Expand Up @@ -160,6 +164,9 @@ export default defineComponent({
proxyVideos: function () {
return this.$store.getters.getProxyVideos
},
defaultAutoplayInterruptionIntervalHours: function () {
return this.$store.getters.getDefaultAutoplayInterruptionIntervalHours
},
defaultInterval: function () {
return this.$store.getters.getDefaultInterval
},
Expand Down Expand Up @@ -321,7 +328,13 @@ export default defineComponent({
this.getVideoInformationLocal()
}

document.removeEventListener('keydown', this.resetAutoplayInterruptionTimeout)
document.removeEventListener('click', this.resetAutoplayInterruptionTimeout)
document.addEventListener('keydown', this.resetAutoplayInterruptionTimeout)
document.addEventListener('click', this.resetAutoplayInterruptionTimeout)

window.addEventListener('beforeunload', this.handleWatchProgress)
this.resetAutoplayInterruptionTimeout()
},

changeTimestamp: function (timestamp) {
Expand Down Expand Up @@ -1233,6 +1246,18 @@ export default defineComponent({
return
}

if (this.blockVideoAutoplay) {
showToast(this.$t('Autoplay Interruption Timer',
this.defaultAutoplayInterruptionIntervalHours,
{
autoplayInterruptionIntervalHours: this.defaultAutoplayInterruptionIntervalHours
}),
3_600_000
)
this.resetAutoplayInterruptionTimeout()
return
}

if (this.watchingPlaylist && this.getPlaylistPauseOnCurrent()) {
this.disablePlaylistPauseOnCurrent()
return
Expand Down Expand Up @@ -1639,6 +1664,12 @@ export default defineComponent({
this.updatePlaylistLastPlayedAt({ _id: playlist._id })
},

resetAutoplayInterruptionTimeout() {
clearTimeout(this.autoplayInterruptionTimeout)
this.autoplayInterruptionTimeout = setTimeout(() => { this.blockVideoAutoplay = true }, this.defaultAutoplayInterruptionIntervalHours * 3_600_000)
this.blockVideoAutoplay = false
},

...mapActions([
'setAppTitle',
'updateHistory',
Expand Down
4 changes: 3 additions & 1 deletion static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ Settings:
Skip by Scrolling Over Video Player: Skip by Scrolling Over Video Player
Display Play Button In Video Player: Display Play Button In Video Player
Enter Fullscreen on Display Rotate: Enter Fullscreen on Display Rotate
Next Video Interval: Next Video Interval
Next Video Interval: Autoplay Countdown Timer
Autoplay Interruption Timer: Autoplay Interruption Timer
Fast-Forward / Rewind Interval: Fast-Forward / Rewind Interval
Default Volume: Default Volume
Default Playback Rate: Default Playback Rate
Expand Down Expand Up @@ -1079,6 +1080,7 @@ Playlist will not pause when current video is finished: Playlist will not pause
Playlist will pause when current video is finished: Playlist will pause when current video is finished
Playing Next Video Interval: Playing next video in no time. Click to cancel. | Playing next video in {nextVideoInterval} second. Click to cancel. | Playing next video in {nextVideoInterval} seconds. Click to cancel.
Canceled next video autoplay: Canceled next video autoplay
Autoplay Interruption Timer: Autoplay canceled due to {autoplayInterruptionIntervalHours} hours of inactivity

Default Invidious instance has been set to {instance}: Default Invidious instance has been set to {instance}
Default Invidious instance has been cleared: Default Invidious instance has been cleared
Expand Down

0 comments on commit b4217ef

Please sign in to comment.