Skip to content

Commit

Permalink
feat: 添加右键刷新歌单菜单
Browse files Browse the repository at this point in the history
每日推荐等歌单以前是定时刷新的.  但这样的问题可能是丢失当前播放状态。
故现在改成手动刷新。
  • Loading branch information
sigoden committed Mar 7, 2022
1 parent a76b44f commit 1e89485
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/background/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ function initContextMenu() {
title: volumeMute ? "取消静音" : "静音",
contexts,
}),
refreshStore: () => ({
title: "刷新歌单",
contexts,
}),
logout: (userId) => ({
title: "退出登录",
contexts,
Expand All @@ -76,6 +80,7 @@ function initContextMenu() {
case "playPrev":
case "playNext":
case "toggleMute":
case "refreshStore":
case "logout":
storeUtils[item.menuItemId]();
break;
Expand Down
23 changes: 6 additions & 17 deletions src/background/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,12 @@ let songsMapStore = {};
let audioState = { ...EMPTY_AUDIO_STATE, volumeMute: null };
// 持久化缓存信息
let persistData = null;
// 上次刷新时间
let refreshAt = 0;
// 加载歌曲时间
let songAt = 0;

const store = proxy({ ...COMMON_PROPS, playing: false, dir: 1, chinaIp: null });

export async function bootstrap() {
setInterval(async () => {
await refreshLogin();
if (Date.now() - refreshAt > 13 * 60 * 60 * 1000) {
store.playing = store.audioPlaying;
await refreshStore();
}
}, 33 * 60 * 1000);

api.code301 = reset;

await persistLoad();
Expand Down Expand Up @@ -277,6 +267,12 @@ export async function refreshPlaylists() {
return getPopupData();
}

export async function refreshStore() {
logger.debug("refreshStore");
await refreshLogin();
await refreshPlaylists();
}

export function popupInit() {
return getPopupData();
}
Expand Down Expand Up @@ -336,13 +332,6 @@ function getPopupData() {
};
}

async function refreshStore() {
logger.debug("refreshStore");
await refreshLogin();
await refreshPlaylists();
refreshAt = Date.now();
}

async function refreshLogin() {
const res = await api.loginRefresh();
if (res.code !== 200) {
Expand Down

0 comments on commit 1e89485

Please sign in to comment.