From d899fd4d893def90f5d5e7baf23bcc73f453da30 Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 17 Feb 2023 17:14:49 -0600 Subject: [PATCH] Android & iOS only open most recent session on first load --- components/app/AudioPlayerContainer.vue | 12 ++++++++++-- pages/bookshelf/index.vue | 13 +++++++++---- store/index.js | 4 ++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/components/app/AudioPlayerContainer.vue b/components/app/AudioPlayerContainer.vue index 2cd17531..436d3058 100644 --- a/components/app/AudioPlayerContainer.vue +++ b/components/app/AudioPlayerContainer.vue @@ -43,6 +43,9 @@ export default { bookmarks() { if (!this.serverLibraryItemId) return [] return this.$store.getters['user/getUserBookmarksForItem'](this.serverLibraryItemId) + }, + isIos() { + return this.$platform === 'ios' } }, methods: { @@ -266,12 +269,17 @@ export default { onReady() { // The UI is reporting elsewhere we are ready this.isReady = true - this.notifyOnReady() + + // TODO: iOS opens last active playback session on app launch. Should be consistent with Android + if (this.isIos) { + this.notifyOnReady() + } }, notifyOnReady() { // If settings aren't loaded yet, native player will receive incorrect settings console.log('Notify on ready... settingsLoaded:', this.settingsLoaded, 'isReady:', this.isReady) - if (this.settingsLoaded && this.isReady) { + if (this.settingsLoaded && this.isReady && this.$store.state.isFirstAudioLoad) { + this.$store.commit('setIsFirstAudioLoad', false) // Only run this once on app launch AbsAudioPlayer.onReady() } } diff --git a/pages/bookshelf/index.vue b/pages/bookshelf/index.vue index 14770ec6..feadbc14 100644 --- a/pages/bookshelf/index.vue +++ b/pages/bookshelf/index.vue @@ -39,7 +39,6 @@ export default { shelves: [], loading: false, isFirstNetworkConnection: true, - isFirstAutoOpenPlayer: true, lastServerFetch: 0, lastServerFetchLibraryId: null, lastLocalFetch: 0, @@ -78,6 +77,9 @@ export default { networkConnected() { return this.$store.state.networkConnected }, + isIos() { + return this.$platform === 'ios' + }, currentLibraryName() { return this.$store.getters['libraries/getCurrentLibraryName'] }, @@ -248,7 +250,10 @@ export default { return cat }) - this.openMediaPlayerWithMostRecentListening() + // TODO: iOS has its own implementation of this. Android & iOS should be consistent here. + if (!this.isIos) { + this.openMediaPlayerWithMostRecentListening() + } // Only add the local shelf with the same media type const localShelves = localCategories.filter((cat) => cat.type === this.currentLibraryMediaType && !cat.localOnly) @@ -267,8 +272,8 @@ export default { openMediaPlayerWithMostRecentListening() { // If we don't already have a player open // Try opening the first book from continue-listening without playing it - if (this.$store.state.playerLibraryItemId || !this.isFirstAutoOpenPlayer) return - this.isFirstAutoOpenPlayer = false // Only run this once, not on every library change + if (this.$store.state.playerLibraryItemId || !this.$store.state.isFirstAudioLoad) return + this.$store.commit('setIsFirstAudioLoad', false) // Only run this once on app launch const continueListeningShelf = this.shelves.find((cat) => cat.id === 'continue-listening') const mostRecentEntity = continueListeningShelf?.entities?.[0] diff --git a/store/index.js b/store/index.js index d98750ee..f4e21dbd 100644 --- a/store/index.js +++ b/store/index.js @@ -15,6 +15,7 @@ export const state = () => ({ networkConnectionType: null, isNetworkUnmetered: true, isFirstLoad: true, + isFirstAudioLoad: true, hasStoragePermission: false, selectedLibraryItem: null, showReader: false, @@ -120,6 +121,9 @@ export const mutations = { setIsFirstLoad(state, val) { state.isFirstLoad = val }, + setIsFirstAudioLoad(state, val) { + state.isFirstAudioLoad = val + }, setSocketConnected(state, val) { state.socketConnected = val },