mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-03-10 05:13:56 +00:00
fixes from pr review
This commit is contained in:
@ -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;
|
||||
};
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user