mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-06-26 23:28:42 +02:00
Update:Remove call to server for settings filter/sort/playback rate
This commit is contained in:
parent
4fd4cc5604
commit
0890a44c0b
8 changed files with 52 additions and 75 deletions
|
@ -273,7 +273,7 @@ export default {
|
||||||
this.$eventBus.$on('pause-item', this.pauseItem)
|
this.$eventBus.$on('pause-item', this.pauseItem)
|
||||||
this.$eventBus.$on('close-stream', this.closeStreamOnly)
|
this.$eventBus.$on('close-stream', this.closeStreamOnly)
|
||||||
this.$eventBus.$on('cast-local-item', this.castLocalItem)
|
this.$eventBus.$on('cast-local-item', this.castLocalItem)
|
||||||
this.$store.commit('user/addSettingsListener', { id: 'streamContainer', meth: this.settingsUpdated })
|
this.$eventBus.$on('user-settings', this.settingsUpdated)
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
if (this.onLocalMediaProgressUpdateListener) this.onLocalMediaProgressUpdateListener.remove()
|
if (this.onLocalMediaProgressUpdateListener) this.onLocalMediaProgressUpdateListener.remove()
|
||||||
|
@ -286,7 +286,7 @@ export default {
|
||||||
this.$eventBus.$off('pause-item', this.pauseItem)
|
this.$eventBus.$off('pause-item', this.pauseItem)
|
||||||
this.$eventBus.$off('close-stream', this.closeStreamOnly)
|
this.$eventBus.$off('close-stream', this.closeStreamOnly)
|
||||||
this.$eventBus.$off('cast-local-item', this.castLocalItem)
|
this.$eventBus.$off('cast-local-item', this.castLocalItem)
|
||||||
this.$store.commit('user/removeSettingsListener', 'streamContainer')
|
this.$eventBus.$off('user-settings', this.settingsUpdated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -453,7 +453,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$eventBus.$on('library-changed', this.libraryChanged)
|
this.$eventBus.$on('library-changed', this.libraryChanged)
|
||||||
this.$store.commit('user/addSettingsListener', { id: 'lazy-bookshelf', meth: this.settingsUpdated })
|
this.$eventBus.$on('user-settings', this.settingsUpdated)
|
||||||
|
|
||||||
this.$socket.$on('item_updated', this.libraryItemUpdated)
|
this.$socket.$on('item_updated', this.libraryItemUpdated)
|
||||||
this.$socket.$on('item_added', this.libraryItemAdded)
|
this.$socket.$on('item_added', this.libraryItemAdded)
|
||||||
|
@ -468,7 +468,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$eventBus.$off('library-changed', this.libraryChanged)
|
this.$eventBus.$off('library-changed', this.libraryChanged)
|
||||||
this.$store.commit('user/removeSettingsListener', 'lazy-bookshelf')
|
this.$eventBus.$off('user-settings', this.settingsUpdated)
|
||||||
|
|
||||||
this.$socket.$off('item_updated', this.libraryItemUpdated)
|
this.$socket.$off('item_updated', this.libraryItemUpdated)
|
||||||
this.$socket.$off('item_added', this.libraryItemAdded)
|
this.$socket.$off('item_added', this.libraryItemAdded)
|
||||||
|
|
|
@ -87,8 +87,7 @@ export default {
|
||||||
this.saveSettings()
|
this.saveSettings()
|
||||||
},
|
},
|
||||||
saveSettings() {
|
saveSettings() {
|
||||||
this.$store.commit('user/setSettings', this.settings) // Immediate update
|
this.$store.dispatch('user/updateUserSettings', this.settings)
|
||||||
this.$store.dispatch('user/updateUserSettings', this.settings) // TODO: No need to update settings on server...
|
|
||||||
},
|
},
|
||||||
async init() {
|
async init() {
|
||||||
this.bookshelfListView = await this.$localStore.getBookshelfListView()
|
this.bookshelfListView = await this.$localStore.getBookshelfListView()
|
||||||
|
@ -111,11 +110,11 @@ export default {
|
||||||
mounted() {
|
mounted() {
|
||||||
this.init()
|
this.init()
|
||||||
this.$eventBus.$on('bookshelf-total-entities', this.setTotalEntities)
|
this.$eventBus.$on('bookshelf-total-entities', this.setTotalEntities)
|
||||||
this.$store.commit('user/addSettingsListener', { id: 'bookshelftoolbar', meth: this.settingsUpdated })
|
this.$eventBus.$on('user-settings', this.settingsUpdated)
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.$eventBus.$off('bookshelf-total-entities', this.setTotalEntities)
|
this.$eventBus.$off('bookshelf-total-entities', this.setTotalEntities)
|
||||||
this.$store.commit('user/removeSettingsListener', 'bookshelftoolbar')
|
this.$eventBus.$off('user-settings', this.settingsUpdated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -9,12 +9,12 @@ install! 'cocoapods', :disable_input_output_paths => true
|
||||||
def capacitor_pods
|
def capacitor_pods
|
||||||
pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
|
pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
|
||||||
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
|
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
|
||||||
pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app'
|
pod 'CapacitorApp', :path => '..\..\node_modules\@capacitor\app'
|
||||||
pod 'CapacitorDialog', :path => '../../node_modules/@capacitor/dialog'
|
pod 'CapacitorDialog', :path => '..\..\node_modules\@capacitor\dialog'
|
||||||
pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics'
|
pod 'CapacitorHaptics', :path => '..\..\node_modules\@capacitor\haptics'
|
||||||
pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network'
|
pod 'CapacitorNetwork', :path => '..\..\node_modules\@capacitor\network'
|
||||||
pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
|
pod 'CapacitorStatusBar', :path => '..\..\node_modules\@capacitor\status-bar'
|
||||||
pod 'CapacitorStorage', :path => '../../node_modules/@capacitor/storage'
|
pod 'CapacitorStorage', :path => '..\..\node_modules\@capacitor\storage'
|
||||||
pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
|
pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -76,15 +76,12 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async loadSavedSettings() {
|
async loadSavedSettings() {
|
||||||
var userSavedServerSettings = await this.$localStore.getServerSettings()
|
const userSavedServerSettings = await this.$localStore.getServerSettings()
|
||||||
if (userSavedServerSettings) {
|
if (userSavedServerSettings) {
|
||||||
this.$store.commit('setServerSettings', userSavedServerSettings)
|
this.$store.commit('setServerSettings', userSavedServerSettings)
|
||||||
}
|
}
|
||||||
|
|
||||||
var userSavedSettings = await this.$localStore.getUserSettings()
|
await this.$store.dispatch('user/loadUserSettings')
|
||||||
if (userSavedSettings) {
|
|
||||||
this.$store.commit('user/setSettings', userSavedSettings)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async attemptConnection() {
|
async attemptConnection() {
|
||||||
console.warn('[default] attemptConnection')
|
console.warn('[default] attemptConnection')
|
||||||
|
|
|
@ -5,8 +5,6 @@ import { StatusBar, Style } from '@capacitor/status-bar';
|
||||||
import { formatDistance, format, addDays, isDate } from 'date-fns'
|
import { formatDistance, format, addDays, isDate } from 'date-fns'
|
||||||
import { Capacitor } from '@capacitor/core';
|
import { Capacitor } from '@capacitor/core';
|
||||||
|
|
||||||
Vue.prototype.$eventBus = new Vue()
|
|
||||||
|
|
||||||
if (Capacitor.getPlatform() != 'web') {
|
if (Capacitor.getPlatform() != 'web') {
|
||||||
const setStatusBarStyleDark = async () => {
|
const setStatusBarStyleDark = async () => {
|
||||||
await StatusBar.setStyle({ style: Style.Dark })
|
await StatusBar.setStyle({ style: Style.Dark })
|
||||||
|
@ -206,7 +204,9 @@ Vue.prototype.$setOrientationLock = (orientationLockSetting) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ({ store, app }) => {
|
export default ({ store, app }, inject) => {
|
||||||
|
inject('eventBus', new Vue())
|
||||||
|
|
||||||
// iOS Only
|
// iOS Only
|
||||||
// backButton event does not work with iOS swipe navigation so use this workaround
|
// backButton event does not work with iOS swipe navigation so use this workaround
|
||||||
if (app.router && Capacitor.getPlatform() === 'ios') {
|
if (app.router && Capacitor.getPlatform() === 'ios') {
|
||||||
|
|
|
@ -15,7 +15,7 @@ class LocalStorage {
|
||||||
|
|
||||||
async getUserSettings() {
|
async getUserSettings() {
|
||||||
try {
|
try {
|
||||||
var settingsObj = await Storage.get({ key: 'userSettings' }) || {}
|
const settingsObj = await Storage.get({ key: 'userSettings' }) || {}
|
||||||
return settingsObj.value ? JSON.parse(settingsObj.value) : null
|
return settingsObj.value ? JSON.parse(settingsObj.value) : null
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[LocalStorage] Failed to get user settings', error)
|
console.error('[LocalStorage] Failed to get user settings', error)
|
||||||
|
|
|
@ -5,13 +5,8 @@ export const state = () => ({
|
||||||
mobileOrderBy: 'addedAt',
|
mobileOrderBy: 'addedAt',
|
||||||
mobileOrderDesc: true,
|
mobileOrderDesc: true,
|
||||||
mobileFilterBy: 'all',
|
mobileFilterBy: 'all',
|
||||||
orderBy: 'book.title',
|
playbackRate: 1
|
||||||
orderDesc: false,
|
}
|
||||||
filterBy: 'all',
|
|
||||||
playbackRate: 1,
|
|
||||||
bookshelfCoverSize: 120
|
|
||||||
},
|
|
||||||
settingsListeners: []
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
|
@ -54,7 +49,7 @@ export const getters = {
|
||||||
export const actions = {
|
export const actions = {
|
||||||
// When changing libraries make sure sort and filter is still valid
|
// When changing libraries make sure sort and filter is still valid
|
||||||
checkUpdateLibrarySortFilter({ state, dispatch, commit }, mediaType) {
|
checkUpdateLibrarySortFilter({ state, dispatch, commit }, mediaType) {
|
||||||
var settingsUpdate = {}
|
const settingsUpdate = {}
|
||||||
if (mediaType == 'podcast') {
|
if (mediaType == 'podcast') {
|
||||||
if (state.settings.mobileOrderBy == 'media.metadata.authorName' || state.settings.mobileOrderBy == 'media.metadata.authorNameLF') {
|
if (state.settings.mobileOrderBy == 'media.metadata.authorName' || state.settings.mobileOrderBy == 'media.metadata.authorNameLF') {
|
||||||
settingsUpdate.mobileOrderBy = 'media.metadata.author'
|
settingsUpdate.mobileOrderBy = 'media.metadata.author'
|
||||||
|
@ -65,10 +60,10 @@ export const actions = {
|
||||||
if (state.settings.mobileOrderBy == 'media.metadata.publishedYear') {
|
if (state.settings.mobileOrderBy == 'media.metadata.publishedYear') {
|
||||||
settingsUpdate.mobileOrderBy = 'media.metadata.title'
|
settingsUpdate.mobileOrderBy = 'media.metadata.title'
|
||||||
}
|
}
|
||||||
var invalidFilters = ['series', 'authors', 'narrators', 'languages', 'progress', 'issues']
|
const invalidFilters = ['series', 'authors', 'narrators', 'languages', 'progress', 'issues']
|
||||||
var filterByFirstPart = (state.settings.mobileFilterBy || '').split('.').shift()
|
const filterByFirstPart = (state.settings.mobileFilterBy || '').split('.').shift()
|
||||||
if (invalidFilters.includes(filterByFirstPart)) {
|
if (invalidFilters.includes(filterByFirstPart)) {
|
||||||
settingsUpdate.filterBy = 'all'
|
settingsUpdate.mobileFilterBy = 'all'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (state.settings.mobileOrderBy == 'media.metadata.author') {
|
if (state.settings.mobileOrderBy == 'media.metadata.author') {
|
||||||
|
@ -83,24 +78,34 @@ export const actions = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async updateUserSettings({ state, commit }, payload) {
|
async updateUserSettings({ state, commit }, payload) {
|
||||||
if (state.serverConnectionConfig) {
|
if (!payload) return false
|
||||||
var updatePayload = {
|
|
||||||
...payload
|
let hasChanges = false
|
||||||
|
const existingSettings = { ...state.settings }
|
||||||
|
for (const key in existingSettings) {
|
||||||
|
if (payload[key] !== undefined && existingSettings[key] !== payload[key]) {
|
||||||
|
hasChanges = true
|
||||||
|
existingSettings[key] = payload[key]
|
||||||
}
|
}
|
||||||
return this.$axios.$patch('/api/me/settings', updatePayload).then((result) => {
|
|
||||||
if (result.success) {
|
|
||||||
commit('setSettings', result.settings)
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
if (hasChanges) {
|
||||||
console.error('Failed to update settings', error)
|
await this.$localStore.setUserSettings(existingSettings)
|
||||||
return false
|
commit('setSettings', existingSettings)
|
||||||
})
|
this.$eventBus.$emit('user-settings', state.settings)
|
||||||
} else {
|
}
|
||||||
console.log('Update settings without server')
|
},
|
||||||
commit('setSettings', payload)
|
async loadUserSettings({ state, commit }) {
|
||||||
|
const userSettingsFromLocal = await this.$localStore.getUserSettings()
|
||||||
|
|
||||||
|
if (userSettingsFromLocal) {
|
||||||
|
const userSettings = { ...state.settings }
|
||||||
|
for (const key in userSettings) {
|
||||||
|
if (userSettingsFromLocal[key] !== undefined) {
|
||||||
|
userSettings[key] = userSettingsFromLocal[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commit('setSettings', userSettings)
|
||||||
|
this.$eventBus.$emit('user-settings', state.settings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,30 +136,6 @@ export const mutations = {
|
||||||
},
|
},
|
||||||
setSettings(state, settings) {
|
setSettings(state, settings) {
|
||||||
if (!settings) return
|
if (!settings) return
|
||||||
|
state.settings = settings
|
||||||
var hasChanges = false
|
|
||||||
for (const key in settings) {
|
|
||||||
if (state.settings[key] !== settings[key]) {
|
|
||||||
if (key === 'mobileOrderBy' && settings[key] === 'recent') {
|
|
||||||
settings[key] = 'addedAt'
|
|
||||||
}
|
|
||||||
hasChanges = true
|
|
||||||
state.settings[key] = settings[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasChanges) {
|
|
||||||
this.$localStore.setUserSettings({ ...state.settings })
|
|
||||||
state.settingsListeners.forEach((listener) => {
|
|
||||||
listener.meth(state.settings)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
addSettingsListener(state, listener) {
|
|
||||||
var index = state.settingsListeners.findIndex(l => l.id === listener.id)
|
|
||||||
if (index >= 0) state.settingsListeners.splice(index, 1, listener)
|
|
||||||
else state.settingsListeners.push(listener)
|
|
||||||
},
|
|
||||||
removeSettingsListener(state, listenerId) {
|
|
||||||
state.settingsListeners = state.settingsListeners.filter(l => l.id !== listenerId)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue