@@ -2,7 +2,7 @@ const path = require("path");
2
2
3
3
const { app, ipcMain } = require ( "electron" ) ;
4
4
5
- const { setOptions } = require ( "../../config/plugins" ) ;
5
+ const { setOptions, isEnabled } = require ( "../../config/plugins" ) ;
6
6
const { injectCSS } = require ( "../utils" ) ;
7
7
8
8
let isInPiP = false ;
@@ -22,6 +22,15 @@ const setLocalOptions = (_options) => {
22
22
setOptions ( "picture-in-picture" , _options ) ;
23
23
}
24
24
25
+
26
+ const adaptors = [ ] ;
27
+ const runAdaptors = ( ) => adaptors . forEach ( a => a ( ) ) ;
28
+
29
+ if ( isEnabled ( "in-app-menu" ) ) {
30
+ let adaptor = require ( "./adaptors/in-app-menu" ) ;
31
+ adaptors . push ( ( ) => adaptor ( win , options , setLocalOptions , togglePiP , isInPiP ) ) ;
32
+ }
33
+
25
34
const togglePiP = async ( ) => {
26
35
isInPiP = ! isInPiP ;
27
36
setLocalOptions ( { isInPiP } ) ;
@@ -38,44 +47,24 @@ const togglePiP = async () => {
38
47
win . webContents . on ( "before-input-event" , blockShortcutsInPiP ) ;
39
48
40
49
win . setFullScreenable ( false ) ;
41
- await win . webContents . executeJavaScript (
42
- // Go fullscreen
43
- `
44
- var exitButton = document.querySelector(".exit-fullscreen-button");
45
- exitButton.replaceWith(exitButton.cloneNode(true));
46
- document.querySelector(".exit-fullscreen-button").onclick = () => togglePictureInPicture();
47
-
48
- var onPlayerDblClick = document.querySelector('#player').onDoubleClick_
49
- document.querySelector('#player').onDoubleClick_ = () => {};
50
- document.querySelector('#expanding-menu').onmouseleave = () => document.querySelector('.middle-controls').click();
51
- if (!document.querySelector("ytmusic-player-page").playerPageOpen_) {
52
- document.querySelector(".toggle-player-page-button").click();
53
- }
54
- document.querySelector(".fullscreen-button").click();
55
- document.querySelector("ytmusic-player-bar").classList.add("pip");
56
- `
57
- ) ;
58
- win . setFullScreenable ( true ) ;
50
+
51
+ runAdaptors ( ) ;
52
+ win . webContents . send ( "pip-toggle" , true ) ;
59
53
60
54
app . dock ?. hide ( ) ;
61
55
win . setVisibleOnAllWorkspaces ( true , {
62
56
visibleOnFullScreen : true ,
63
57
} ) ;
64
58
app . dock ?. show ( ) ;
65
- win . setAlwaysOnTop ( true , "screen-saver" , 1 ) ;
59
+ if ( options . alwaysOnTop ) {
60
+ win . setAlwaysOnTop ( true , "screen-saver" , 1 ) ;
61
+ }
66
62
} else {
67
63
win . webContents . removeListener ( "before-input-event" , blockShortcutsInPiP ) ;
64
+ win . setFullScreenable ( true ) ;
68
65
69
- await win . webContents . executeJavaScript (
70
- // Exit fullscreen
71
- `
72
- document.querySelector('#player').onDoubleClick_ = onPlayerDblClick;
73
- document.querySelector('#expanding-menu').onmouseleave = undefined;
74
- document.querySelector(".exit-fullscreen-button").replaceWith(exitButton);
75
- document.querySelector(".exit-fullscreen-button").click();
76
- document.querySelector("ytmusic-player-bar").classList.remove("pip");
77
- `
78
- ) ;
66
+ runAdaptors ( ) ;
67
+ win . webContents . send ( "pip-toggle" , false ) ;
79
68
80
69
win . setVisibleOnAllWorkspaces ( false ) ;
81
70
win . setAlwaysOnTop ( false ) ;
@@ -114,4 +103,3 @@ module.exports = (_win, _options) => {
114
103
} ;
115
104
116
105
module . exports . setOptions = setLocalOptions ;
117
-
0 commit comments