mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-07 04:18:48 +02:00
Improvements and fixes on the cellular permissions
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
<script>
|
||||
import { AbsAudioPlayer } from '@/plugins/capacitor'
|
||||
import { Dialog } from '@capacitor/dialog'
|
||||
import CellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@@ -39,6 +40,7 @@ export default {
|
||||
serverEpisodeId: null
|
||||
}
|
||||
},
|
||||
mixins: [CellularPermissionHelpers],
|
||||
computed: {
|
||||
bookmarks() {
|
||||
if (!this.serverLibraryItemId) return []
|
||||
@@ -193,12 +195,21 @@ export default {
|
||||
const startTime = payload.startTime
|
||||
const startWhenReady = !payload.paused
|
||||
|
||||
const isLocal = libraryItemId.startsWith('local')
|
||||
if (!isLocal) {
|
||||
const hasPermission = await this.checkCellularPermission('streaming')
|
||||
if (!hasPermission) {
|
||||
this.$store.commit('setPlayerDoneStartingPlayback')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// When playing local library item and can also play this item from the server
|
||||
// then store the server library item id so it can be used if a cast is made
|
||||
const serverLibraryItemId = payload.serverLibraryItemId || null
|
||||
const serverEpisodeId = payload.serverEpisodeId || null
|
||||
|
||||
if (libraryItemId.startsWith('local') && this.$store.state.isCasting) {
|
||||
if (isLocal && this.$store.state.isCasting) {
|
||||
const { value } = await Dialog.confirm({
|
||||
title: 'Warning',
|
||||
message: `Cannot cast downloaded media items. Confirm to close cast and play on your device.`
|
||||
@@ -373,4 +384,4 @@ export default {
|
||||
this.$eventBus.$off('device-focus-update', this.deviceFocused)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
|
||||
<script>
|
||||
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
||||
import cellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
|
||||
|
||||
export default {
|
||||
props: {
|
||||
@@ -73,6 +74,7 @@ export default {
|
||||
},
|
||||
isLocal: Boolean
|
||||
},
|
||||
mixins: [cellularPermissionHelpers],
|
||||
data() {
|
||||
return {
|
||||
isProcessingReadUpdate: false,
|
||||
@@ -180,6 +182,9 @@ export default {
|
||||
async downloadClick() {
|
||||
if (this.downloadItem || this.startingDownload) return
|
||||
|
||||
const hasPermission = await this.checkCellularPermission('download')
|
||||
if (!hasPermission) return
|
||||
|
||||
this.startingDownload = true
|
||||
setTimeout(() => {
|
||||
this.startingDownload = false
|
||||
|
||||
@@ -60,8 +60,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Dialog } from '@capacitor/dialog'
|
||||
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
||||
import CellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
|
||||
|
||||
export default {
|
||||
props: {
|
||||
@@ -84,6 +84,7 @@ export default {
|
||||
processing: false
|
||||
}
|
||||
},
|
||||
mixins: [CellularPermissionHelpers],
|
||||
computed: {
|
||||
bookCoverAspectRatio() {
|
||||
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
||||
@@ -97,15 +98,6 @@ export default {
|
||||
userCanDownload() {
|
||||
return this.$store.getters['user/getUserCanDownload']
|
||||
},
|
||||
canDownloadUsingCellular() {
|
||||
return this.$store.getters['getCanDownloadUsingCellular']
|
||||
},
|
||||
canStreamUsingCellular() {
|
||||
return this.$store.getters['getCanStreamingUsingCellular']
|
||||
},
|
||||
isCellular() {
|
||||
return this.$store.state.networkConnectionType === 'cellular'
|
||||
},
|
||||
audioFile() {
|
||||
return this.episode.audioFile
|
||||
},
|
||||
@@ -195,43 +187,10 @@ export default {
|
||||
}
|
||||
return folderObj
|
||||
},
|
||||
async confirmAction(action) {
|
||||
const { value } = await Dialog.confirm({
|
||||
title: 'Confirm',
|
||||
message: `You are about to ${action} using cellular data. Do you want to proceed?`
|
||||
});
|
||||
return value
|
||||
},
|
||||
async checkDownloadPermission() {
|
||||
if (this.isCellular) {
|
||||
const permission = this.canDownloadUsingCellular
|
||||
if (permission === 'NEVER') {
|
||||
this.$toast.error('Downloading is not allowed on cellular data.')
|
||||
return false
|
||||
} else if (permission === 'ASK') {
|
||||
const confirmed = await this.confirmAction('download')
|
||||
return confirmed
|
||||
}
|
||||
}
|
||||
return true
|
||||
},
|
||||
async checkStreamPermission() {
|
||||
if (this.isCellular) {
|
||||
const permission = this.canStreamUsingCellular
|
||||
if (permission === 'NEVER') {
|
||||
this.$toast.error('Streaming is not allowed on cellular data.')
|
||||
return false
|
||||
} else if (permission === 'ASK') {
|
||||
const confirmed = await this.confirmAction('stream')
|
||||
return confirmed
|
||||
}
|
||||
}
|
||||
return true
|
||||
},
|
||||
async downloadClick() {
|
||||
if (this.downloadItem || this.pendingDownload) return
|
||||
|
||||
const hasPermission = await this.checkDownloadPermission()
|
||||
const hasPermission = await this.checkCellularPermission('download')
|
||||
if (!hasPermission) return
|
||||
|
||||
this.pendingDownload = true
|
||||
@@ -305,26 +264,13 @@ export default {
|
||||
if (this.streamIsPlaying) {
|
||||
this.$eventBus.$emit('pause-item')
|
||||
} else {
|
||||
if (this.localEpisode && this.localLibraryItemId) {
|
||||
this.$store.commit('setPlayerIsStartingPlayback', this.episode.id)
|
||||
console.log('Play local episode', this.localEpisode.id, this.localLibraryItemId)
|
||||
|
||||
this.$eventBus.$emit('play-item', {
|
||||
libraryItemId: this.localLibraryItemId,
|
||||
episodeId: this.localEpisode.id,
|
||||
serverLibraryItemId: this.libraryItemId,
|
||||
serverEpisodeId: this.episode.id
|
||||
})
|
||||
} else {
|
||||
const hasPermission = await this.checkStreamPermission()
|
||||
if (!hasPermission) return
|
||||
|
||||
this.$store.commit('setPlayerIsStartingPlayback', this.episode.id)
|
||||
this.$eventBus.$emit('play-item', {
|
||||
libraryItemId: this.libraryItemId,
|
||||
episodeId: this.episode.id
|
||||
})
|
||||
}
|
||||
this.$store.commit('setPlayerIsStartingPlayback', this.episode.id)
|
||||
this.$eventBus.$emit('play-item', {
|
||||
libraryItemId: this.libraryItemId,
|
||||
episodeId: this.episode.id,
|
||||
serverLibraryItemId: this.libraryItemId,
|
||||
serverEpisodeId: this.episode.id
|
||||
})
|
||||
}
|
||||
},
|
||||
async toggleFinished() {
|
||||
@@ -335,7 +281,11 @@ export default {
|
||||
const isFinished = !this.userIsFinished
|
||||
const localLibraryItemId = this.isLocal ? this.libraryItemId : this.localLibraryItemId
|
||||
const localEpisodeId = this.isLocal ? this.episode.id : this.localEpisode.id
|
||||
const payload = await this.$db.updateLocalMediaProgressFinished({ localLibraryItemId, localEpisodeId, isFinished })
|
||||
const payload = await this.$db.updateLocalMediaProgressFinished({
|
||||
localLibraryItemId,
|
||||
localEpisodeId,
|
||||
isFinished
|
||||
})
|
||||
console.log('toggleFinished payload', JSON.stringify(payload))
|
||||
if (payload?.error) {
|
||||
this.$toast.error(payload?.error || 'Unknown error')
|
||||
|
||||
Reference in New Issue
Block a user