fix(unblockMusic): the song information may fail to be fetched and reduce the request time

1. Increase the timeout time to prevent blocking the rendering process
2. Use the modification package to solve the problem that song information may not be available and repeatedly requested.
This commit is contained in:
njzy 2020-12-04 00:16:18 +08:00
parent 02c4ee9fb2
commit 6fa6155817
5 changed files with 29 additions and 12 deletions

View File

@ -25,7 +25,7 @@
},
"main": "background.js",
"dependencies": {
"@nondanee/unblockneteasemusic": "^0.25.3",
"@njzy/unblockneteasemusic": "^0.25.3",
"axios": "^0.21.0",
"big-integer": "^1.6.48",
"core-js": "^3.6.5",

View File

@ -1,5 +1,5 @@
import { app, ipcMain } from "electron";
import match from "@nondanee/unblockneteasemusic";
import match from "@njzy/unblockneteasemusic";
export function initIpcMain(win) {
// Make vuex copy for electron.
@ -9,9 +9,26 @@ export function initIpcMain(win) {
global.vuexCopy = state;
});
ipcMain.on("unblock-music", (event, id) => {
match(id, ["qq", "kuwo", "migu"]).then((res) => {
ipcMain.on("unblock-music", (event, track) => {
// 兼容 unblockneteasemusic 所使用的 api 字段
track.alias = track.alia || [];
track.duration = track.dt || 0;
track.album = track.al || [];
track.artists = track.ar || [];
const matchPromise = match(track.id, ["qq", "kuwo", "migu"], track);
const timeoutPromise = new Promise((_, reject) => {
setTimeout(() => {
reject("timeout");
}, 3000);
});
Promise.race([matchPromise, timeoutPromise])
.then((res) => {
event.returnValue = res;
})
.catch((err) => {
console.log("unblock music error: ", err);
event.returnValue = null;
});
});

View File

@ -43,7 +43,7 @@ export default {
if (track.playable === false) {
let res = undefined;
if (process.env.IS_ELECTRON === true) {
res = ipcRenderer.sendSync("unblock-music", track.id);
res = ipcRenderer.sendSync("unblock-music", track);
}
if (res?.url) {
commitMP3(res.url);

View File

@ -49,7 +49,7 @@ module.exports = {
pluginOptions: {
// electron-builder的配置文件
electronBuilder: {
externals: ["@nondanee/unblockneteasemusic"],
externals: ["@nondanee/unblockneteasemusic", "@njzy/unblockneteasemusic"],
builderOptions: {
productName: "YesPlayMusic",
copyright: "Copyright © YesPlayMusic",

View File

@ -1265,16 +1265,16 @@
call-me-maybe "^1.0.1"
glob-to-regexp "^0.3.0"
"@njzy/unblockneteasemusic@^0.25.3":
version "0.25.3"
resolved "https://registry.yarnpkg.com/@njzy/unblockneteasemusic/-/unblockneteasemusic-0.25.3.tgz#f8223df756ab3a723af066a75b91357a2b162443"
integrity sha512-rY9SMf6VbJueIvVW22Ut4dX48PBSETvdCoVJNdbKzOMacgxiQ5K5I2ZJtbLhZ0kj27tx7bN5Zo36bSwf2KlP7g==
"@nodelib/fs.stat@^1.1.2":
version "1.1.3"
resolved "https://registry.npm.taobao.org/@nodelib/fs.stat/download/@nodelib/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
integrity sha1-K1o6s/kYzKSKjHVMCBaOPwPrphs=
"@nondanee/unblockneteasemusic@^0.25.3":
version "0.25.3"
resolved "https://registry.yarnpkg.com/@nondanee/unblockneteasemusic/-/unblockneteasemusic-0.25.3.tgz#72d936f18f46523a2b929b8eaec8dfd2acf25e7e"
integrity sha512-Fgl0iRvuFCNhyFlovbqqnJQRomaFVjMLosS1hRUd/X47y6HeNlQsxa9c8RtmeLwNnZ27rj0DsUZlECqU7FyNPA==
"@npmcli/move-file@^1.0.1":
version "1.0.1"
resolved "https://registry.npm.taobao.org/@npmcli/move-file/download/@npmcli/move-file-1.0.1.tgz#de103070dac0f48ce49cf6693c23af59c0f70464"