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
if (
shortcutDetails.target !== appLocation ||
shortcutDetails.appUserModelId !== appID ||
shortcutDetails.toastActivatorClsid !== toastActivatorClsid
shortcutDetails.appUserModelId !== appID
) {
throw "needUpdate";
}

View File

@ -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);
}
};
module.exports.get = (option) => {
let res = config[option];
return res;
}
};

View File

@ -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();

View File

@ -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,

View File

@ -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
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