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