mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-31 15:19:34 +02:00
Improvements and fixes on the cellular permissions
This commit is contained in:
parent
574dda5286
commit
4ad54f34fe
9 changed files with 94 additions and 72 deletions
|
@ -11,6 +11,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { AbsAudioPlayer } from '@/plugins/capacitor'
|
import { AbsAudioPlayer } from '@/plugins/capacitor'
|
||||||
import { Dialog } from '@capacitor/dialog'
|
import { Dialog } from '@capacitor/dialog'
|
||||||
|
import CellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
|
@ -39,6 +40,7 @@ export default {
|
||||||
serverEpisodeId: null
|
serverEpisodeId: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mixins: [CellularPermissionHelpers],
|
||||||
computed: {
|
computed: {
|
||||||
bookmarks() {
|
bookmarks() {
|
||||||
if (!this.serverLibraryItemId) return []
|
if (!this.serverLibraryItemId) return []
|
||||||
|
@ -193,12 +195,21 @@ export default {
|
||||||
const startTime = payload.startTime
|
const startTime = payload.startTime
|
||||||
const startWhenReady = !payload.paused
|
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
|
// 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
|
// then store the server library item id so it can be used if a cast is made
|
||||||
const serverLibraryItemId = payload.serverLibraryItemId || null
|
const serverLibraryItemId = payload.serverLibraryItemId || null
|
||||||
const serverEpisodeId = payload.serverEpisodeId || 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({
|
const { value } = await Dialog.confirm({
|
||||||
title: 'Warning',
|
title: 'Warning',
|
||||||
message: `Cannot cast downloaded media items. Confirm to close cast and play on your device.`
|
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)
|
this.$eventBus.$off('device-focus-update', this.deviceFocused)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
||||||
|
import cellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
@ -73,6 +74,7 @@ export default {
|
||||||
},
|
},
|
||||||
isLocal: Boolean
|
isLocal: Boolean
|
||||||
},
|
},
|
||||||
|
mixins: [cellularPermissionHelpers],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isProcessingReadUpdate: false,
|
isProcessingReadUpdate: false,
|
||||||
|
@ -180,6 +182,9 @@ export default {
|
||||||
async downloadClick() {
|
async downloadClick() {
|
||||||
if (this.downloadItem || this.startingDownload) return
|
if (this.downloadItem || this.startingDownload) return
|
||||||
|
|
||||||
|
const hasPermission = await this.checkCellularPermission('download')
|
||||||
|
if (!hasPermission) return
|
||||||
|
|
||||||
this.startingDownload = true
|
this.startingDownload = true
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.startingDownload = false
|
this.startingDownload = false
|
||||||
|
|
|
@ -60,8 +60,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Dialog } from '@capacitor/dialog'
|
|
||||||
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
||||||
|
import CellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
@ -84,6 +84,7 @@ export default {
|
||||||
processing: false
|
processing: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mixins: [CellularPermissionHelpers],
|
||||||
computed: {
|
computed: {
|
||||||
bookCoverAspectRatio() {
|
bookCoverAspectRatio() {
|
||||||
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
||||||
|
@ -97,15 +98,6 @@ export default {
|
||||||
userCanDownload() {
|
userCanDownload() {
|
||||||
return this.$store.getters['user/getUserCanDownload']
|
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() {
|
audioFile() {
|
||||||
return this.episode.audioFile
|
return this.episode.audioFile
|
||||||
},
|
},
|
||||||
|
@ -195,43 +187,10 @@ export default {
|
||||||
}
|
}
|
||||||
return folderObj
|
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() {
|
async downloadClick() {
|
||||||
if (this.downloadItem || this.pendingDownload) return
|
if (this.downloadItem || this.pendingDownload) return
|
||||||
|
|
||||||
const hasPermission = await this.checkDownloadPermission()
|
const hasPermission = await this.checkCellularPermission('download')
|
||||||
if (!hasPermission) return
|
if (!hasPermission) return
|
||||||
|
|
||||||
this.pendingDownload = true
|
this.pendingDownload = true
|
||||||
|
@ -305,26 +264,13 @@ export default {
|
||||||
if (this.streamIsPlaying) {
|
if (this.streamIsPlaying) {
|
||||||
this.$eventBus.$emit('pause-item')
|
this.$eventBus.$emit('pause-item')
|
||||||
} else {
|
} else {
|
||||||
if (this.localEpisode && this.localLibraryItemId) {
|
this.$store.commit('setPlayerIsStartingPlayback', this.episode.id)
|
||||||
this.$store.commit('setPlayerIsStartingPlayback', this.episode.id)
|
this.$eventBus.$emit('play-item', {
|
||||||
console.log('Play local episode', this.localEpisode.id, this.localLibraryItemId)
|
libraryItemId: this.libraryItemId,
|
||||||
|
episodeId: this.episode.id,
|
||||||
this.$eventBus.$emit('play-item', {
|
serverLibraryItemId: this.libraryItemId,
|
||||||
libraryItemId: this.localLibraryItemId,
|
serverEpisodeId: this.episode.id
|
||||||
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async toggleFinished() {
|
async toggleFinished() {
|
||||||
|
@ -335,7 +281,11 @@ export default {
|
||||||
const isFinished = !this.userIsFinished
|
const isFinished = !this.userIsFinished
|
||||||
const localLibraryItemId = this.isLocal ? this.libraryItemId : this.localLibraryItemId
|
const localLibraryItemId = this.isLocal ? this.libraryItemId : this.localLibraryItemId
|
||||||
const localEpisodeId = this.isLocal ? this.episode.id : this.localEpisode.id
|
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))
|
console.log('toggleFinished payload', JSON.stringify(payload))
|
||||||
if (payload?.error) {
|
if (payload?.error) {
|
||||||
this.$toast.error(payload?.error || 'Unknown error')
|
this.$toast.error(payload?.error || 'Unknown error')
|
||||||
|
|
|
@ -60,6 +60,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
newObject?["downloadUsingCellular"] = "ALWAYS"
|
newObject?["downloadUsingCellular"] = "ALWAYS"
|
||||||
newObject?["streamingUsingCellular"] = "ALWAYS"
|
newObject?["streamingUsingCellular"] = "ALWAYS"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -245,7 +245,7 @@ public class AbsDatabase: CAPPlugin {
|
||||||
let hapticFeedback = call.getString("hapticFeedback") ?? "LIGHT"
|
let hapticFeedback = call.getString("hapticFeedback") ?? "LIGHT"
|
||||||
let languageCode = call.getString("languageCode") ?? "en-us"
|
let languageCode = call.getString("languageCode") ?? "en-us"
|
||||||
let downloadUsingCellular = call.getString("downloadUsingCellular") ?? "ALWAYS"
|
let downloadUsingCellular = call.getString("downloadUsingCellular") ?? "ALWAYS"
|
||||||
let streamingUsingCellular = call.getString("downloadUsingCellular") ?? "ALWAYS"
|
let streamingUsingCellular = call.getString("streamingUsingCellular") ?? "ALWAYS"
|
||||||
let settings = DeviceSettings()
|
let settings = DeviceSettings()
|
||||||
settings.disableAutoRewind = disableAutoRewind
|
settings.disableAutoRewind = disableAutoRewind
|
||||||
settings.enableAltView = enableAltView
|
settings.enableAltView = enableAltView
|
||||||
|
|
42
mixins/cellularPermissionHelpers.js
Normal file
42
mixins/cellularPermissionHelpers.js
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import { Dialog } from '@capacitor/dialog';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
async checkCellularPermission(actionType) {
|
||||||
|
if (this.$store.state.networkConnectionType !== 'cellular') return true
|
||||||
|
|
||||||
|
let permission;
|
||||||
|
if (actionType === 'download') {
|
||||||
|
permission = this.$store.getters['getCanDownloadUsingCellular']
|
||||||
|
if (permission === 'NEVER') {
|
||||||
|
this.$toast.error(this.$strings.ToastDownloadNotAllowedOnCellular)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else if (actionType === 'streaming') {
|
||||||
|
permission = this.$store.getters['getCanStreamingUsingCellular']
|
||||||
|
if (permission === 'NEVER') {
|
||||||
|
this.$toast.error(this.$strings.ToastStreamingNotAllowedOnCellular)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (permission === 'ASK') {
|
||||||
|
const confirmed = await this.confirmAction(actionType)
|
||||||
|
return confirmed
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
async confirmAction(actionType) {
|
||||||
|
const message = actionType === 'download' ?
|
||||||
|
this.$strings.MessageConfirmDownloadUsingCellular :
|
||||||
|
this.$strings.MessageConfirmStreamingUsingCellular
|
||||||
|
|
||||||
|
const { value } = await Dialog.confirm({
|
||||||
|
title: 'Confirm',
|
||||||
|
message
|
||||||
|
})
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,6 +56,7 @@
|
||||||
import { Capacitor } from '@capacitor/core'
|
import { Capacitor } from '@capacitor/core'
|
||||||
import { Dialog } from '@capacitor/dialog'
|
import { Dialog } from '@capacitor/dialog'
|
||||||
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
||||||
|
import cellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async asyncData({ store, params, redirect, app }) {
|
async asyncData({ store, params, redirect, app }) {
|
||||||
|
@ -115,6 +116,7 @@ export default {
|
||||||
startingDownload: false
|
startingDownload: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mixins: [cellularPermissionHelpers],
|
||||||
computed: {
|
computed: {
|
||||||
transformedDescription() {
|
transformedDescription() {
|
||||||
return this.parseDescription(this.description)
|
return this.parseDescription(this.description)
|
||||||
|
@ -419,6 +421,9 @@ export default {
|
||||||
async downloadClick() {
|
async downloadClick() {
|
||||||
if (this.downloadItem || this.startingDownload) return
|
if (this.downloadItem || this.startingDownload) return
|
||||||
|
|
||||||
|
const hasPermission = await this.checkCellularPermission('download')
|
||||||
|
if (!hasPermission) return
|
||||||
|
|
||||||
this.startingDownload = true
|
this.startingDownload = true
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.startingDownload = false
|
this.startingDownload = false
|
||||||
|
|
|
@ -171,6 +171,7 @@
|
||||||
import { Dialog } from '@capacitor/dialog'
|
import { Dialog } from '@capacitor/dialog'
|
||||||
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
|
||||||
import { FastAverageColor } from 'fast-average-color'
|
import { FastAverageColor } from 'fast-average-color'
|
||||||
|
import cellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async asyncData({ store, params, redirect, app, query }) {
|
async asyncData({ store, params, redirect, app, query }) {
|
||||||
|
@ -221,6 +222,7 @@ export default {
|
||||||
startingDownload: false
|
startingDownload: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mixins: [cellularPermissionHelpers],
|
||||||
computed: {
|
computed: {
|
||||||
isIos() {
|
isIos() {
|
||||||
return this.$platform === 'ios'
|
return this.$platform === 'ios'
|
||||||
|
@ -607,9 +609,11 @@ export default {
|
||||||
this.download(localFolder)
|
this.download(localFolder)
|
||||||
},
|
},
|
||||||
async downloadClick() {
|
async downloadClick() {
|
||||||
if (this.downloadItem || this.startingDownload) {
|
if (this.downloadItem || this.startingDownload) return
|
||||||
return
|
|
||||||
}
|
const hasPermission = await this.checkCellularPermission('download')
|
||||||
|
if (!hasPermission) return
|
||||||
|
|
||||||
this.startingDownload = true
|
this.startingDownload = true
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.startingDownload = false
|
this.startingDownload = false
|
||||||
|
|
|
@ -251,8 +251,10 @@
|
||||||
"MessageConfirmDeleteLocalEpisode": "Remove local episode \"{0}\" from your device? The file on the server will be unaffected.",
|
"MessageConfirmDeleteLocalEpisode": "Remove local episode \"{0}\" from your device? The file on the server will be unaffected.",
|
||||||
"MessageConfirmDeleteLocalFiles": "Remove local files of this item from your device? The files on the server and your progress will be unaffected.",
|
"MessageConfirmDeleteLocalFiles": "Remove local files of this item from your device? The files on the server and your progress will be unaffected.",
|
||||||
"MessageConfirmDiscardProgress": "Are you sure you want to reset your progress?",
|
"MessageConfirmDiscardProgress": "Are you sure you want to reset your progress?",
|
||||||
|
"MessageConfirmDownloadUsingCellular": "You are about to download using cellular data. This may include carrier data charges. Do you wish to continue?",
|
||||||
"MessageConfirmMarkAsFinished": "Are you sure you want to mark this item as finished?",
|
"MessageConfirmMarkAsFinished": "Are you sure you want to mark this item as finished?",
|
||||||
"MessageConfirmRemoveBookmark": "Are you sure you want to remove bookmark?",
|
"MessageConfirmRemoveBookmark": "Are you sure you want to remove bookmark?",
|
||||||
|
"MessageConfirmStreamingUsingCellular": "You are about to stream using cellular data. This may include carrier data charges. Do you wish to continue?",
|
||||||
"MessageDiscardProgress": "Discard Progress",
|
"MessageDiscardProgress": "Discard Progress",
|
||||||
"MessageDownloadCompleteProcessing": "Download complete. Processing...",
|
"MessageDownloadCompleteProcessing": "Download complete. Processing...",
|
||||||
"MessageDownloading": "Downloading...",
|
"MessageDownloading": "Downloading...",
|
||||||
|
@ -292,11 +294,13 @@
|
||||||
"ToastBookmarkCreateFailed": "Failed to create bookmark",
|
"ToastBookmarkCreateFailed": "Failed to create bookmark",
|
||||||
"ToastBookmarkRemoveFailed": "Failed to remove bookmark",
|
"ToastBookmarkRemoveFailed": "Failed to remove bookmark",
|
||||||
"ToastBookmarkUpdateFailed": "Failed to update bookmark",
|
"ToastBookmarkUpdateFailed": "Failed to update bookmark",
|
||||||
|
"ToastDownloadNotAllowedOnCellular": "Downloading is not allowed on cellular data",
|
||||||
"ToastItemMarkedAsFinishedFailed": "Failed to mark as Finished",
|
"ToastItemMarkedAsFinishedFailed": "Failed to mark as Finished",
|
||||||
"ToastItemMarkedAsNotFinishedFailed": "Failed to mark as Not Finished",
|
"ToastItemMarkedAsNotFinishedFailed": "Failed to mark as Not Finished",
|
||||||
"ToastPlaylistCreateFailed": "Failed to create playlist",
|
"ToastPlaylistCreateFailed": "Failed to create playlist",
|
||||||
"ToastPodcastCreateFailed": "Failed to create podcast",
|
"ToastPodcastCreateFailed": "Failed to create podcast",
|
||||||
"ToastPodcastCreateSuccess": "Podcast created successfully",
|
"ToastPodcastCreateSuccess": "Podcast created successfully",
|
||||||
"ToastRSSFeedCloseFailed": "Failed to close RSS feed",
|
"ToastRSSFeedCloseFailed": "Failed to close RSS feed",
|
||||||
"ToastRSSFeedCloseSuccess": "RSS feed closed"
|
"ToastRSSFeedCloseSuccess": "RSS feed closed",
|
||||||
|
"ToastStreamingNotAllowedOnCellular": "Streaming is not allowed on cellular data"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue