mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Merge pull request #216 from Araxeus/fix-duplicate-notification
[Notification Plugin] Fix duplicate notification
This commit is contained in:
@ -42,7 +42,8 @@ const defaultConfig = {
|
|||||||
},
|
},
|
||||||
notifications: {
|
notifications: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
urgency: "normal"
|
urgency: "normal",
|
||||||
|
unpauseNotification: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -18,7 +18,7 @@ const notify = (info, options) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Send the notification
|
// Send the notification
|
||||||
currentNotification = new Notification(notification);
|
const currentNotification = new Notification(notification);
|
||||||
currentNotification.show()
|
currentNotification.show()
|
||||||
|
|
||||||
return currentNotification;
|
return currentNotification;
|
||||||
@ -27,11 +27,21 @@ const notify = (info, options) => {
|
|||||||
module.exports = (win, options) => {
|
module.exports = (win, options) => {
|
||||||
const registerCallback = getSongInfo(win);
|
const registerCallback = getSongInfo(win);
|
||||||
let oldNotification;
|
let oldNotification;
|
||||||
|
let oldURL = "";
|
||||||
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
|
// on pause - reset url? and skip notification
|
||||||
if (!songInfo.isPaused) {
|
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
|
// Close the old notification
|
||||||
oldNotification?.close();
|
oldNotification?.close();
|
||||||
// This fixes a weird bug that would cause the notification to be updated instead of showing
|
// This fixes a weird bug that would cause the notification to be updated instead of showing
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const {urgencyLevels, setUrgency} = require("./utils");
|
const {urgencyLevels, setUrgency, setUnpause} = require("./utils");
|
||||||
|
|
||||||
module.exports = (win, options) => [
|
module.exports = (win, options) => [
|
||||||
{
|
{
|
||||||
@ -10,4 +10,10 @@ module.exports = (win, options) => [
|
|||||||
click: () => setUrgency(options, level.value)
|
click: () => setUrgency(options, level.value)
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Show notification on unpause",
|
||||||
|
type: "checkbox",
|
||||||
|
checked: options.unpauseNotification,
|
||||||
|
click: (item) => setUnpause(options, item.checked)
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@ -7,5 +7,13 @@ module.exports.urgencyLevels = [
|
|||||||
];
|
];
|
||||||
module.exports.setUrgency = (options, level) => {
|
module.exports.setUrgency = (options, level) => {
|
||||||
options.urgency = level
|
options.urgency = level
|
||||||
|
setOption(options)
|
||||||
|
};
|
||||||
|
module.exports.setUnpause = (options, value) => {
|
||||||
|
options.unpauseNotification = value
|
||||||
|
setOption(options)
|
||||||
|
};
|
||||||
|
|
||||||
|
let setOption = options => {
|
||||||
setOptions("notifications", options)
|
setOptions("notifications", options)
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user