Fix radio race condition
This commit is contained in:
parent
6fc9f64583
commit
abe67de138
|
@ -315,11 +315,22 @@ export const useQueue = createGlobalState(() => {
|
||||||
if (localStorage.queue) {
|
if (localStorage.queue) {
|
||||||
(async () => {
|
(async () => {
|
||||||
const { queue: { currentIndex: index, tracks: oldTracks } } = JSON.parse(localStorage.queue) as { queue: { currentIndex: number, tracks: Track[] } }
|
const { queue: { currentIndex: index, tracks: oldTracks } } = JSON.parse(localStorage.queue) as { queue: { currentIndex: number, tracks: Track[] } }
|
||||||
|
|
||||||
|
const oldRadios = localStorage.radios
|
||||||
|
|
||||||
if (oldTracks.length !== 0) {
|
if (oldTracks.length !== 0) {
|
||||||
tracks.value.length = 0
|
tracks.value.length = 0
|
||||||
await enqueue(...oldTracks)
|
await enqueue(...oldTracks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: There is a race condition between clearing queue and adding new tracks that resets the radio.
|
||||||
|
// We need to reset the radio to the old state
|
||||||
|
try {
|
||||||
|
const radios = JSON.parse(oldRadios)
|
||||||
|
store.commit('radios/current', radios.radios.current)
|
||||||
|
store.commit('radios/running', radios.radios.running)
|
||||||
|
} catch (err) {}
|
||||||
|
|
||||||
currentIndex.value = index
|
currentIndex.value = index
|
||||||
delete localStorage.queue
|
delete localStorage.queue
|
||||||
})().catch((error) => console.error('Could not successfully migrate between queue versions', error))
|
})().catch((error) => console.error('Could not successfully migrate between queue versions', error))
|
||||||
|
|
Loading…
Reference in New Issue