Skip to content

Commit 5bffdbd

Browse files
Sem VissscherSem Vissscher
Sem Vissscher
authored and
Sem Vissscher
committed
Simplifies the notification plugin to use the globalized song info
1 parent ee239da commit 5bffdbd

File tree

3 files changed

+18
-124
lines changed

3 files changed

+18
-124
lines changed

plugins/notifications/actions.js

-18
This file was deleted.

plugins/notifications/back.js

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
const { nativeImage, Notification } = require("electron");
2-
3-
const { listenAction } = require("../utils");
4-
const { ACTIONS, CHANNEL } = require("./actions.js");
1+
const {Notification} = require('electron');
52

63
function notify(info) {
7-
let notificationImage = "assets/youtube-music.png";
4+
let notificationImage = 'assets/youtube-music.png';
5+
86
if (info.image) {
9-
notificationImage = nativeImage.createFromDataURL(info.image);
7+
notificationImage = info.image.resize({height: 256, width: 256});
108
}
119

10+
// Fill the notification with content
1211
const notification = {
13-
title: info.title || "Playing",
12+
title: info.title || 'Playing',
1413
body: info.artist,
1514
icon: notificationImage,
16-
silent: true,
15+
silent: true
1716
};
17+
// Send the notification
1818
new Notification(notification).show();
1919
}
2020

21-
function listenAndNotify() {
22-
listenAction(CHANNEL, (event, action, imageSrc) => {
23-
switch (action) {
24-
case ACTIONS.NOTIFICATION:
25-
notify(imageSrc);
26-
break;
27-
default:
28-
console.log("Unknown action: " + action);
29-
}
21+
module.exports = win => {
22+
win.on('ready-to-show', () => {
23+
// Register the callback for new song information
24+
global.songInfo.onNewData(songInfo => {
25+
// If song is playing send notification
26+
if (!songInfo.isPaused) {
27+
notify(songInfo);
28+
}
29+
});
3030
});
31-
}
32-
33-
module.exports = listenAndNotify;
31+
};

plugins/notifications/front.js

-86
This file was deleted.

0 commit comments

Comments
 (0)