Merge pull request #964 from Araxeus/fix-PiP-button

fix PiP buttons not showing up
This commit is contained in:
th-ch
2023-01-14 14:47:31 +01:00
committed by GitHub
2 changed files with 19 additions and 7 deletions

View File

@ -47,6 +47,7 @@ const togglePiP = async () => {
win.webContents.on("before-input-event", blockShortcutsInPiP); win.webContents.on("before-input-event", blockShortcutsInPiP);
win.setMaximizable(false);
win.setFullScreenable(false); win.setFullScreenable(false);
runAdaptors(); runAdaptors();
@ -62,6 +63,7 @@ const togglePiP = async () => {
} }
} else { } else {
win.webContents.removeListener("before-input-event", blockShortcutsInPiP); win.webContents.removeListener("before-input-event", blockShortcutsInPiP);
win.setMaximizable(true);
win.setFullScreenable(true); win.setFullScreenable(true);
runAdaptors(); runAdaptors();

View File

@ -10,6 +10,21 @@ const pipButton = ElementFromFile(
templatePath(__dirname, "picture-in-picture.html") templatePath(__dirname, "picture-in-picture.html")
); );
// will also clone
function replaceButton(query, button) {
const svg = button.querySelector("#icon svg").cloneNode(true);
button.replaceWith(button.cloneNode(true));
button.remove();
const newButton = $(query);
newButton.querySelector("#icon").appendChild(svg);
return newButton;
}
function cloneButton(query) {
replaceButton(query, $(query));
return $(query);
}
const observer = new MutationObserver(() => { const observer = new MutationObserver(() => {
if (!menu) { if (!menu) {
menu = getSongMenu(); menu = getSongMenu();
@ -30,9 +45,6 @@ global.togglePictureInPicture = () => {
const listenForToggle = () => { const listenForToggle = () => {
const originalExitButton = $(".exit-fullscreen-button"); const originalExitButton = $(".exit-fullscreen-button");
const clonedExitButton = originalExitButton.cloneNode(true);
clonedExitButton.onclick = () => togglePictureInPicture();
const appLayout = $("ytmusic-app-layout"); const appLayout = $("ytmusic-app-layout");
const expandMenu = $('#expanding-menu'); const expandMenu = $('#expanding-menu');
const middleControls = $('.middle-controls'); const middleControls = $('.middle-controls');
@ -44,7 +56,7 @@ const listenForToggle = () => {
ipcRenderer.on('pip-toggle', (_, isPip) => { ipcRenderer.on('pip-toggle', (_, isPip) => {
if (isPip) { if (isPip) {
$(".exit-fullscreen-button").replaceWith(clonedExitButton); replaceButton(".exit-fullscreen-button", originalExitButton).onclick = () => togglePictureInPicture();
player.onDoubleClick_ = () => {}; player.onDoubleClick_ = () => {};
expandMenu.onmouseleave = () => middleControls.click(); expandMenu.onmouseleave = () => middleControls.click();
if (!playerPage.playerPageOpen_) { if (!playerPage.playerPageOpen_) {
@ -67,10 +79,8 @@ function observeMenu(options) {
"apiLoaded", "apiLoaded",
() => { () => {
listenForToggle(); listenForToggle();
const minButton = $(".player-minimize-button");
// remove native listeners // remove native listeners
minButton.replaceWith(minButton.cloneNode(true)); cloneButton(".player-minimize-button").onclick = () => {
$(".player-minimize-button").onclick = () => {
global.togglePictureInPicture(); global.togglePictureInPicture();
setTimeout(() => $('#player').click()); setTimeout(() => $('#player').click());
}; };