mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Update back.js
This commit is contained in:
@ -1,8 +1,7 @@
|
|||||||
const { Notification } = require("electron");
|
const { Notification } = require("electron");
|
||||||
|
|
||||||
const getSongInfo = require("../../providers/song-info");
|
const getSongInfo = require("../../providers/song-info");
|
||||||
|
|
||||||
const notify = (info, notification) => {
|
const notify = (info) => {
|
||||||
let notificationImage = "assets/youtube-music.png";
|
let notificationImage = "assets/youtube-music.png";
|
||||||
|
|
||||||
if (info.image) {
|
if (info.image) {
|
||||||
@ -10,31 +9,32 @@ const notify = (info, notification) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fill the notification with content
|
// Fill the notification with content
|
||||||
notification.title = info.title || "Playing";
|
const notification = {
|
||||||
notification.body = info.artist;
|
title: info.title || "Playing",
|
||||||
notification.icon = notificationImage;
|
body: info.artist,
|
||||||
|
icon: notificationImage,
|
||||||
|
silent: true,
|
||||||
|
};
|
||||||
|
|
||||||
// Send the notification
|
// Send the notification
|
||||||
notification.show();
|
currentNotification = new Notification(notification);
|
||||||
|
currentNotification.show()
|
||||||
|
|
||||||
|
return currentNotification;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = (win) => {
|
module.exports = (win) => {
|
||||||
const registerCallback = getSongInfo(win);
|
const registerCallback = getSongInfo(win);
|
||||||
|
let oldNotification;
|
||||||
// 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, notification);
|
// Close the old notification
|
||||||
|
oldNotification?.close();
|
||||||
|
// This fixes a weird bug that would cause the notification to be updated instead of showing
|
||||||
|
setTimeout(()=>{ oldNotification = notify(songInfo) }, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user