Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
feat: 重新启动时自动选中上次播放歌曲
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Mar 7, 2022
1 parent 1e89485 commit 52e8b0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/background/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function initContextMenu() {
contexts,
}),
refreshStore: () => ({
title: "刷新歌单",
title: "每日刷新",
contexts,
}),
logout: (userId) => ({
Expand Down
19 changes: 7 additions & 12 deletions src/background/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ let playlistDetailStore = {};
let songsMapStore = {};
// 播放状态
let audioState = { ...EMPTY_AUDIO_STATE, volumeMute: null };
// 持久化缓存信息
let persistData = null;
// 加载歌曲时间
let songAt = 0;

Expand Down Expand Up @@ -137,16 +135,19 @@ export async function updatePlayMode() {
export async function changePlaylist(playlistId) {
let songId;
if (!playlistId) {
if (persistData) {
const persistData = await loadData();
if (persistData?.playlistId) {
playlistId = persistData.playlistId;
songId = persistData.songId;
persistData = null;
}
}
let playlist = store.playlists.find((playlist) => playlist.id === playlistId);
if (!playlist) playlist = store.playlists[0];
if (!playlist) {
playlist = store.playlists[0];
songId = null;
}
const selectedPlaylist = await loadPlaylistDetails(playlist);
if (!selectedPlaylist.normalIndexes.find((v) => v === songId)) {
if (!songId || !selectedPlaylist.normalIndexes.find((v) => v === songId)) {
const songsIndex =
store.playMode === PLAY_MODE.SHUFFLE
? selectedPlaylist.shuffleIndexes
Expand Down Expand Up @@ -296,14 +297,8 @@ async function persistLoad() {
volume = COMMON_PROPS.volume,
playMode = COMMON_PROPS.playMode,
chinaIp = null,
playlistId,
songId,
} = data;
logger.debug("persist.load", data);
if (playlistId) {
persistData = { playlistId };
if (songId) persistData.songId = songId;
}
Object.assign(store, { volume, playMode, chinaIp });
}
}
Expand Down

0 comments on commit 52e8b0f

Please sign in to comment.