Reuse the same notifcation, instead of creating a new notification each time.

This commit is contained in:
Sem Visscher
2021-02-01 20:18:16 +01:00
parent 39dc22973e
commit c1ee58b47f

View File

@ -2,7 +2,7 @@ const { Notification } = require("electron");
const getSongInfo = require("../../providers/song-info");
const notify = (info) => {
const notify = (info, notification) => {
let notificationImage = "assets/youtube-music.png";
if (info.image) {
@ -10,25 +10,31 @@ const notify = (info) => {
}
// Fill the notification with content
const notification = {
title: info.title || "Playing",
body: info.artist,
icon: notificationImage,
silent: true,
};
notification.title = info.title || "Playing";
notification.body = info.artist;
notification.icon = notificationImage;
// Send the notification
new Notification(notification).show();
notification.show();
};
module.exports = (win) => {
const registerCallback = getSongInfo(win);
// Create a notification
let notification = new Notification( {
title:'',
body: '',
icon: "assets/youtube-music.png",
silent: true,
});
win.on("ready-to-show", () => {
// Register the callback for new song information
registerCallback((songInfo) => {
// If song is playing send notification
if (!songInfo.isPaused) {
notify(songInfo);
notify(songInfo, notification);
}
});
});