From 41e39654678496eacf5bb67f6a22bda74cbd3e58 Mon Sep 17 00:00:00 2001 From: Greg Lorenzen Date: Thu, 11 Jul 2024 17:36:31 +0000 Subject: [PATCH 1/6] Add SleepTimerTypes for countdown and chapter --- client/plugins/constants.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/plugins/constants.js b/client/plugins/constants.js index f001f6ced..d89fbbbd6 100644 --- a/client/plugins/constants.js +++ b/client/plugins/constants.js @@ -32,12 +32,18 @@ const PlayMethod = { LOCAL: 3 } +const SleepTimerTypes = { + COUNTDOWN: 'countdown', + CHAPTER: 'chapter' +} + const Constants = { SupportedFileTypes, DownloadStatus, BookCoverAspectRatio, BookshelfView, - PlayMethod + PlayMethod, + SleepTimerTypes } const KeyNames = { From cd902c06365732508e60c26cdce4fbf485bdc6ff Mon Sep 17 00:00:00 2001 From: Greg Lorenzen Date: Thu, 11 Jul 2024 17:37:02 +0000 Subject: [PATCH 2/6] Add functionality for 'end of chapter' sleep timer --- .../components/app/MediaPlayerContainer.vue | 45 +++++++++++++++---- client/components/modals/SleepTimerModal.vue | 36 +++++++++------ client/components/player/PlayerUi.vue | 4 +- 3 files changed, 61 insertions(+), 24 deletions(-) diff --git a/client/components/app/MediaPlayerContainer.vue b/client/components/app/MediaPlayerContainer.vue index 3c99a6da6..1f6846541 100644 --- a/client/components/app/MediaPlayerContainer.vue +++ b/client/components/app/MediaPlayerContainer.vue @@ -35,6 +35,7 @@ chapter.start <= this.currentTime && this.currentTime < chapter.end) + }, title() { if (this.playerHandler.displayTitle) return this.playerHandler.displayTitle return this.mediaMetadata.title || 'No Title' @@ -204,14 +216,19 @@ export default { this.$store.commit('setIsPlaying', isPlaying) this.updateMediaSessionPlaybackState() }, - setSleepTimer(seconds) { + setSleepTimer(time) { this.sleepTimerSet = true - this.sleepTimerTime = seconds - this.sleepTimerRemaining = seconds - this.runSleepTimer() this.showSleepTimerModal = false + + this.sleepTimerType = time.timerType + if (this.sleepTimerType === this.$constants.SleepTimerTypes.COUNTDOWN) { + this.runSleepTimer(time) + } }, - runSleepTimer() { + runSleepTimer(time) { + this.sleepTimerTime = time.seconds + this.sleepTimerRemaining = time.seconds + var lastTick = Date.now() clearInterval(this.sleepTimer) this.sleepTimer = setInterval(() => { @@ -220,12 +237,23 @@ export default { this.sleepTimerRemaining -= elapsed / 1000 if (this.sleepTimerRemaining <= 0) { - this.clearSleepTimer() - this.playerHandler.pause() - this.$toast.info('Sleep Timer Done.. zZzzZz') + this.sleepTimerEnd() } }, 1000) }, + checkChapterEnd(time) { + const chapterEndTime = this.currentChapter.end + const tolerance = 0.5 + if (time >= chapterEndTime - tolerance) { + console.log('Chapter end reached', time, chapterEndTime) + this.sleepTimerEnd() + } + }, + sleepTimerEnd() { + this.clearSleepTimer() + this.playerHandler.pause() + this.$toast.info('Sleep Timer Done.. zZzzZz') + }, cancelSleepTimer() { this.showSleepTimerModal = false this.clearSleepTimer() @@ -235,6 +263,7 @@ export default { this.sleepTimerRemaining = 0 this.sleepTimer = null this.sleepTimerSet = false + this.sleepTimerType = null }, incrementSleepTimer(amount) { if (!this.sleepTimerSet) return diff --git a/client/components/modals/SleepTimerModal.vue b/client/components/modals/SleepTimerModal.vue index 051c5d3d7..626883cae 100644 --- a/client/components/modals/SleepTimerModal.vue +++ b/client/components/modals/SleepTimerModal.vue @@ -9,7 +9,7 @@
@@ -48,7 +48,8 @@ export default { value: Boolean, timerSet: Boolean, timerTime: Number, - remaining: Number + remaining: Number, + currentChapter: Object }, data() { return { @@ -56,36 +57,45 @@ export default { sleepTimes: [ { seconds: 60 * 5, - text: '5 minutes' + text: '5 minutes', + timerType: this.$constants.SleepTimerTypes.COUNTDOWN }, { seconds: 60 * 15, - text: '15 minutes' + text: '15 minutes', + timerType: this.$constants.SleepTimerTypes.COUNTDOWN }, { seconds: 60 * 20, - text: '20 minutes' + text: '20 minutes', + timerType: this.$constants.SleepTimerTypes.COUNTDOWN }, { seconds: 60 * 30, - text: '30 minutes' + text: '30 minutes', + timerType: this.$constants.SleepTimerTypes.COUNTDOWN }, { seconds: 60 * 45, - text: '45 minutes' + text: '45 minutes', + timerType: this.$constants.SleepTimerTypes.COUNTDOWN }, { seconds: 60 * 60, - text: '60 minutes' + text: '60 minutes', + timerType: this.$constants.SleepTimerTypes.COUNTDOWN }, { seconds: 60 * 90, - text: '90 minutes' + text: '90 minutes', + timerType: this.$constants.SleepTimerTypes.COUNTDOWN }, { seconds: 60 * 120, - text: '2 hours' - } + text: '2 hours', + timerType: this.$constants.SleepTimerTypes.COUNTDOWN + }, + { seconds: -1, text: 'End of chapter', timerType: this.$constants.SleepTimerTypes.CHAPTER } ] } }, @@ -115,8 +125,8 @@ export default { const timeInSeconds = Math.round(Number(this.customTime) * 60) this.setTime(timeInSeconds) }, - setTime(seconds) { - this.$emit('set', seconds) + setTime(time) { + this.$emit('set', time) }, increment(amount) { this.$emit('increment', amount) diff --git a/client/components/player/PlayerUi.vue b/client/components/player/PlayerUi.vue index 3093975f6..058c6e116 100644 --- a/client/components/player/PlayerUi.vue +++ b/client/components/player/PlayerUi.vue @@ -72,6 +72,7 @@ export default { type: Array, default: () => [] }, + currentChapter: Object, bookmarks: { type: Array, default: () => [] @@ -135,9 +136,6 @@ export default { if (!duration) return 0 return Math.round((100 * time) / duration) }, - currentChapter() { - return this.chapters.find((chapter) => chapter.start <= this.currentTime && this.currentTime < chapter.end) - }, currentChapterName() { return this.currentChapter ? this.currentChapter.title : '' }, From b989b9fa4cd9f1676c967a924c9a99225ececcbd Mon Sep 17 00:00:00 2001 From: Greg Lorenzen Date: Thu, 11 Jul 2024 17:57:24 +0000 Subject: [PATCH 3/6] Fix custom time for sleep timer --- client/components/modals/SleepTimerModal.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/components/modals/SleepTimerModal.vue b/client/components/modals/SleepTimerModal.vue index 626883cae..dc4346c70 100644 --- a/client/components/modals/SleepTimerModal.vue +++ b/client/components/modals/SleepTimerModal.vue @@ -123,7 +123,11 @@ export default { } const timeInSeconds = Math.round(Number(this.customTime) * 60) - this.setTime(timeInSeconds) + const time = { + seconds: timeInSeconds, + timerType: this.$constants.SleepTimerTypes.COUNTDOWN + } + this.setTime(time) }, setTime(time) { this.$emit('set', time) From aa2c13262149f5b15ac2f5f0e3416079a99bb4d4 Mon Sep 17 00:00:00 2001 From: Greg Lorenzen Date: Thu, 11 Jul 2024 21:13:00 +0000 Subject: [PATCH 4/6] Include end of chapter string for sleep timer --- .../components/app/MediaPlayerContainer.vue | 1 + client/components/player/PlayerUi.vue | 23 +++++++++++-------- client/strings/en-us.json | 1 + 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/client/components/app/MediaPlayerContainer.vue b/client/components/app/MediaPlayerContainer.vue index 1f6846541..f13fd840e 100644 --- a/client/components/app/MediaPlayerContainer.vue +++ b/client/components/app/MediaPlayerContainer.vue @@ -41,6 +41,7 @@ :bookmarks="bookmarks" :sleep-timer-set="sleepTimerSet" :sleep-timer-remaining="sleepTimerRemaining" + :sleep-timer-type="sleepTimerType" :is-podcast="isPodcast" @playPause="playPause" @jumpForward="jumpForward" diff --git a/client/components/player/PlayerUi.vue b/client/components/player/PlayerUi.vue index 058c6e116..6db91d824 100644 --- a/client/components/player/PlayerUi.vue +++ b/client/components/player/PlayerUi.vue @@ -79,6 +79,7 @@ export default { }, sleepTimerSet: Boolean, sleepTimerRemaining: Number, + sleepTimerType: String, isPodcast: Boolean, hideBookmarks: Boolean, hideSleepTimer: Boolean @@ -102,16 +103,20 @@ export default { }, computed: { sleepTimerRemainingString() { - var rounded = Math.round(this.sleepTimerRemaining) - if (rounded < 90) { - return `${rounded}s` + if (this.sleepTimerType === this.$constants.SleepTimerTypes.CHAPTER) { + return this.$strings.LabelEndOfChapter + } else { + var rounded = Math.round(this.sleepTimerRemaining) + if (rounded < 90) { + return `${rounded}s` + } + var minutesRounded = Math.round(rounded / 60) + if (minutesRounded < 90) { + return `${minutesRounded}m` + } + var hoursRounded = Math.round(minutesRounded / 60) + return `${hoursRounded}h` } - var minutesRounded = Math.round(rounded / 60) - if (minutesRounded < 90) { - return `${minutesRounded}m` - } - var hoursRounded = Math.round(minutesRounded / 60) - return `${hoursRounded}h` }, token() { return this.$store.getters['user/getToken'] diff --git a/client/strings/en-us.json b/client/strings/en-us.json index f713cb11d..7c8672495 100644 --- a/client/strings/en-us.json +++ b/client/strings/en-us.json @@ -290,6 +290,7 @@ "LabelEmbeddedCover": "Embedded Cover", "LabelEnable": "Enable", "LabelEnd": "End", + "LabelEndOfChapter": "End of Chapter", "LabelEpisode": "Episode", "LabelEpisodeTitle": "Episode Title", "LabelEpisodeType": "Episode Type", From 549d0770e277ff1c39d0160a95a2dc897c3735d7 Mon Sep 17 00:00:00 2001 From: Greg Lorenzen Date: Thu, 11 Jul 2024 21:35:32 +0000 Subject: [PATCH 5/6] Increase chapter end tolerance to 0.75 --- client/components/app/MediaPlayerContainer.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/components/app/MediaPlayerContainer.vue b/client/components/app/MediaPlayerContainer.vue index f13fd840e..e6fae07bc 100644 --- a/client/components/app/MediaPlayerContainer.vue +++ b/client/components/app/MediaPlayerContainer.vue @@ -244,9 +244,8 @@ export default { }, checkChapterEnd(time) { const chapterEndTime = this.currentChapter.end - const tolerance = 0.5 + const tolerance = 0.75 if (time >= chapterEndTime - tolerance) { - console.log('Chapter end reached', time, chapterEndTime) this.sleepTimerEnd() } }, From 63541ffb73cc63bbbfb58bef9c64ff16d661907c Mon Sep 17 00:00:00 2001 From: Greg Lorenzen Date: Fri, 12 Jul 2024 00:31:08 +0000 Subject: [PATCH 6/6] Show sleep time options in modal when timer is active --- client/components/app/MediaPlayerContainer.vue | 2 +- client/components/modals/SleepTimerModal.vue | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/client/components/app/MediaPlayerContainer.vue b/client/components/app/MediaPlayerContainer.vue index e6fae07bc..2c8a63ff3 100644 --- a/client/components/app/MediaPlayerContainer.vue +++ b/client/components/app/MediaPlayerContainer.vue @@ -57,7 +57,7 @@ - +
diff --git a/client/components/modals/SleepTimerModal.vue b/client/components/modals/SleepTimerModal.vue index dc4346c70..11ca7f51d 100644 --- a/client/components/modals/SleepTimerModal.vue +++ b/client/components/modals/SleepTimerModal.vue @@ -7,7 +7,7 @@
-
+