advplyr.audiobookshelf-app/store/index.js

134 lines
4.1 KiB
JavaScript
Raw Normal View History

2021-11-21 06:54:10 -06:00
import { Network } from '@capacitor/network'
2021-09-01 20:07:11 -05:00
export const state = () => ({
deviceData: null,
playerLibraryItemId: null,
playerEpisodeId: null,
playerIsLocal: false,
playerIsPlaying: false,
playerIsFullscreen: false,
isCasting: false,
isCastAvailable: false,
socketConnected: false,
networkConnected: false,
networkConnectionType: null,
isFirstLoad: true,
2021-10-17 20:20:00 -05:00
hasStoragePermission: false,
2022-04-16 06:10:10 -05:00
selectedLibraryItem: null,
showReader: false,
2021-11-19 10:29:26 -06:00
showSideDrawer: false,
2021-12-04 19:56:29 -06:00
isNetworkListenerInit: false,
serverSettings: null,
lastBookshelfScrollData: {},
lastLocalMediaSyncResults: null
2021-09-01 20:07:11 -05:00
})
export const getters = {
getIsItemStreaming: state => libraryItemId => {
return state.playerLibraryItemId == libraryItemId
},
getIsEpisodeStreaming: state => (libraryItemId, episodeId) => {
return state.playerLibraryItemId == libraryItemId && state.playerEpisodeId == episodeId
2021-12-04 19:56:29 -06:00
},
getServerSetting: state => key => {
if (!state.serverSettings) return null
return state.serverSettings[key]
},
getBookCoverAspectRatio: state => {
2022-04-23 14:38:29 -05:00
if (!state.serverSettings) return 1
2021-12-04 19:56:29 -06:00
return state.serverSettings.coverAspectRatio === 0 ? 1.6 : 1
},
getJumpForwardTime: state => {
if (!state.deviceData || !state.deviceData.deviceSettings) return 10
return state.deviceData.deviceSettings.jumpForwardTime || 10
},
getJumpBackwardsTime: state => {
if (!state.deviceData || !state.deviceData.deviceSettings) return 10
return state.deviceData.deviceSettings.jumpBackwardsTime || 10
}
}
2021-11-21 06:54:10 -06:00
export const actions = {
// Listen for network connection
2021-11-21 06:54:10 -06:00
async setupNetworkListener({ state, commit }) {
if (state.isNetworkListenerInit) return
commit('setNetworkListenerInit', true)
var status = await Network.getStatus()
console.log('Network status', status)
2021-11-21 06:54:10 -06:00
commit('setNetworkStatus', status)
Network.addListener('networkStatusChange', (status) => {
console.log('Network status changed', status.connected, status.connectionType)
commit('setNetworkStatus', status)
})
}
}
2021-09-01 20:07:11 -05:00
export const mutations = {
setDeviceData(state, deviceData) {
state.deviceData = deviceData
},
setLastBookshelfScrollData(state, { scrollTop, path, name }) {
state.lastBookshelfScrollData[name] = { scrollTop, path }
},
setPlayerItem(state, playbackSession) {
state.playerIsLocal = playbackSession ? playbackSession.playMethod == this.$constants.PlayMethod.LOCAL : false
2022-04-15 20:48:39 -05:00
if (state.playerIsLocal) {
state.playerLibraryItemId = playbackSession ? playbackSession.localLibraryItem.id || null : null
state.playerEpisodeId = playbackSession ? playbackSession.localEpisodeId || null : null
} else {
state.playerLibraryItemId = playbackSession ? playbackSession.libraryItemId || null : null
state.playerEpisodeId = playbackSession ? playbackSession.episodeId || null : null
}
var mediaPlayer = playbackSession ? playbackSession.mediaPlayer : null
state.isCasting = mediaPlayer === "cast-player"
},
setMediaPlayer(state, mediaPlayer) {
state.isCasting = mediaPlayer === 'cast-player'
},
setCastAvailable(state, available) {
state.isCastAvailable = available
},
setPlayerPlaying(state, val) {
state.playerIsPlaying = val
},
setPlayerFullscreen(state, val) {
state.playerIsFullscreen = val
},
setHasStoragePermission(state, val) {
state.hasStoragePermission = val
},
setIsFirstLoad(state, val) {
state.isFirstLoad = val
},
setSocketConnected(state, val) {
state.socketConnected = val
},
2021-11-21 06:54:10 -06:00
setNetworkListenerInit(state, val) {
state.isNetworkListenerInit = val
},
setNetworkStatus(state, val) {
state.networkConnected = val.connected
state.networkConnectionType = val.connectionType
},
2022-04-16 06:10:10 -05:00
openReader(state, libraryItem) {
state.selectedLibraryItem = libraryItem
2021-10-17 20:20:00 -05:00
state.showReader = true
},
setShowReader(state, val) {
state.showReader = val
},
setShowSideDrawer(state, val) {
state.showSideDrawer = val
2021-11-19 10:29:26 -06:00
},
2021-12-04 19:56:29 -06:00
setServerSettings(state, val) {
state.serverSettings = val
this.$localStore.setServerSettings(state.serverSettings)
},
setLastLocalMediaSyncResults(state, val) {
state.lastLocalMediaSyncResults = val
2021-09-01 20:07:11 -05:00
}
}