add optional PiP hotkey

This commit is contained in:
Araxeus
2022-04-15 15:57:48 +03:00
parent b420998458
commit 77d4e9cb84
2 changed files with 36 additions and 0 deletions

View File

@ -1,6 +1,7 @@
const path = require("path");
const { app, ipcMain } = require("electron");
const electronLocalshortcut = require("electron-localshortcut");
const { setOptions, isEnabled } = require("../../config/plugins");
const { injectCSS } = require("../utils");
@ -100,6 +101,9 @@ module.exports = (_win, _options) => {
ipcMain.on("picture-in-picture", async () => {
await togglePiP();
});
if (options.hotkey) {
electronLocalshortcut.register(win, options.hotkey, togglePiP);
}
};
module.exports.setOptions = setLocalOptions;

View File

@ -1,3 +1,6 @@
const prompt = require("custom-electron-prompt");
const promptOptions = require("../../providers/prompt-options");
const { setOptions } = require("./back.js");
module.exports = (win, options) => [
@ -25,5 +28,34 @@ module.exports = (win, options) => [
click: (item) => {
setOptions({ saveSize: item.checked });
},
},
{
label: "Hotkey",
type: "checkbox",
checked: options.hotkey,
click: async (item) => {
const output = await prompt({
title: "Picture in Picture Hotkey",
label: "Choose a hotkey for toggling Picture in Picture",
type: "keybind",
keybindOptions: [{
value: "hotkey",
label: "Hotkey",
default: options.hotkey
}],
...promptOptions()
}, win)
if (output) {
const { value, accelerator } = output[0];
console.log({ [value]: accelerator }); // DELETE
setOptions({ [value]: accelerator });
item.checked = !!accelerator;
} else {
// Reset checkbox if prompt was canceled
item.checked = !item.checked;
}
},
}
];