Set title/artist metadata in downloader

This commit is contained in:
TC
2021-01-14 23:01:26 +01:00
parent 25fd48697b
commit 2861473097
4 changed files with 36 additions and 0 deletions

View File

@ -2,6 +2,7 @@ const { join } = require("path");
const { dialog } = require("electron");
const getSongInfo = require("../../providers/song-info");
const { injectCSS, listenAction } = require("../utils");
const { ACTIONS, CHANNEL } = require("./actions.js");
@ -16,14 +17,26 @@ const sendError = (win, err) => {
dialog.showMessageBox(dialogOpts);
};
let metadata = {};
function handle(win) {
injectCSS(win.webContents, join(__dirname, "style.css"));
const registerCallback = getSongInfo(win);
registerCallback((info) => {
metadata = {
...info,
image: info.image ? info.image.toDataURL() : undefined,
};
});
listenAction(CHANNEL, (event, action, error) => {
switch (action) {
case ACTIONS.ERROR:
sendError(win, error);
break;
case ACTIONS.METADATA:
event.returnValue = JSON.stringify(metadata);
break;
default:
console.log("Unknown action: " + action);
}