From a3ec9b7b78c4677d31f7281d842bf623275e4ee5 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 1 Apr 2021 17:44:40 +0300 Subject: [PATCH] add `notification on unpause` option --- config/defaults.js | 3 ++- plugins/notifications/back.js | 16 ++++++++++++---- plugins/notifications/menu.js | 8 +++++++- plugins/notifications/utils.js | 8 ++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/config/defaults.js b/config/defaults.js index 25f8141f..cc590bea 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -41,7 +41,8 @@ const defaultConfig = { }, notifications: { enabled: false, - urgency: "normal" + urgency: "normal", + unpauseNotification: false } }, }; diff --git a/plugins/notifications/back.js b/plugins/notifications/back.js index 2a95489a..dedd9379 100644 --- a/plugins/notifications/back.js +++ b/plugins/notifications/back.js @@ -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 diff --git a/plugins/notifications/menu.js b/plugins/notifications/menu.js index 83a7e4f6..a61cac67 100644 --- a/plugins/notifications/menu.js +++ b/plugins/notifications/menu.js @@ -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) + } ]; diff --git a/plugins/notifications/utils.js b/plugins/notifications/utils.js index f80dd342..c43ecb20 100644 --- a/plugins/notifications/utils.js +++ b/plugins/notifications/utils.js @@ -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) };