2021-10-17 20:20:00 -05:00
|
|
|
<template>
|
2023-06-01 17:19:16 -05:00
|
|
|
<div v-if="show" class="absolute top-0 left-0 w-full h-full bg-primary z-40 pt-18" :class="{ 'reader-player-open': !!playerLibraryItemId }">
|
|
|
|
<div class="h-18 pt-10 w-full flex bg-bg items-center px-2 fixed top-0 left-0 z-30">
|
2021-10-17 20:20:00 -05:00
|
|
|
<p class="w-5/6 truncate">{{ title }}</p>
|
|
|
|
<div class="flex-grow" />
|
|
|
|
<span class="material-icons text-xl text-white" @click.stop="show = false">close</span>
|
|
|
|
</div>
|
2023-05-21 15:02:49 -05:00
|
|
|
<component v-if="readerComponentName" ref="readerComponent" :is="readerComponentName" :url="ebookUrl" :library-item="selectedLibraryItem" :is-local="isLocal" />
|
2021-10-17 20:20:00 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-21 15:02:49 -05:00
|
|
|
import { Capacitor } from '@capacitor/core'
|
|
|
|
|
2021-10-17 20:20:00 -05:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
touchstartX: 0,
|
2022-12-06 17:07:27 -06:00
|
|
|
touchstartY: 0,
|
|
|
|
touchendX: 0,
|
|
|
|
touchendY: 0,
|
|
|
|
touchstartTime: 0
|
2021-10-17 20:20:00 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
show: {
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.registerListeners()
|
|
|
|
} else {
|
|
|
|
this.unregisterListeners()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get() {
|
|
|
|
return this.$store.state.showReader
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$store.commit('setShowReader', val)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
title() {
|
2022-04-16 06:10:10 -05:00
|
|
|
return this.mediaMetadata.title || 'No Title'
|
2021-10-17 20:20:00 -05:00
|
|
|
},
|
2022-04-16 06:10:10 -05:00
|
|
|
selectedLibraryItem() {
|
|
|
|
return this.$store.state.selectedLibraryItem
|
|
|
|
},
|
|
|
|
media() {
|
2023-06-04 11:13:05 -05:00
|
|
|
return this.selectedLibraryItem?.media || null
|
2022-04-16 06:10:10 -05:00
|
|
|
},
|
|
|
|
mediaMetadata() {
|
2023-06-04 11:13:05 -05:00
|
|
|
return this.media?.metadata || {}
|
2021-10-17 20:20:00 -05:00
|
|
|
},
|
|
|
|
readerComponentName() {
|
|
|
|
if (this.ebookType === 'epub') return 'readers-epub-reader'
|
|
|
|
else if (this.ebookType === 'mobi') return 'readers-mobi-reader'
|
|
|
|
else if (this.ebookType === 'comic') return 'readers-comic-reader'
|
2022-12-06 17:07:27 -06:00
|
|
|
else if (this.ebookType === 'pdf') return 'readers-pdf-reader'
|
2021-10-17 20:20:00 -05:00
|
|
|
return null
|
|
|
|
},
|
2022-04-16 06:10:10 -05:00
|
|
|
ebookFile() {
|
2023-05-21 15:02:49 -05:00
|
|
|
return this.media?.ebookFile || null
|
2022-04-16 06:10:10 -05:00
|
|
|
},
|
|
|
|
ebookFormat() {
|
2023-05-21 15:02:49 -05:00
|
|
|
return this.ebookFile?.ebookFormat || null
|
2022-04-16 06:10:10 -05:00
|
|
|
},
|
|
|
|
ebookType() {
|
|
|
|
if (this.isMobi) return 'mobi'
|
|
|
|
else if (this.isEpub) return 'epub'
|
|
|
|
else if (this.isPdf) return 'pdf'
|
|
|
|
else if (this.isComic) return 'comic'
|
|
|
|
return null
|
|
|
|
},
|
|
|
|
isEpub() {
|
|
|
|
return this.ebookFormat == 'epub'
|
|
|
|
},
|
|
|
|
isMobi() {
|
|
|
|
return this.ebookFormat == 'mobi' || this.ebookFormat == 'azw3'
|
2021-10-17 20:20:00 -05:00
|
|
|
},
|
2022-04-16 06:10:10 -05:00
|
|
|
isPdf() {
|
|
|
|
return this.ebookFormat == 'pdf'
|
|
|
|
},
|
|
|
|
isComic() {
|
|
|
|
return this.ebookFormat == 'cbz' || this.ebookFormat == 'cbr'
|
|
|
|
},
|
2023-05-21 15:02:49 -05:00
|
|
|
isLocal() {
|
|
|
|
return !!this.ebookFile?.isLocal
|
|
|
|
},
|
|
|
|
localContentUrl() {
|
|
|
|
return this.ebookFile?.contentUrl
|
|
|
|
},
|
2022-04-16 06:10:10 -05:00
|
|
|
ebookUrl() {
|
|
|
|
if (!this.ebookFile) return null
|
2023-05-21 15:02:49 -05:00
|
|
|
if (this.localContentUrl) {
|
|
|
|
return Capacitor.convertFileSrc(this.localContentUrl)
|
|
|
|
}
|
2022-12-06 17:07:27 -06:00
|
|
|
const serverAddress = this.$store.getters['user/getServerAddress']
|
2023-06-04 11:13:05 -05:00
|
|
|
return `${serverAddress}/api/items/${this.selectedLibraryItem.id}/ebook`
|
2022-12-04 08:29:55 -06:00
|
|
|
},
|
|
|
|
playerLibraryItemId() {
|
|
|
|
return this.$store.state.playerLibraryItemId
|
2021-10-17 20:20:00 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
next() {
|
|
|
|
if (this.$refs.readerComponent && this.$refs.readerComponent.next) {
|
|
|
|
this.$refs.readerComponent.next()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
prev() {
|
|
|
|
if (this.$refs.readerComponent && this.$refs.readerComponent.prev) {
|
|
|
|
this.$refs.readerComponent.prev()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleGesture() {
|
2022-12-06 17:07:27 -06:00
|
|
|
// Touch must be less than 1s. Must be > 100px drag and X distance > Y distance
|
|
|
|
const touchTimeMs = Date.now() - this.touchstartTime
|
|
|
|
if (touchTimeMs >= 1000) {
|
|
|
|
console.log('Touch too long', touchTimeMs)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const touchDistanceX = Math.abs(this.touchendX - this.touchstartX)
|
|
|
|
const touchDistanceY = Math.abs(this.touchendY - this.touchstartY)
|
2023-03-06 10:58:08 -06:00
|
|
|
if (touchDistanceX < 60 || touchDistanceY > touchDistanceX) {
|
|
|
|
return
|
|
|
|
}
|
2022-12-06 17:07:27 -06:00
|
|
|
|
2021-10-17 20:20:00 -05:00
|
|
|
if (this.touchendX < this.touchstartX) {
|
|
|
|
console.log('swiped left')
|
|
|
|
this.next()
|
|
|
|
}
|
|
|
|
if (this.touchendX > this.touchstartX) {
|
|
|
|
console.log('swiped right')
|
|
|
|
this.prev()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
touchstart(e) {
|
2023-03-06 10:58:08 -06:00
|
|
|
this.touchstartX = e.touches[0].screenX
|
|
|
|
this.touchstartY = e.touches[0].screenY
|
2022-12-06 17:07:27 -06:00
|
|
|
this.touchstartTime = Date.now()
|
2021-10-17 20:20:00 -05:00
|
|
|
},
|
|
|
|
touchend(e) {
|
|
|
|
this.touchendX = e.changedTouches[0].screenX
|
2022-12-06 17:07:27 -06:00
|
|
|
this.touchendY = e.changedTouches[0].screenY
|
2021-10-17 20:20:00 -05:00
|
|
|
this.handleGesture()
|
|
|
|
},
|
2023-06-04 15:38:26 -05:00
|
|
|
closeEvt() {
|
|
|
|
this.show = false
|
|
|
|
},
|
2021-10-17 20:20:00 -05:00
|
|
|
registerListeners() {
|
2023-06-04 15:38:26 -05:00
|
|
|
this.$eventBus.$on('close-ebook', this.closeEvt)
|
2021-10-17 20:20:00 -05:00
|
|
|
document.body.addEventListener('touchstart', this.touchstart)
|
|
|
|
document.body.addEventListener('touchend', this.touchend)
|
|
|
|
},
|
|
|
|
unregisterListeners() {
|
2023-06-04 15:38:26 -05:00
|
|
|
this.$eventBus.$on('close-ebook', this.closeEvt)
|
2021-10-17 20:20:00 -05:00
|
|
|
document.body.removeEventListener('touchstart', this.touchstart)
|
|
|
|
document.body.removeEventListener('touchend', this.touchend)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.unregisterListeners()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|