fix net state not being right on startup

This commit is contained in:
austinried 2021-08-26 08:17:39 +09:00
parent 5af187ba48
commit 46eb293f98

View File

@ -35,6 +35,7 @@ const rebuildQueue = () => {
}
let serviceCreated = false
const createService = async () => {
useStore.subscribe(
(currentTrack?: TrackExt) => {
@ -46,6 +47,10 @@ const createService = async () => {
(prev, next) => prev?.id === next?.id,
)
NetInfo.fetch().then(state => {
setNetState(state.type === NetInfoStateType.cellular ? 'mobile' : 'wifi')
})
NetInfo.addEventListener(state => {
const currentType = useStore.getState().netState
const newType = state.type === NetInfoStateType.cellular ? 'mobile' : 'wifi'