mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 09:09:29 +01:00
fix back handler dying on unsub
also remove need for unsub
This commit is contained in:
parent
df3e913125
commit
4ac1f3d931
@ -21,30 +21,22 @@ const setCurrentTrackIdx = (idx?: number) => {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = async function () {
|
||||
const unsubs: (() => void)[] = []
|
||||
|
||||
unsubs.push(
|
||||
useStore.subscribe(
|
||||
(currentTrack?: TrackExt) => {
|
||||
if (currentTrack) {
|
||||
useStore.getState().scrobbleTrack(currentTrack.id)
|
||||
}
|
||||
},
|
||||
state => state.currentTrack,
|
||||
),
|
||||
let serviceCreated = false
|
||||
const createService = async () => {
|
||||
useStore.subscribe(
|
||||
(currentTrack?: TrackExt) => {
|
||||
if (currentTrack) {
|
||||
useStore.getState().scrobbleTrack(currentTrack.id)
|
||||
}
|
||||
},
|
||||
state => state.currentTrack,
|
||||
)
|
||||
|
||||
const { emitter } = TrackPlayer.addEventListener(Event.RemoteStop, () => {
|
||||
for (const unsub of unsubs) {
|
||||
unsub()
|
||||
}
|
||||
TrackPlayer.addEventListener(Event.RemoteStop, () => {
|
||||
reset()
|
||||
trackPlayerCommands.enqueue(TrackPlayer.destroy)
|
||||
})
|
||||
|
||||
unsubs.push(() => emitter.removeAllListeners())
|
||||
|
||||
TrackPlayer.addEventListener(Event.RemotePlay, () => trackPlayerCommands.enqueue(TrackPlayer.play))
|
||||
TrackPlayer.addEventListener(Event.RemotePause, () => trackPlayerCommands.enqueue(TrackPlayer.pause))
|
||||
|
||||
@ -91,3 +83,10 @@ module.exports = async function () {
|
||||
setCurrentTrackIdx(useStore.getState().currentTrackIdx)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = async function () {
|
||||
if (!serviceCreated) {
|
||||
createService()
|
||||
serviceCreated = true
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user