add notification on unpause option

This commit is contained in:
Araxeus
2021-04-01 17:44:40 +03:00
parent 2d534b0293
commit a3ec9b7b78
4 changed files with 29 additions and 6 deletions

View File

@ -41,7 +41,8 @@ const defaultConfig = {
},
notifications: {
enabled: false,
urgency: "normal"
urgency: "normal",
unpauseNotification: false
}
},
};

View File

@ -27,13 +27,21 @@ const notify = (info, options) => {
module.exports = (win, options) => {
const registerCallback = getSongInfo(win);
let oldNotification;
let oldTitle = "";
let oldURL = "";
win.on("ready-to-show", () => {
// Register the callback for new song information
registerCallback(songInfo => {
// If song is playing && title isn't the same as last one - send notification
if (!songInfo.isPaused && songInfo.title !== oldTitle) {
oldTitle = songInfo.title;
// on pause - reset url? and skip notification
if (songInfo.isPaused) {
//reset oldURL if unpause notification option is on
if (options.unpauseNotification) {
oldURL = "";
}
return;
}
// If url isn't the same as last one - send notification
if (songInfo.url !== oldURL) {
oldURL = songInfo.url;
// Close the old notification
oldNotification?.close();
// This fixes a weird bug that would cause the notification to be updated instead of showing

View File

@ -1,4 +1,4 @@
const {urgencyLevels, setUrgency} = require("./utils");
const {urgencyLevels, setUrgency, setUnpause} = require("./utils");
module.exports = (win, options) => [
{
@ -10,4 +10,10 @@ module.exports = (win, options) => [
click: () => setUrgency(options, level.value)
})),
},
{
label: "Show notification on unpause",
type: "checkbox",
checked: options.unpauseNotification,
click: (item) => setUnpause(options, item.checked)
}
];

View File

@ -7,5 +7,13 @@ module.exports.urgencyLevels = [
];
module.exports.setUrgency = (options, level) => {
options.urgency = level
setOption(options)
};
module.exports.setUnpause = (options, value) => {
options.unpauseNotification = value
setOption(options)
};
let setOption = options => {
setOptions("notifications", options)
};