Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoplay time limit #5871

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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)
kommunarr marked this conversation as resolved.
Show resolved Hide resolved

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
)
Comment on lines +1255 to +1256
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised that linter is ok with this o_0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It not only tolerates it: it enforces it to be like that. ¯\(ツ)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason that is happening is because showToast( and this.$t( are both on the same line, so the linter sees this.$t as having one level of indentation and showToast as having none. That is why it forcing 3_600_000 and ) to have no indentation.

Moving this.$t to its own line fixes the issue, as then the linter allows them both to have indentation:
screenshot-of-fixed-formatting

It would also improve the general readability of that code snippet if the placeholder name in the translation string weren't so long e.g. {hours} would already suffice, as there is only one placeholder in that string and there is enough context in the string and the code where it is used, to understand what the purpose of the placeholder is.

However as both things are stylistic issues and don't influence the functionality of the code, we can leave the cleanup for some future pull request.

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([
'updateHistory',
'updateWatchProgress',
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 @@ -402,7 +402,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 @@ -1056,6 +1057,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
Loading