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

feat: Add support for "Open Current Chapter" button #3334

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions client/components/app/MediaPlayerContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ref="audioPlayer"
:chapters="chapters"
:current-chapter="currentChapter"
:libraryItem="streamLibraryItem"
:paused="!isPlaying"
:loading="playerLoading"
:bookmarks="bookmarks"
Expand Down
13 changes: 12 additions & 1 deletion client/components/player/PlayerUi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<ui-tooltip direction="top" :text="$strings.LabelVolume">
<controls-volume-control ref="volumeControl" v-model="volume" @input="setVolume" class="mx-2 hidden sm:block" />
</ui-tooltip>

<ui-tooltip v-if="hasEbookFile" direction="top" :text="$strings.ButtonOpenCurrentChapter">
<button :aria-label="$strings.ButtonOpenCurrentChapter" class="text-gray-300 hover:text-white mx-1 lg:mx-2" @mousedown.prevent @mouseup.prevent @click.stop="openEbook">
<span class="material-symbols text-2xl">auto_stories</span>
</button>
</ui-tooltip>
<ui-tooltip v-if="!hideSleepTimer" direction="top" :text="$strings.LabelSleepTimer">
<button :aria-label="$strings.LabelSleepTimer" class="text-gray-300 hover:text-white mx-1 lg:mx-2" @mousedown.prevent @mouseup.prevent @click.stop="$emit('showSleepTimer')">
<span v-if="!sleepTimerSet" class="material-symbols text-2xl">snooze</span>
Expand Down Expand Up @@ -77,6 +81,7 @@ export default {
type: Array,
default: () => []
},
libraryItem: Object,
sleepTimerSet: Boolean,
sleepTimerRemaining: Number,
sleepTimerType: String,
Expand Down Expand Up @@ -173,6 +178,9 @@ export default {
useChapterTrack() {
const _useChapterTrack = this.$store.getters['user/getUserSetting']('useChapterTrack') || false
return this.chapters.length ? _useChapterTrack : false
},
hasEbookFile() {
return this.libraryItem.media && this.libraryItem.media.ebookFile
}
},
methods: {
Expand Down Expand Up @@ -352,6 +360,9 @@ export default {
else if (action === this.$hotkeys.AudioPlayer.INCREASE_PLAYBACK_RATE) this.increasePlaybackRate()
else if (action === this.$hotkeys.AudioPlayer.DECREASE_PLAYBACK_RATE) this.decreasePlaybackRate()
else if (action === this.$hotkeys.AudioPlayer.CLOSE) this.closePlayer()
},
openEbook() {
this.$store.commit('showEReader', { libraryItem: this.libraryItem, keepProgress: true })
}
},
mounted() {
Expand Down
53 changes: 48 additions & 5 deletions client/components/readers/EpubReader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export default {
})
}
},
initEpub() {
async initEpub() {
/** @type {EpubReader} */
const reader = this

Expand All @@ -330,8 +330,26 @@ export default {
flow: 'paginated'
})

// load saved progress
reader.rendition.display(this.savedEbookLocation || reader.book.locations.start)
await reader.book.ready
// load saved progress or initial chapter
var initialLocation = this.savedEbookLocation || this.initialChapterHref || reader.book.locations.start
try {
const initialChapterTitle = this.getCurrentAudioChapter()
if (initialChapterTitle) {
const href = this.findChapterHref(initialChapterTitle)
if (href) {
try {
initialLocation = 'text/' + href
} catch (error) {
console.error('Failed to navigate to chapter:', error)
}
}
}
} catch (error) {
return
}

reader.rendition.display(initialLocation)

reader.rendition.on('rendered', () => {
this.applyTheme()
Expand Down Expand Up @@ -439,13 +457,38 @@ export default {
this.rendition.getContents().forEach((c) => {
c.addStylesheetRules(this.themeRules)
})
},
getCurrentAudioChapter() {
try {
var currentTime = this.$store.getters['user/getUserMediaProgress'](this.libraryItemId).currentTime
var audioBookChapters = this.$store.state.streamLibraryItem.media.chapters
} catch (error) {
return null
}
if (!audioBookChapters) return null
const chapter = audioBookChapters.find((chapter) => chapter.start <= currentTime && currentTime < chapter.end)
return chapter.title || audioBookChapters[audioBookChapters.length - 1].title
},
findChapterHref(title) {
const findInToc = (items) => {
for (let item of items) {
if (item.label.trim() === title) return item.href
if (item.subitems) {
const result = findInToc(item.subitems)
if (result) return result
}
}
return null
}
return findInToc(this.rendition.book.navigation.toc)
}
},
mounted() {
async mounted() {
this.windowWidth = window.innerWidth
this.windowHeight = window.innerHeight
window.addEventListener('resize', this.resize)
this.initEpub()

await this.initEpub()
},
beforeDestroy() {
window.removeEventListener('resize', this.resize)
Expand Down
1 change: 1 addition & 0 deletions client/strings/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Следваща Глава",
"ButtonOk": "Добре",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Отвори Feed",
"ButtonOpenManager": "Отвори Мениджър",
"ButtonPause": "Пауза",
Expand Down
1 change: 1 addition & 0 deletions client/strings/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "পরবর্তী",
"ButtonNextChapter": "পরবর্তী অধ্যায়",
"ButtonOk": "ঠিক আছে",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "ফিড খুলুন",
"ButtonOpenManager": "ম্যানেজার খুলুন",
"ButtonPause": "বিরতি",
Expand Down
1 change: 1 addition & 0 deletions client/strings/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Další Kapitola",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Otevřít kanál",
"ButtonOpenManager": "Otevřít správce",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Next Chapter",
"ButtonOk": "OK",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Åbn feed",
"ButtonOpenManager": "Åbn manager",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Vor",
"ButtonNextChapter": "Nächstes Kapitel",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Feed öffnen",
"ButtonOpenManager": "Manager öffnen",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"ButtonNextChapter": "Next Chapter",
"ButtonNextItemInQueue": "Next Item in Queue",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
Copy link
Contributor

Choose a reason for hiding this comment

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

We only want to add the string to the English file, not all of the other files unless you know the translation (Weblate will handle the other languages)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do i undo all the changes? do i just undo locally and commit again?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you did all of the changes in one commit you can do git revert [SHA], or checkout the files from a specific commit and then do another commit, or undo it manually.

Thanks for doing that, it makes it easier to review the changes. :)

"ButtonOpenFeed": "Open Feed",
"ButtonOpenManager": "Open Manager",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Siguiente Capítulo",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Abrir fuente",
"ButtonOpenManager": "Abrir Editor",
"ButtonPause": "Pausar",
Expand Down
1 change: 1 addition & 0 deletions client/strings/et.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Järgmine peatükk",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Ava voog",
"ButtonOpenManager": "Ava haldur",
"ButtonPause": "Peata",
Expand Down
1 change: 1 addition & 0 deletions client/strings/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Seuraava",
"ButtonNextChapter": "Seuraava luku",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Avaa syöte",
"ButtonOpenManager": "Avaa hallinta",
"ButtonPause": "Pysäytä",
Expand Down
1 change: 1 addition & 0 deletions client/strings/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Suivant",
"ButtonNextChapter": "Chapitre suivant",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Ouvrir le flux",
"ButtonOpenManager": "Ouvrir le gestionnaire",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/gu.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Next Chapter",
"ButtonOk": "ઓકે",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "ફીડ ખોલો",
"ButtonOpenManager": "મેનેજર ખોલો",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "הבא",
"ButtonNextChapter": "פרק הבא",
"ButtonOk": "אישור",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "פתח פיד",
"ButtonOpenManager": "פתח מנהל",
"ButtonPause": "השהה",
Expand Down
1 change: 1 addition & 0 deletions client/strings/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Next Chapter",
"ButtonOk": "ठीक है",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "फ़ीड खोलें",
"ButtonOpenManager": "मैनेजर खोलें",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/hr.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Next Chapter",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Otvori feed",
"ButtonOpenManager": "Otvori menadžera",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Következő fejezet",
"ButtonOk": "Oké",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Hírcsatorna megnyitása",
"ButtonOpenManager": "Kezelő megnyitása",
"ButtonPause": "Szünet",
Expand Down
1 change: 1 addition & 0 deletions client/strings/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Prossimo",
"ButtonNextChapter": "Prossimo Capitolo",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Apri il flusso",
"ButtonOpenManager": "Apri Manager",
"ButtonPause": "Pausa",
Expand Down
1 change: 1 addition & 0 deletions client/strings/lt.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Kitas Skyrius",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Atidaryti srautą",
"ButtonOpenManager": "Atidaryti tvarkyklę",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Volgende",
"ButtonNextChapter": "Volgend hoofdstuk",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Feed openen",
"ButtonOpenManager": "Manager openen",
"ButtonPause": "Pauze",
Expand Down
1 change: 1 addition & 0 deletions client/strings/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Neste Kapittel",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Åpne Feed",
"ButtonOpenManager": "Åpne behandler",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Następny",
"ButtonNextChapter": "Następny rozdział",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Otwórz feed",
"ButtonOpenManager": "Otwórz menadżera",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Próximo",
"ButtonNextChapter": "Próximo Capítulo",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Abrir Feed",
"ButtonOpenManager": "Abrir Gerenciador",
"ButtonPause": "Pausar",
Expand Down
1 change: 1 addition & 0 deletions client/strings/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Следующая глава",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Открыть канал",
"ButtonOpenManager": "Открыть менеджер",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Next",
"ButtonNextChapter": "Next Chapter",
"ButtonOk": "Okej",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Öppna flöde",
"ButtonOpenManager": "Öppna Manager",
"ButtonPause": "Pause",
Expand Down
1 change: 1 addition & 0 deletions client/strings/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Наступний",
"ButtonNextChapter": "Наступна глава",
"ButtonOk": "Гаразд",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Відкрити стрічку",
"ButtonOpenManager": "Відкрити менеджер",
"ButtonPause": "Пауза",
Expand Down
1 change: 1 addition & 0 deletions client/strings/vi-vn.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "Tiếp Theo",
"ButtonNextChapter": "Chương Tiếp Theo",
"ButtonOk": "Ok",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "Mở Feed",
"ButtonOpenManager": "Mở Quản Lý",
"ButtonPause": "Tạm Dừng",
Expand Down
1 change: 1 addition & 0 deletions client/strings/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "下一个",
"ButtonNextChapter": "下一章节",
"ButtonOk": "确定",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "打开源",
"ButtonOpenManager": "打开管理器",
"ButtonPause": "暂停",
Expand Down
1 change: 1 addition & 0 deletions client/strings/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ButtonNext": "下個",
"ButtonNextChapter": "下個章節",
"ButtonOk": "確定",
"ButtonOpenCurrentChapter": "Open Current Chapter",
"ButtonOpenFeed": "打開源",
"ButtonOpenManager": "打開管理器",
"ButtonPause": "暫停",
Expand Down
Loading