-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplifies the notification plugin to use the globalized song info
- Loading branch information
Sem Vissscher
authored and
Sem Vissscher
committed
Dec 21, 2020
1 parent
ee239da
commit 5bffdbd
Showing
3 changed files
with
18 additions
and
124 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
const { nativeImage, Notification } = require("electron"); | ||
|
||
const { listenAction } = require("../utils"); | ||
const { ACTIONS, CHANNEL } = require("./actions.js"); | ||
const {Notification} = require('electron'); | ||
|
||
function notify(info) { | ||
let notificationImage = "assets/youtube-music.png"; | ||
let notificationImage = 'assets/youtube-music.png'; | ||
|
||
if (info.image) { | ||
notificationImage = nativeImage.createFromDataURL(info.image); | ||
notificationImage = info.image.resize({height: 256, width: 256}); | ||
} | ||
|
||
// Fill the notification with content | ||
const notification = { | ||
title: info.title || "Playing", | ||
title: info.title || 'Playing', | ||
body: info.artist, | ||
icon: notificationImage, | ||
silent: true, | ||
silent: true | ||
}; | ||
// Send the notification | ||
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 = win => { | ||
win.on('ready-to-show', () => { | ||
// Register the callback for new song information | ||
global.songInfo.onNewData(songInfo => { | ||
// If song is playing send notification | ||
if (!songInfo.isPaused) { | ||
notify(songInfo); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = listenAndNotify; | ||
}; |
This file was deleted.
Oops, something went wrong.