fixes from pr review

This commit is contained in:
Araxeus
2023-01-09 19:20:11 +02:00
parent 70522173b7
commit 1c5d61854e
5 changed files with 34 additions and 24 deletions

View File

@ -368,8 +368,7 @@ app.on("ready", () => {
const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet
if ( if (
shortcutDetails.target !== appLocation || shortcutDetails.target !== appLocation ||
shortcutDetails.appUserModelId !== appID || shortcutDetails.appUserModelId !== appID
shortcutDetails.toastActivatorClsid !== toastActivatorClsid
) { ) {
throw "needUpdate"; throw "needUpdate";
} }

View File

@ -1,22 +1,23 @@
const { setOptions, setMenuOptions } = require("../../config/plugins"); const { setOptions, setMenuOptions } = require("../../config/plugins");
const defaultConfig = require("../../config/defaults");
let config; let config = defaultConfig.plugins["notifications"];
module.exports.init = (options) => { module.exports.init = (options) => {
config = options; config = { ...config, ...options };
} };
module.exports.setAndMaybeRestart = (option, value) => { module.exports.setAndMaybeRestart = (option, value) => {
config[option] = value; config[option] = value;
setMenuOptions("notifications", config); setMenuOptions("notifications", config);
} };
module.exports.set = (option, value) => { module.exports.set = (option, value) => {
config[option] = value; config[option] = value;
setOptions("notifications", config); setOptions("notifications", config);
} };
module.exports.get = (option) => { module.exports.get = (option) => {
let res = config[option]; let res = config[option];
return res; return res;
} };

View File

@ -10,7 +10,7 @@ const config = require("./config");
let songControls; let songControls;
let savedNotification; let savedNotification;
// TODO create banner function
/** @param {Electron.BrowserWindow} win */ /** @param {Electron.BrowserWindow} win */
module.exports = (win) => { module.exports = (win) => {
songControls = getSongControls(win); songControls = getSongControls(win);
@ -26,13 +26,15 @@ module.exports = (win) => {
// Register songInfoCallback // Register songInfoCallback
registerCallback(songInfo => { registerCallback(songInfo => {
if (!songInfo.isPaused && (songInfo.url !== lastSongInfo.url || config.get("unpauseNotification"))) { if (!songInfo.isPaused &&
(songInfo.url !== lastSongInfo.url || config.get("unpauseNotification"))
) {
lastSongInfo = { ...songInfo }; lastSongInfo = { ...songInfo };
sendXML(songInfo); sendNotification(songInfo);
} }
}); });
// TODO on app before close, close notification
app.once("before-quit", () => { app.once("before-quit", () => {
savedNotification?.close(); savedNotification?.close();
}); });
@ -43,7 +45,11 @@ module.exports = (win) => {
songControls[cmd](); songControls[cmd]();
if (cmd === 'pause' || (cmd === 'play' && !config.get("unpauseNotification"))) { if (cmd === 'pause' || (cmd === 'play' && !config.get("unpauseNotification"))) {
setImmediate(() => 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); const iconSrc = notificationImage(songInfo);
savedNotification?.close(); savedNotification?.close();

View File

@ -40,7 +40,7 @@ module.exports = (_win, options) => [
]; ];
function getToastStyleMenuItems(options) { function getToastStyleMenuItems(options) {
const arr = new Array(Object.keys(ToastStyles).length + 1); const arr = new Array(Object.keys(ToastStyles).length + 2);
arr[0] = { arr[0] = {
label: "Hide Button Text", label: "Hide Button Text",
@ -49,9 +49,11 @@ function getToastStyleMenuItems(options) {
click: (item) => config.set("hideButtonText", item.checked), click: (item) => config.set("hideButtonText", item.checked),
} }
arr[1] = { type: "separator" };
// ToastStyles index starts from 1 // ToastStyles index starts from 1
for (const [name, index] of Object.entries(ToastStyles)) { for (const [name, index] of Object.entries(ToastStyles)) {
arr[index] = { arr[index + 1] = {
label: snakeToCamel(name), label: snakeToCamel(name),
type: "radio", type: "radio",
checked: options.style === index, checked: options.style === index,

View File

@ -3,6 +3,7 @@ const { fileExists } = require("./plugins/utils");
const setupSongInfo = require("./providers/song-info-front"); const setupSongInfo = require("./providers/song-info-front");
const { setupSongControls } = require("./providers/song-controls-front"); const { setupSongControls } = require("./providers/song-controls-front");
const { ipcRenderer } = require("electron"); const { ipcRenderer } = require("electron");
const is = require("electron-is");
const plugins = config.plugins.getEnabled(); const plugins = config.plugins.getEnabled();
@ -70,9 +71,11 @@ document.addEventListener("DOMContentLoaded", () => {
setInterval(() => window._lact = Date.now(), 900000); setInterval(() => window._lact = Date.now(), 900000);
// setup back to front logger // setup back to front logger
ipcRenderer.on("log", (_event, log) => { if (is.dev()) {
console.log(JSON.parse(log)); ipcRenderer.on("log", (_event, log) => {
}); console.log(JSON.parse(log));
});
}
}); });
function listenForApiLoad() { function listenForApiLoad() {
@ -95,7 +98,6 @@ function listenForApiLoad() {
function onApiLoaded() { function onApiLoaded() {
document.dispatchEvent(new CustomEvent('apiLoaded', { detail: api })); document.dispatchEvent(new CustomEvent('apiLoaded', { detail: api }));
//setImmediate()
ipcRenderer.send('apiLoaded'); ipcRenderer.send('apiLoaded');
// Remove upgrade button // Remove upgrade button