Skip to content

Commit 1fdf241

Browse files
Sem VisscherSem Visscher
Sem Visscher
authored and
Sem Visscher
committed
Update back.js
1 parent df62778 commit 1fdf241

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

plugins/notifications/back.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
const { Notification } = require("electron");
2-
32
const getSongInfo = require("../../providers/song-info");
43

5-
const notify = (info, notification) => {
4+
const notify = (info) => {
65
let notificationImage = "assets/youtube-music.png";
76

87
if (info.image) {
98
notificationImage = info.image.resize({ height: 256, width: 256 });
109
}
1110

1211
// Fill the notification with content
13-
notification.title = info.title || "Playing";
14-
notification.body = info.artist;
15-
notification.icon = notificationImage;
16-
12+
const notification = {
13+
title: info.title || "Playing",
14+
body: info.artist,
15+
icon: notificationImage,
16+
silent: true,
17+
};
18+
1719
// Send the notification
18-
notification.show();
20+
currentNotification = new Notification(notification);
21+
currentNotification.show()
22+
23+
return currentNotification;
1924
};
2025

2126
module.exports = (win) => {
2227
const registerCallback = getSongInfo(win);
23-
24-
// Create a notification
25-
let notification = new Notification( {
26-
title: "",
27-
body: "",
28-
icon: "assets/youtube-music.png",
29-
silent: true,
30-
});
31-
28+
let oldNotification;
3229
win.on("ready-to-show", () => {
3330
// Register the callback for new song information
3431
registerCallback((songInfo) => {
3532
// If song is playing send notification
36-
if (!songInfo.isPaused) {
37-
notify(songInfo, notification);
33+
if (!songInfo.isPaused) {
34+
// Close the old notification
35+
oldNotification?.close();
36+
// This fixes a weird bug that would cause the notification to be updated instead of showing
37+
setTimeout(()=>{ oldNotification = notify(songInfo) }, 1);
3838
}
3939
});
4040
});

0 commit comments

Comments
 (0)