From a7087aaa38496ed93790be9613ea80f548e4ed6b Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Fri, 26 Mar 2021 17:41:12 +0300 Subject: [PATCH 1/4] uses getFolder() now --- plugins/downloader/menu.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/downloader/menu.js b/plugins/downloader/menu.js index 14419e0c..caed50bb 100644 --- a/plugins/downloader/menu.js +++ b/plugins/downloader/menu.js @@ -67,10 +67,10 @@ module.exports = (win, options, refreshMenu) => [ click: () => { let result = dialog.showOpenDialogSync({ properties: ['openDirectory', 'createDirectory'], - defaultPath: Array.isArray(options.downloadFolder) ? options.downloadFolder[0] : undefined, + defaultPath: getFolder(options.downloadFolder), }) if(result) { - options.downloadFolder = result + options.downloadFolder = result[0] setOptions("downloader", options) } //else = user pressed cancel } From d73d0cf8ce1f7afa0d13254c096b5129a4b334aa Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 1 Apr 2021 15:39:07 +0300 Subject: [PATCH 2/4] fix duplicate notification --- plugins/notifications/back.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/notifications/back.js b/plugins/notifications/back.js index 65e4337b..0d390307 100644 --- a/plugins/notifications/back.js +++ b/plugins/notifications/back.js @@ -18,7 +18,7 @@ const notify = (info, options) => { }; // Send the notification - currentNotification = new Notification(notification); + const currentNotification = new Notification(notification); currentNotification.show() return currentNotification; @@ -27,11 +27,13 @@ const notify = (info, options) => { module.exports = (win, options) => { const registerCallback = getSongInfo(win); let oldNotification; + let oldTitle = ""; win.on("ready-to-show", () => { // Register the callback for new song information registerCallback(songInfo => { // If song is playing send notification - if (!songInfo.isPaused) { + if (!songInfo.isPaused && songInfo.title !== oldTitle) { + oldTitle = songInfo.title; // Close the old notification oldNotification?.close(); // This fixes a weird bug that would cause the notification to be updated instead of showing From 2d534b029396cb4bfdbfa637b79d80524f1ada40 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 1 Apr 2021 15:50:26 +0300 Subject: [PATCH 3/4] fix duplicate notification --- plugins/downloader/menu.js | 1 - plugins/notifications/back.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/downloader/menu.js b/plugins/downloader/menu.js index cf78001c..06a3c124 100644 --- a/plugins/downloader/menu.js +++ b/plugins/downloader/menu.js @@ -64,7 +64,6 @@ module.exports = (win, options, refreshMenu) => [ { label: "Choose download folder", click: () => { - let result = dialog.showOpenDialogSync({ properties: ["openDirectory", "createDirectory"], defaultPath: getFolder(options.downloadFolder), diff --git a/plugins/notifications/back.js b/plugins/notifications/back.js index 0d390307..2a95489a 100644 --- a/plugins/notifications/back.js +++ b/plugins/notifications/back.js @@ -31,7 +31,7 @@ module.exports = (win, options) => { win.on("ready-to-show", () => { // Register the callback for new song information registerCallback(songInfo => { - // If song is playing send notification + // If song is playing && title isn't the same as last one - send notification if (!songInfo.isPaused && songInfo.title !== oldTitle) { oldTitle = songInfo.title; // Close the old notification 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 4/4] 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) };