setup SongInfo **once**

This commit is contained in:
Araxeus
2021-05-10 04:15:56 +03:00
parent 7942efa202
commit 7cf78c6635
8 changed files with 20 additions and 26 deletions

View File

@ -51,6 +51,7 @@ const songInfo = {
};
const handleData = async (responseText, win) => {
console.log("handling song-info")
let data = JSON.parse(responseText);
songInfo.title = data?.videoDetails?.title;
songInfo.artist = await getArtist(win) || cleanupArtistName(data?.videoDetails?.author);
@ -64,15 +65,15 @@ const handleData = async (responseText, win) => {
win.webContents.send("update-song-info", JSON.stringify(songInfo));
};
// This variable will be filled with the callbacks once they register
const callbacks = [];
// This function will allow plugins to register callback that will be triggered when data changes
const registerCallback = (callback) => {
callbacks.push(callback);
};
const registerProvider = (win) => {
// This variable will be filled with the callbacks once they register
const callbacks = [];
// This function will allow plugins to register callback that will be triggered when data changes
const registerCallback = (callback) => {
callbacks.push(callback);
};
win.on("page-title-updated", async () => {
// Get and set the new data
songInfo.isPaused = await getPausedStatus(win);
@ -93,8 +94,6 @@ const registerProvider = (win) => {
c(songInfo);
});
});
return registerCallback;
};
const suffixesToRemove = [' - Topic', 'VEVO'];
@ -110,7 +109,8 @@ function cleanupArtistName(artist) {
return artist;
}
module.exports = registerProvider;
module.exports = registerCallback;
module.exports.setupSongInfo = registerProvider;
module.exports.getImage = getImage;
module.exports.cleanupArtistName = cleanupArtistName;