2021-11-21 06:54:10 -06:00
|
|
|
import { Network } from '@capacitor/network'
|
2022-07-21 19:18:32 -05:00
|
|
|
import { AbsAudioPlayer } from '@/plugins/capacitor'
|
2023-06-19 14:03:29 -05:00
|
|
|
import { PlayMethod } from '@/plugins/constants'
|
2021-09-01 20:07:11 -05:00
|
|
|
|
|
|
|
export const state = () => ({
|
2022-07-01 20:05:11 -05:00
|
|
|
deviceData: null,
|
2023-06-19 12:37:44 -05:00
|
|
|
currentPlaybackSession: null,
|
2022-04-10 20:31:47 -05:00
|
|
|
playerIsPlaying: false,
|
2022-07-04 15:42:59 -05:00
|
|
|
playerIsFullscreen: false,
|
2023-12-15 17:35:37 -06:00
|
|
|
playerIsStartingPlayback: false, // When pressing play before native play response
|
|
|
|
playerStartingPlaybackMediaId: null,
|
2022-04-17 16:59:49 -05:00
|
|
|
isCasting: false,
|
2022-04-17 18:14:45 -05:00
|
|
|
isCastAvailable: false,
|
2023-06-04 17:14:26 -05:00
|
|
|
attemptingConnection: false,
|
2021-09-12 18:37:08 -05:00
|
|
|
socketConnected: false,
|
|
|
|
networkConnected: false,
|
2021-09-19 18:44:10 -05:00
|
|
|
networkConnectionType: null,
|
2022-07-21 19:18:32 -05:00
|
|
|
isNetworkUnmetered: true,
|
2021-09-19 18:44:10 -05:00
|
|
|
isFirstLoad: true,
|
2023-02-17 17:14:49 -06:00
|
|
|
isFirstAudioLoad: true,
|
2021-10-17 20:20:00 -05:00
|
|
|
hasStoragePermission: false,
|
2022-04-16 06:10:10 -05:00
|
|
|
selectedLibraryItem: null,
|
2021-10-28 09:37:31 -05:00
|
|
|
showReader: false,
|
2023-06-11 11:12:52 -05:00
|
|
|
ereaderKeepProgress: false,
|
|
|
|
ereaderFileId: null,
|
2021-11-19 10:29:26 -06:00
|
|
|
showSideDrawer: false,
|
2021-12-04 19:56:29 -06:00
|
|
|
isNetworkListenerInit: false,
|
2022-05-22 14:19:13 -05:00
|
|
|
serverSettings: null,
|
2023-06-04 15:52:36 -05:00
|
|
|
lastBookshelfScrollData: {},
|
|
|
|
lastItemScrollData: {}
|
2021-09-01 20:07:11 -05:00
|
|
|
})
|
|
|
|
|
2021-09-12 18:37:08 -05:00
|
|
|
export const getters = {
|
2024-10-31 21:14:25 +02:00
|
|
|
getCurrentPlaybackSessionId: (state) => {
|
2023-06-19 12:37:44 -05:00
|
|
|
return state.currentPlaybackSession?.id || null
|
2022-12-03 15:20:27 -06:00
|
|
|
},
|
2024-10-31 21:14:25 +02:00
|
|
|
getIsPlayerOpen: (state) => {
|
2023-06-19 12:37:44 -05:00
|
|
|
return !!state.currentPlaybackSession
|
2021-09-12 18:37:08 -05:00
|
|
|
},
|
2024-10-31 21:14:25 +02:00
|
|
|
getIsCurrentSessionLocal: (state) => {
|
2023-06-19 14:03:29 -05:00
|
|
|
return state.currentPlaybackSession?.playMethod == PlayMethod.LOCAL
|
2023-06-19 12:37:44 -05:00
|
|
|
},
|
2024-10-31 21:14:25 +02:00
|
|
|
getIsMediaStreaming: (state) => (libraryItemId, episodeId) => {
|
2023-06-19 12:37:44 -05:00
|
|
|
if (!state.currentPlaybackSession || !libraryItemId) return false
|
|
|
|
|
|
|
|
// Check using local library item id and local episode id
|
|
|
|
const isLocalLibraryItemId = libraryItemId.startsWith('local_')
|
|
|
|
if (isLocalLibraryItemId) {
|
|
|
|
if (state.currentPlaybackSession.localLibraryItem?.id !== libraryItemId) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (!episodeId) return true
|
|
|
|
return state.currentPlaybackSession.localEpisodeId === episodeId
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.currentPlaybackSession.libraryItemId !== libraryItemId) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (!episodeId) return true
|
|
|
|
return state.currentPlaybackSession.episodeId === episodeId
|
2021-12-04 19:56:29 -06:00
|
|
|
},
|
2024-10-31 21:14:25 +02:00
|
|
|
getServerSetting: (state) => (key) => {
|
2021-12-04 19:56:29 -06:00
|
|
|
if (!state.serverSettings) return null
|
|
|
|
return state.serverSettings[key]
|
|
|
|
},
|
2024-10-31 21:14:25 +02:00
|
|
|
getJumpForwardTime: (state) => {
|
2024-01-01 11:55:57 -06:00
|
|
|
if (!state.deviceData?.deviceSettings) return 10
|
2022-07-01 20:05:11 -05:00
|
|
|
return state.deviceData.deviceSettings.jumpForwardTime || 10
|
|
|
|
},
|
2024-10-31 21:14:25 +02:00
|
|
|
getJumpBackwardsTime: (state) => {
|
2024-01-01 11:55:57 -06:00
|
|
|
if (!state.deviceData?.deviceSettings) return 10
|
2022-07-01 20:05:11 -05:00
|
|
|
return state.deviceData.deviceSettings.jumpBackwardsTime || 10
|
2022-07-27 13:15:03 -05:00
|
|
|
},
|
2024-10-31 21:14:25 +02:00
|
|
|
getAltViewEnabled: (state) => {
|
2024-01-01 11:55:57 -06:00
|
|
|
if (!state.deviceData?.deviceSettings) return true
|
2022-07-27 13:15:03 -05:00
|
|
|
return state.deviceData.deviceSettings.enableAltView
|
2022-12-04 10:41:09 -06:00
|
|
|
},
|
2024-10-31 21:14:25 +02:00
|
|
|
getOrientationLockSetting: (state) => {
|
2023-06-20 16:29:56 -05:00
|
|
|
return state.deviceData?.deviceSettings?.lockOrientation
|
2024-05-23 22:33:06 +01:00
|
|
|
},
|
2024-10-31 21:14:25 +02:00
|
|
|
getCanDownloadUsingCellular: (state) => {
|
2024-05-23 22:33:06 +01:00
|
|
|
if (!state.deviceData?.deviceSettings?.downloadUsingCellular) return 'ALWAYS'
|
|
|
|
return state.deviceData.deviceSettings.downloadUsingCellular || 'ALWAYS'
|
|
|
|
},
|
2024-10-31 21:14:25 +02:00
|
|
|
getCanStreamingUsingCellular: (state) => {
|
2024-05-23 22:33:06 +01:00
|
|
|
if (!state.deviceData?.deviceSettings?.streamingUsingCellular) return 'ALWAYS'
|
|
|
|
return state.deviceData.deviceSettings.streamingUsingCellular || 'ALWAYS'
|
2025-01-26 14:22:35 -06:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Old server versions require a token for images
|
|
|
|
*
|
|
|
|
* @param {*} state
|
|
|
|
* @returns {boolean} True if server version is less than 2.17
|
|
|
|
*/
|
|
|
|
getDoesServerImagesRequireToken: (state) => {
|
|
|
|
const serverVersion = state.serverSettings?.version
|
|
|
|
if (!serverVersion) return false
|
|
|
|
const versionParts = serverVersion.split('.')
|
|
|
|
const majorVersion = parseInt(versionParts[0])
|
|
|
|
const minorVersion = parseInt(versionParts[1])
|
|
|
|
return majorVersion < 2 || (majorVersion == 2 && minorVersion < 17)
|
2022-07-01 20:05:11 -05:00
|
|
|
}
|
2021-09-12 18:37:08 -05:00
|
|
|
}
|
|
|
|
|
2021-11-21 06:54:10 -06:00
|
|
|
export const actions = {
|
2022-04-03 14:24:17 -05:00
|
|
|
// Listen for network connection
|
2021-11-21 06:54:10 -06:00
|
|
|
async setupNetworkListener({ state, commit }) {
|
|
|
|
if (state.isNetworkListenerInit) return
|
|
|
|
commit('setNetworkListenerInit', true)
|
|
|
|
|
2023-01-29 16:04:03 -06:00
|
|
|
const status = await Network.getStatus()
|
2022-04-03 14:24:17 -05:00
|
|
|
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)
|
|
|
|
})
|
2022-07-21 19:18:32 -05:00
|
|
|
|
|
|
|
AbsAudioPlayer.addListener('onNetworkMeteredChanged', (payload) => {
|
|
|
|
const isUnmetered = payload.value
|
|
|
|
console.log('On network metered changed', isUnmetered)
|
|
|
|
commit('setIsNetworkUnmetered', isUnmetered)
|
|
|
|
})
|
2021-11-21 06:54:10 -06:00
|
|
|
}
|
|
|
|
}
|
2021-09-01 20:07:11 -05:00
|
|
|
|
|
|
|
export const mutations = {
|
2022-07-01 20:05:11 -05:00
|
|
|
setDeviceData(state, deviceData) {
|
|
|
|
state.deviceData = deviceData
|
|
|
|
},
|
2022-05-22 14:19:13 -05:00
|
|
|
setLastBookshelfScrollData(state, { scrollTop, path, name }) {
|
|
|
|
state.lastBookshelfScrollData[name] = { scrollTop, path }
|
|
|
|
},
|
2023-06-04 15:52:36 -05:00
|
|
|
setLastItemScrollData(state, data) {
|
|
|
|
state.lastItemScrollData = data
|
|
|
|
},
|
2023-06-19 12:37:44 -05:00
|
|
|
setPlaybackSession(state, playbackSession) {
|
|
|
|
state.currentPlaybackSession = playbackSession
|
2022-04-15 20:48:39 -05:00
|
|
|
|
2024-10-31 21:14:25 +02:00
|
|
|
state.isCasting = playbackSession?.mediaPlayer === 'cast-player'
|
2022-04-10 20:31:47 -05:00
|
|
|
},
|
2022-04-17 16:59:49 -05:00
|
|
|
setMediaPlayer(state, mediaPlayer) {
|
|
|
|
state.isCasting = mediaPlayer === 'cast-player'
|
|
|
|
},
|
2022-04-17 18:14:45 -05:00
|
|
|
setCastAvailable(state, available) {
|
|
|
|
state.isCastAvailable = available
|
|
|
|
},
|
2023-06-04 17:14:26 -05:00
|
|
|
setAttemptingConnection(state, val) {
|
|
|
|
state.attemptingConnection = val
|
|
|
|
},
|
2022-04-10 20:31:47 -05:00
|
|
|
setPlayerPlaying(state, val) {
|
|
|
|
state.playerIsPlaying = val
|
|
|
|
},
|
2022-07-04 15:42:59 -05:00
|
|
|
setPlayerFullscreen(state, val) {
|
|
|
|
state.playerIsFullscreen = val
|
|
|
|
},
|
2023-12-15 17:35:37 -06:00
|
|
|
setPlayerIsStartingPlayback(state, mediaId) {
|
|
|
|
state.playerStartingPlaybackMediaId = mediaId
|
|
|
|
state.playerIsStartingPlayback = true
|
|
|
|
},
|
|
|
|
setPlayerDoneStartingPlayback(state) {
|
|
|
|
state.playerStartingPlaybackMediaId = null
|
|
|
|
state.playerIsStartingPlayback = false
|
|
|
|
},
|
2021-09-19 18:44:10 -05:00
|
|
|
setHasStoragePermission(state, val) {
|
|
|
|
state.hasStoragePermission = val
|
|
|
|
},
|
|
|
|
setIsFirstLoad(state, val) {
|
|
|
|
state.isFirstLoad = val
|
|
|
|
},
|
2023-02-17 17:14:49 -06:00
|
|
|
setIsFirstAudioLoad(state, val) {
|
|
|
|
state.isFirstAudioLoad = val
|
|
|
|
},
|
2021-09-12 18:37:08 -05:00
|
|
|
setSocketConnected(state, val) {
|
|
|
|
state.socketConnected = val
|
|
|
|
},
|
2021-11-21 06:54:10 -06:00
|
|
|
setNetworkListenerInit(state, val) {
|
|
|
|
state.isNetworkListenerInit = val
|
|
|
|
},
|
2021-09-12 18:37:08 -05:00
|
|
|
setNetworkStatus(state, val) {
|
2024-10-31 21:14:25 +02:00
|
|
|
if (val.connectionType !== 'none') {
|
|
|
|
state.networkConnected = true
|
|
|
|
} else {
|
|
|
|
state.networkConnected = false
|
|
|
|
}
|
2024-11-03 21:45:05 +02:00
|
|
|
if (this.$platform === 'ios') {
|
|
|
|
// Capacitor Network plugin only shows ios device connected if internet access is available.
|
|
|
|
// This fix allows iOS users to use local servers without internet access.
|
|
|
|
state.networkConnected = true
|
|
|
|
}
|
2021-09-12 18:37:08 -05:00
|
|
|
state.networkConnectionType = val.connectionType
|
|
|
|
},
|
2022-07-21 19:18:32 -05:00
|
|
|
setIsNetworkUnmetered(state, val) {
|
|
|
|
state.isNetworkUnmetered = val
|
|
|
|
},
|
2023-06-11 11:12:52 -05:00
|
|
|
showReader(state, { libraryItem, keepProgress, fileId }) {
|
2022-04-16 06:10:10 -05:00
|
|
|
state.selectedLibraryItem = libraryItem
|
2023-06-11 11:12:52 -05:00
|
|
|
state.ereaderKeepProgress = keepProgress
|
|
|
|
state.ereaderFileId = fileId
|
|
|
|
|
2021-10-17 20:20:00 -05:00
|
|
|
state.showReader = true
|
|
|
|
},
|
|
|
|
setShowReader(state, val) {
|
|
|
|
state.showReader = val
|
2021-10-28 09:37:31 -05:00
|
|
|
},
|
2021-11-14 19:59:34 -06:00
|
|
|
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
|
2021-12-05 18:31:47 -06:00
|
|
|
this.$localStore.setServerSettings(state.serverSettings)
|
2021-09-01 20:07:11 -05:00
|
|
|
}
|
2024-05-23 22:33:06 +01:00
|
|
|
}
|