Merge pull request #1025 from Araxeus/fix-PiP-hotkey-active-in-search

[PiP] fix hotkey activating when typing in the search box
This commit is contained in:
th-ch
2023-02-12 18:34:29 +01:00
committed by GitHub
4 changed files with 21 additions and 6 deletions

View File

@ -92,9 +92,6 @@ 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,5 +1,8 @@
const { ipcRenderer } = require("electron");
const { toKeyEvent } = require('keyboardevent-from-electron-accelerator');
const keyEventAreEqual = require('keyboardevents-areequal');
const { getSongMenu } = require("../../providers/dom-elements");
const { ElementFromFile, templatePath } = require("../utils");
@ -78,7 +81,7 @@ const listenForToggle = () => {
});
}
function observeMenu(options) {
function observeMenu() {
document.addEventListener(
"apiLoaded",
() => {
@ -101,4 +104,15 @@ function observeMenu(options) {
);
}
module.exports = observeMenu;
module.exports = (options) => {
observeMenu();
if (options.hotkey) {
const hotkeyEvent = toKeyEvent(options.hotkey);
window.addEventListener('keydown', (event) => {
if (keyEventAreEqual(event, hotkeyEvent) && !$('ytmusic-search-box').opened) {
togglePictureInPicture();
}
});
}
};