mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-13 15:34:50 +02:00
This patch allows user to not only add a chapter track but also remove the total track. This means that you can have only the total track or only the chapter track. This patch does not allow user to have no track at all. Disabling one track will automatically enable the other one, if that one is already disabled. The reasoning behind this is that for long-ish audio books, users will not very often look at the overall progress. In fact, I find the progress bar mostly useful only for quickly seeking to a position when jumping back a few seconds is not sufficient. In the seldom occasion that I want the overall progress, I can easily get it from the book details page.
149 lines
No EOL
4.1 KiB
JavaScript
149 lines
No EOL
4.1 KiB
JavaScript
import { Storage } from '@capacitor/storage'
|
|
|
|
class LocalStorage {
|
|
constructor(vuexStore) {
|
|
this.vuexStore = vuexStore
|
|
}
|
|
|
|
async setUserSettings(settings) {
|
|
try {
|
|
await Storage.set({ key: 'userSettings', value: JSON.stringify(settings) })
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to update user settings', error)
|
|
}
|
|
}
|
|
|
|
async getUserSettings() {
|
|
try {
|
|
const settingsObj = await Storage.get({ key: 'userSettings' }) || {}
|
|
return settingsObj.value ? JSON.parse(settingsObj.value) : null
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to get user settings', error)
|
|
return null
|
|
}
|
|
}
|
|
|
|
async setServerSettings(settings) {
|
|
try {
|
|
await Storage.set({ key: 'serverSettings', value: JSON.stringify(settings) })
|
|
console.log('Saved server settings', JSON.stringify(settings))
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to update server settings', error)
|
|
}
|
|
}
|
|
|
|
async getServerSettings() {
|
|
try {
|
|
var settingsObj = await Storage.get({ key: 'serverSettings' }) || {}
|
|
return settingsObj.value ? JSON.parse(settingsObj.value) : null
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to get server settings', error)
|
|
return null
|
|
}
|
|
}
|
|
|
|
async setUseChapterTrack(useChapterTrack) {
|
|
try {
|
|
await Storage.set({ key: 'useChapterTrack', value: useChapterTrack ? '1' : '0' })
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to set use chapter track', error)
|
|
}
|
|
}
|
|
|
|
async getUseChapterTrack() {
|
|
try {
|
|
var obj = await Storage.get({ key: 'useChapterTrack' }) || {}
|
|
return obj.value === '1'
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to get use chapter track', error)
|
|
return false
|
|
}
|
|
}
|
|
|
|
async setUseTotalTrack(useTotalTrack) {
|
|
try {
|
|
await Storage.set({ key: 'useTotalTrack', value: useTotalTrack ? '1' : '0' })
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to set use total track', error)
|
|
}
|
|
}
|
|
|
|
async getUseTotalTrack() {
|
|
try {
|
|
var obj = await Storage.get({ key: 'useTotalTrack' }) || {}
|
|
return obj.value === '1'
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to get use total track', error)
|
|
return false
|
|
}
|
|
}
|
|
|
|
async setPlayerLock(lock) {
|
|
try {
|
|
await Storage.set({ key: 'playerLock', value: lock ? '1' : '0' })
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to set player lock', error)
|
|
}
|
|
}
|
|
|
|
async getPlayerLock() {
|
|
try {
|
|
var obj = await Storage.get({ key: 'playerLock' }) || {}
|
|
return obj.value === '1'
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to get player lock', error)
|
|
return false
|
|
}
|
|
}
|
|
|
|
async setBookshelfListView(useIt) {
|
|
try {
|
|
await Storage.set({ key: 'bookshelfListView', value: useIt ? '1' : '0' })
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to set bookshelf list view', error)
|
|
}
|
|
}
|
|
|
|
async getBookshelfListView() {
|
|
try {
|
|
var obj = await Storage.get({ key: 'bookshelfListView' }) || {}
|
|
return obj.value === '1'
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to get bookshelf list view', error)
|
|
return false
|
|
}
|
|
}
|
|
|
|
async setLastLibraryId(libraryId) {
|
|
try {
|
|
await Storage.set({ key: 'lastLibraryId', value: libraryId })
|
|
console.log('[LocalStorage] Set Last Library Id', libraryId)
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to set last library id', error)
|
|
}
|
|
}
|
|
|
|
async removeLastLibraryId() {
|
|
try {
|
|
await Storage.remove({ key: 'lastLibraryId' })
|
|
console.log('[LocalStorage] Remove Last Library Id')
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to remove last library id', error)
|
|
}
|
|
}
|
|
|
|
async getLastLibraryId() {
|
|
try {
|
|
var obj = await Storage.get({ key: 'lastLibraryId' }) || {}
|
|
return obj.value || null
|
|
} catch (error) {
|
|
console.error('[LocalStorage] Failed to get last library id', error)
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
export default ({ app, store }, inject) => {
|
|
inject('localStore', new LocalStorage(store))
|
|
} |