mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 18:21:47 +00:00
34 lines
765 B
JavaScript
34 lines
765 B
JavaScript
const { nativeImage, Notification } = require("electron");
|
|
|
|
const { listenAction } = require("../utils");
|
|
const { ACTIONS, CHANNEL } = require("./actions.js");
|
|
|
|
function notify(info) {
|
|
let notificationImage = "assets/youtube-music.png";
|
|
if (info.image) {
|
|
notificationImage = nativeImage.createFromDataURL(info.image);
|
|
}
|
|
|
|
const notification = {
|
|
title: info.title || "Playing",
|
|
body: info.artist,
|
|
icon: notificationImage,
|
|
silent: true,
|
|
};
|
|
new Notification(notification).show();
|
|
}
|
|
|
|
function listenAndNotify() {
|
|
listenAction(CHANNEL, (event, action, imageSrc) => {
|
|
switch (action) {
|
|
case ACTIONS.NOTIFICATION:
|
|
notify(imageSrc);
|
|
break;
|
|
default:
|
|
console.log("Unknown action: " + action);
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = listenAndNotify;
|