@@ -41,6 +41,25 @@ function onClosed() {
41
41
mainWindow = null ;
42
42
}
43
43
44
+ function loadPlugins ( win ) {
45
+ injectCSS ( win . webContents , path . join ( __dirname , "youtube-music.css" ) ) ;
46
+ win . webContents . on ( "did-finish-load" , ( ) => {
47
+ if ( is . dev ( ) ) {
48
+ console . log ( "did finish load" ) ;
49
+ win . webContents . openDevTools ( ) ;
50
+ }
51
+ } ) ;
52
+
53
+ getEnabledPlugins ( ) . forEach ( ( plugin ) => {
54
+ console . log ( "Loaded plugin - " + plugin ) ;
55
+ const pluginPath = path . join ( __dirname , "plugins" , plugin , "back.js" ) ;
56
+ fileExists ( pluginPath , ( ) => {
57
+ const handle = require ( pluginPath ) ;
58
+ handle ( win ) ;
59
+ } ) ;
60
+ } ) ;
61
+ }
62
+
44
63
function createMainWindow ( ) {
45
64
const windowSize = store . get ( "window-size" ) ;
46
65
const windowMaximized = store . get ( "window-maximized" ) ;
@@ -54,6 +73,7 @@ function createMainWindow() {
54
73
webPreferences : {
55
74
nodeIntegration : isTesting ( ) , // Only necessary when testing with Spectron
56
75
preload : path . join ( __dirname , "preload.js" ) ,
76
+ nodeIntegrationInSubFrames : true ,
57
77
nativeWindowOpen : true , // window.open return Window object(like in regular browsers), not BrowserWindowProxy
58
78
enableRemoteModule : true ,
59
79
affinity : "main-window" , // main window, and addition windows should work in one process
@@ -68,23 +88,32 @@ function createMainWindow() {
68
88
win . webContents . loadURL ( store . get ( "url" ) ) ;
69
89
win . on ( "closed" , onClosed ) ;
70
90
71
- injectCSS ( win . webContents , path . join ( __dirname , "youtube-music.css" ) ) ;
72
- win . webContents . on ( "did-finish-load" , ( ) => {
73
- if ( is . dev ( ) ) {
74
- console . log ( "did finish load" ) ;
75
- win . webContents . openDevTools ( ) ;
91
+ win . on ( "move" , ( ) => {
92
+ let position = win . getPosition ( ) ;
93
+ store . set ( "window-position" , { x : position [ 0 ] , y : position [ 1 ] } ) ;
94
+ } ) ;
95
+
96
+ win . on ( "resize" , ( ) => {
97
+ const windowSize = win . getSize ( ) ;
98
+
99
+ store . set ( "window-maximized" , win . isMaximized ( ) ) ;
100
+ if ( ! win . isMaximized ( ) ) {
101
+ store . set ( "window-size" , { width : windowSize [ 0 ] , height : windowSize [ 1 ] } ) ;
76
102
}
77
103
} ) ;
78
104
79
- getEnabledPlugins ( ) . forEach ( ( plugin ) => {
80
- console . log ( "Loaded plugin - " + plugin ) ;
81
- const pluginPath = path . join ( __dirname , "plugins" , plugin , "back.js" ) ;
82
- fileExists ( pluginPath , ( ) => {
83
- const handle = require ( pluginPath ) ;
84
- handle ( win ) ;
85
- } ) ;
105
+ win . once ( "ready-to-show" , ( ) => {
106
+ if ( isAppVisible ( ) ) {
107
+ win . show ( ) ;
108
+ }
86
109
} ) ;
87
110
111
+ return win ;
112
+ }
113
+
114
+ app . on ( "browser-window-created" , ( event , win ) => {
115
+ loadPlugins ( win ) ;
116
+
88
117
win . webContents . on ( "did-fail-load" , ( ) => {
89
118
if ( is . dev ( ) ) {
90
119
console . log ( "did fail load" ) ;
@@ -128,29 +157,7 @@ function createMainWindow() {
128
157
options . webPreferences . affinity = "main-window" ;
129
158
}
130
159
) ;
131
-
132
- win . on ( "move" , ( ) => {
133
- let position = win . getPosition ( ) ;
134
- store . set ( "window-position" , { x : position [ 0 ] , y : position [ 1 ] } ) ;
135
- } ) ;
136
-
137
- win . on ( "resize" , ( ) => {
138
- const windowSize = win . getSize ( ) ;
139
-
140
- store . set ( "window-maximized" , win . isMaximized ( ) ) ;
141
- if ( ! win . isMaximized ( ) ) {
142
- store . set ( "window-size" , { width : windowSize [ 0 ] , height : windowSize [ 1 ] } ) ;
143
- }
144
- } ) ;
145
-
146
- win . once ( "ready-to-show" , ( ) => {
147
- if ( isAppVisible ( ) ) {
148
- win . show ( ) ;
149
- }
150
- } ) ;
151
-
152
- return win ;
153
- }
160
+ } ) ;
154
161
155
162
app . on ( "window-all-closed" , ( ) => {
156
163
if ( process . platform !== "darwin" ) {
0 commit comments