From 1c5d61854e696b12e9149e649383be1983590a4e Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Mon, 9 Jan 2023 19:20:11 +0200 Subject: [PATCH] fixes from pr review --- index.js | 3 +-- plugins/notifications/config.js | 21 +++++++++++---------- plugins/notifications/interactive.js | 18 ++++++++++++------ plugins/notifications/menu.js | 6 ++++-- preload.js | 10 ++++++---- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index eed0c040..41cc861a 100644 --- a/index.js +++ b/index.js @@ -368,8 +368,7 @@ app.on("ready", () => { const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet if ( shortcutDetails.target !== appLocation || - shortcutDetails.appUserModelId !== appID || - shortcutDetails.toastActivatorClsid !== toastActivatorClsid + shortcutDetails.appUserModelId !== appID ) { throw "needUpdate"; } diff --git a/plugins/notifications/config.js b/plugins/notifications/config.js index dfba8ca5..38d8100e 100644 --- a/plugins/notifications/config.js +++ b/plugins/notifications/config.js @@ -1,22 +1,23 @@ const { setOptions, setMenuOptions } = require("../../config/plugins"); +const defaultConfig = require("../../config/defaults"); -let config; +let config = defaultConfig.plugins["notifications"]; module.exports.init = (options) => { - config = options; -} + config = { ...config, ...options }; +}; module.exports.setAndMaybeRestart = (option, value) => { config[option] = value; setMenuOptions("notifications", config); -} +}; module.exports.set = (option, value) => { - config[option] = value; - setOptions("notifications", config); -} + config[option] = value; + setOptions("notifications", config); +}; module.exports.get = (option) => { - let res = config[option]; - return res; -} + let res = config[option]; + return res; +}; diff --git a/plugins/notifications/interactive.js b/plugins/notifications/interactive.js index dac18700..da6128b1 100644 --- a/plugins/notifications/interactive.js +++ b/plugins/notifications/interactive.js @@ -10,7 +10,7 @@ const config = require("./config"); let songControls; let savedNotification; -// TODO create banner function + /** @param {Electron.BrowserWindow} win */ module.exports = (win) => { songControls = getSongControls(win); @@ -26,13 +26,15 @@ module.exports = (win) => { // Register songInfoCallback registerCallback(songInfo => { - if (!songInfo.isPaused && (songInfo.url !== lastSongInfo.url || config.get("unpauseNotification"))) { + if (!songInfo.isPaused && + (songInfo.url !== lastSongInfo.url || config.get("unpauseNotification")) + ) { lastSongInfo = { ...songInfo }; - sendXML(songInfo); + sendNotification(songInfo); } }); - // TODO on app before close, close notification + app.once("before-quit", () => { savedNotification?.close(); }); @@ -43,7 +45,11 @@ module.exports = (win) => { songControls[cmd](); if (cmd === 'pause' || (cmd === 'play' && !config.get("unpauseNotification"))) { setImmediate(() => - sendXML({ ...lastSongInfo, isPaused: cmd === 'pause', elapsedSeconds: currentSeconds }) + sendNotification({ + ...lastSongInfo, + isPaused: cmd === 'pause', + elapsedSeconds: currentSeconds + }) ); } } @@ -51,7 +57,7 @@ module.exports = (win) => { ) } -function sendXML(songInfo) { +function sendNotification(songInfo) { const iconSrc = notificationImage(songInfo); savedNotification?.close(); diff --git a/plugins/notifications/menu.js b/plugins/notifications/menu.js index 6d238dd7..23d33c8d 100644 --- a/plugins/notifications/menu.js +++ b/plugins/notifications/menu.js @@ -40,7 +40,7 @@ module.exports = (_win, options) => [ ]; function getToastStyleMenuItems(options) { - const arr = new Array(Object.keys(ToastStyles).length + 1); + const arr = new Array(Object.keys(ToastStyles).length + 2); arr[0] = { label: "Hide Button Text", @@ -49,9 +49,11 @@ function getToastStyleMenuItems(options) { click: (item) => config.set("hideButtonText", item.checked), } + arr[1] = { type: "separator" }; + // ToastStyles index starts from 1 for (const [name, index] of Object.entries(ToastStyles)) { - arr[index] = { + arr[index + 1] = { label: snakeToCamel(name), type: "radio", checked: options.style === index, diff --git a/preload.js b/preload.js index 6c6abae9..1a641335 100644 --- a/preload.js +++ b/preload.js @@ -3,6 +3,7 @@ const { fileExists } = require("./plugins/utils"); const setupSongInfo = require("./providers/song-info-front"); const { setupSongControls } = require("./providers/song-controls-front"); const { ipcRenderer } = require("electron"); +const is = require("electron-is"); const plugins = config.plugins.getEnabled(); @@ -70,9 +71,11 @@ document.addEventListener("DOMContentLoaded", () => { setInterval(() => window._lact = Date.now(), 900000); // setup back to front logger - ipcRenderer.on("log", (_event, log) => { - console.log(JSON.parse(log)); - }); + if (is.dev()) { + ipcRenderer.on("log", (_event, log) => { + console.log(JSON.parse(log)); + }); + } }); function listenForApiLoad() { @@ -95,7 +98,6 @@ function listenForApiLoad() { function onApiLoaded() { document.dispatchEvent(new CustomEvent('apiLoaded', { detail: api })); - //setImmediate() ipcRenderer.send('apiLoaded'); // Remove upgrade button