mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-17 05:02:06 +00:00
Reuse the same notifcation, instead of creating a new notification each time.
This commit is contained in:
@ -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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user