Skip to content

Commit

Permalink
fix: 刷新播放列表时清除缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Nov 8, 2021
1 parent 3c69e1e commit dfd98e2
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/background/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {
randChinaIp,
} from '../utils'

// 缓存歌单
const playlistDetailStore = {}
// 缓存歌单内歌曲
const songsMapStore = {}
// 播放器
const audio = new Audio()
// 缓存歌单
let playlistDetailStore = {}
// 缓存歌单内歌曲
let songsMapStore = {}
// 播放状态
let audioState = { ...EMPTY_AUDIO_STATE, volumeMute: null }
// 持久化缓存信息
Expand Down Expand Up @@ -234,21 +234,19 @@ export async function logout () {
}

export async function refreshPlaylists () {
const oldPlaylistIds = store.playlists.map(v => v.id)
playlistDetailStore = {}
globalThis.playlistDetailStore = playlistDetailStore

songsMapStore = {}
globalThis.songsMapStore = songsMapStore

if (store.userId) {
store.playlists = await loadPlaylists()
await changePlaylist()
} else {
store.playlists = [...PLAYLIST_TOP, PLAYLIST_NEW_SONGS]
await changePlaylist()
}
const newPlaylists = store.playlists
for (const playlistId of oldPlaylistIds) {
if (newPlaylists.findIndex(v => v.id === playlistId) === -1) {
delete songsMapStore[playlistId]
delete playlistDetailStore[playlistId]
}
}
return getPopupData()
}

Expand Down Expand Up @@ -666,11 +664,8 @@ function tracksToSongsMap (tracks) {
return songsMap
}

// 这些暴露到全局变量仅为调试用
globalThis.audio = audio
globalThis.store = store
globalThis.songsMapStore = songsMapStore
globalThis.playlistDetailStore = playlistDetailStore
globalThis.refreshStore = refreshStore
globalThis.api = api

Expand Down

0 comments on commit dfd98e2

Please sign in to comment.