advplyr.audiobookshelf-app/store/index.js

112 lines
2.8 KiB
JavaScript
Raw Normal View History

import Vue from 'vue'
2021-09-01 20:07:11 -05:00
export const state = () => ({
streamAudiobook: null,
playingDownload: null,
2021-09-01 20:07:11 -05:00
playOnLoad: false,
serverUrl: null,
appUpdateInfo: null,
socketConnected: false,
networkConnected: false,
networkConnectionType: null,
streamListener: null,
isFirstLoad: true,
2021-10-17 20:20:00 -05:00
hasStoragePermission: false,
selectedBook: null,
showReader: false,
downloadFolder: null,
mediaScanResults: {},
2021-11-19 10:29:26 -06:00
showSideDrawer: false,
bookshelfView: 'grid'
2021-09-01 20:07:11 -05:00
})
export const getters = {
playerIsOpen: (state) => {
return state.streamAudiobook || state.playingDownload
},
isAudiobookStreaming: (state) => id => {
return (state.streamAudiobook && state.streamAudiobook.id === id)
},
isAudiobookPlaying: (state) => id => {
return (state.playingDownload && state.playingDownload.id === id) || (state.streamAudiobook && state.streamAudiobook.id === id)
},
getAudiobookIdStreaming: state => {
return state.streamAudiobook ? state.streamAudiobook.id : null
}
}
2021-09-02 12:19:26 -05:00
export const actions = {}
2021-09-01 20:07:11 -05:00
export const mutations = {
setHasStoragePermission(state, val) {
state.hasStoragePermission = val
},
setIsFirstLoad(state, val) {
state.isFirstLoad = val
},
setAppUpdateInfo(state, info) {
state.appUpdateInfo = info
2021-09-02 12:19:26 -05:00
},
2021-09-01 20:07:11 -05:00
closeStream(state, audiobookId) {
if (state.streamAudiobook && state.streamAudiobook.id !== audiobookId) {
return
}
state.streamAudiobook = null
},
setPlayOnLoad(state, val) {
state.playOnLoad = val
},
setStreamAudiobook(state, audiobook) {
if (audiobook) {
state.playingDownload = null
}
Vue.set(state, 'streamAudiobook', audiobook)
if (state.streamListener) {
state.streamListener('stream', audiobook)
}
},
setPlayingDownload(state, download) {
if (download) {
state.streamAudiobook = null
}
Vue.set(state, 'playingDownload', download)
if (state.streamListener) {
state.streamListener('download', download)
}
2021-09-01 20:07:11 -05:00
},
setServerUrl(state, url) {
state.serverUrl = url
},
setSocketConnected(state, val) {
state.socketConnected = val
},
setNetworkStatus(state, val) {
state.networkConnected = val.connected
state.networkConnectionType = val.connectionType
},
setStreamListener(state, val) {
state.streamListener = val
},
removeStreamListener(state) {
state.streamListener = null
2021-10-17 20:20:00 -05:00
},
openReader(state, audiobook) {
state.selectedBook = audiobook
state.showReader = true
},
setShowReader(state, val) {
state.showReader = val
},
setDownloadFolder(state, val) {
state.downloadFolder = val
},
setMediaScanResults(state, val) {
state.mediaScanResults = val
},
setShowSideDrawer(state, val) {
state.showSideDrawer = val
2021-11-19 10:29:26 -06:00
},
setBookshelfView(state, val) {
state.bookshelfView = val
2021-09-01 20:07:11 -05:00
}
}