This commit is contained in:
Araxeus
2021-05-05 01:25:45 +03:00
parent 79acf6c0ba
commit 22c5ea5000
4 changed files with 54 additions and 55 deletions

View File

@ -32,7 +32,7 @@ function registerShortcuts(win, options) {
_registerLocalShortcut(win, "CommandOrControl+L", search);
const { global, local } = options;
const shortcutOptions = {global, local};
const shortcutOptions = { global, local };
for (const optionType in shortcutOptions) {
registerAllShortcuts(shortcutOptions[optionType], optionType);
@ -41,23 +41,25 @@ function registerShortcuts(win, options) {
function registerAllShortcuts(container, type) {
for (const action in container) {
if (!container[action]) {
continue; //accelerator is empty
continue; // Action accelerator is empty
}
console.debug(`Registering ${type} shortcut`, container[action], ":", action);
if (!songControls[action]) {
console.warn("Invalid action", action);
continue;
}
type === "global" ?
_registerGlobalShortcut(win.webContents, container[action], songControls[action]) :
_registerLocalShortcut(win, local[action], songControls[action]);
if (type === "global") {
_registerGlobalShortcut(win.webContents, container[action], songControls[action]);
} else { // type === "local"
_registerLocalShortcut(win, local[action], songControls[action]);
}
}
}
}
/** Update options to new format */
/** Update options to new format if they are still an array (old format) */
function updateOptions(options) {
let updated = false;
for (const optionType of ["global", "local"]) {

View File

@ -25,16 +25,17 @@ function setOption(options, key = null, newValue = null) {
setOptions("shortcuts", options);
}
const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined }; };
const iconPath = path.join(process.cwd(), "assets", "youtube-music-tray.png");
// Helper function for keybind prompt
const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ }; };
function promptKeybind(options, win) {
let promptOptions = {
const promptOptions = {
title: "Global Keybinds",
icon: iconPath,
label: "Choose Global Keybinds for Songs Control:",
type: "keybind",
keybindOptions: [
keybindOptions: [ // If default=undefined then no default is used
kb("Previous", "previous", options.global?.previous),
kb("Play / Pause", "playPause", options.global?.playPause),
kb("Next", "next", options.global?.next)