@@ -6,6 +6,7 @@ const is = require("electron-is");
6
6
7
7
const { getAllPlugins } = require ( "./plugins/utils" ) ;
8
8
const config = require ( "./config" ) ;
9
+ const prompt = require ( "custom-electron-prompt" ) ;
9
10
10
11
const pluginEnabledMenu = ( win , plugin , label = "" , hasSubmenu = false ) => ( {
11
12
label : label || plugin ,
@@ -103,30 +104,38 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [
103
104
} ,
104
105
...( is . windows ( ) || is . linux ( )
105
106
? [
106
- {
107
- label : "Hide menu" ,
108
- type : "checkbox" ,
109
- checked : config . get ( "options.hideMenu" ) ,
110
- click : ( item ) => {
111
- config . set ( "options.hideMenu" , item . checked ) ;
112
- } ,
107
+ {
108
+ label : "Hide menu" ,
109
+ type : "checkbox" ,
110
+ checked : config . get ( "options.hideMenu" ) ,
111
+ click : ( item ) => {
112
+ config . set ( "options.hideMenu" , item . checked ) ;
113
113
} ,
114
- ]
114
+ } ,
115
+ ]
115
116
: [ ] ) ,
116
117
...( is . windows ( ) || is . macOS ( )
117
118
? // Only works on Win/Mac
118
- // https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows
119
- [
120
- {
121
- label : "Start at login" ,
122
- type : "checkbox" ,
123
- checked : config . get ( "options.startAtLogin" ) ,
124
- click : ( item ) => {
125
- config . set ( "options.startAtLogin" , item . checked ) ;
126
- } ,
119
+ // https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows
120
+ [
121
+ {
122
+ label : "Start at login" ,
123
+ type : "checkbox" ,
124
+ checked : config . get ( "options.startAtLogin" ) ,
125
+ click : ( item ) => {
126
+ config . set ( "options.startAtLogin" , item . checked ) ;
127
127
} ,
128
- ]
128
+ } ,
129
+ ]
129
130
: [ ] ) ,
131
+ {
132
+ label : "Proxy" ,
133
+ type : "checkbox" ,
134
+ checked : ! ! config . get ( "options.proxy" ) ,
135
+ click : ( item ) => {
136
+ setProxy ( item , win ) ;
137
+ }
138
+ } ,
130
139
{
131
140
label : "Tray" ,
132
141
submenu : [
@@ -194,56 +203,56 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [
194
203
} ,
195
204
...( ! isTray
196
205
? [
197
- {
198
- label : "View" ,
199
- submenu : withRoles
200
- ? [
201
- { role : "reload" } ,
202
- { role : "forceReload" } ,
203
- { type : "separator" } ,
204
- { role : "zoomIn" } ,
205
- { role : "zoomOut" } ,
206
- { role : "resetZoom" } ,
207
- ]
208
- : [
209
- {
210
- label : "Reload" ,
211
- click : ( ) => {
212
- win . webContents . reload ( ) ;
213
- } ,
214
- } ,
215
- {
216
- label : "Force Reload" ,
217
- click : ( ) => {
218
- win . webContents . reloadIgnoringCache ( ) ;
219
- } ,
220
- } ,
221
- { type : "separator" } ,
222
- {
223
- label : "Zoom In" ,
224
- click : ( ) => {
225
- win . webContents . setZoomLevel (
226
- win . webContents . getZoomLevel ( ) + 1
227
- ) ;
228
- } ,
229
- } ,
230
- {
231
- label : "Zoom Out" ,
232
- click : ( ) => {
233
- win . webContents . setZoomLevel (
234
- win . webContents . getZoomLevel ( ) - 1
235
- ) ;
236
- } ,
237
- } ,
238
- {
239
- label : "Reset Zoom" ,
240
- click : ( ) => {
241
- win . webContents . setZoomLevel ( 0 ) ;
242
- } ,
243
- } ,
244
- ] ,
245
- } ,
246
- ]
206
+ {
207
+ label : "View" ,
208
+ submenu : withRoles
209
+ ? [
210
+ { role : "reload" } ,
211
+ { role : "forceReload" } ,
212
+ { type : "separator" } ,
213
+ { role : "zoomIn" } ,
214
+ { role : "zoomOut" } ,
215
+ { role : "resetZoom" } ,
216
+ ]
217
+ : [
218
+ {
219
+ label : "Reload" ,
220
+ click : ( ) => {
221
+ win . webContents . reload ( ) ;
222
+ } ,
223
+ } ,
224
+ {
225
+ label : "Force Reload" ,
226
+ click : ( ) => {
227
+ win . webContents . reloadIgnoringCache ( ) ;
228
+ } ,
229
+ } ,
230
+ { type : "separator" } ,
231
+ {
232
+ label : "Zoom In" ,
233
+ click : ( ) => {
234
+ win . webContents . setZoomLevel (
235
+ win . webContents . getZoomLevel ( ) + 1
236
+ ) ;
237
+ } ,
238
+ } ,
239
+ {
240
+ label : "Zoom Out" ,
241
+ click : ( ) => {
242
+ win . webContents . setZoomLevel (
243
+ win . webContents . getZoomLevel ( ) - 1
244
+ ) ;
245
+ } ,
246
+ } ,
247
+ {
248
+ label : "Reset Zoom" ,
249
+ click : ( ) => {
250
+ win . webContents . setZoomLevel ( 0 ) ;
251
+ } ,
252
+ } ,
253
+ ] ,
254
+ } ,
255
+ ]
247
256
: [ ] ) ,
248
257
{
249
258
label : "Navigation" ,
@@ -273,13 +282,13 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [
273
282
} ,
274
283
...( ! isTray
275
284
? [
276
- {
277
- label : "Quit App" ,
278
- click : ( ) => {
279
- app . quit ( ) ;
280
- } ,
285
+ {
286
+ label : "Quit App" ,
287
+ click : ( ) => {
288
+ app . quit ( ) ;
281
289
} ,
282
- ]
290
+ } ,
291
+ ]
283
292
: [ ] ) ,
284
293
] ,
285
294
} ,
@@ -318,3 +327,39 @@ module.exports.setApplicationMenu = (win) => {
318
327
const menu = Menu . buildFromTemplate ( menuTemplate ) ;
319
328
Menu . setApplicationMenu ( menu ) ;
320
329
} ;
330
+
331
+ const iconPath = path . join ( __dirname , "assets" , "youtube-music-tray.png" ) ;
332
+ const example = `Example: "socks5://127.0.0.1:9999"` ;
333
+ function setProxy ( item , win ) {
334
+ let options = {
335
+ title : 'Set Proxy' ,
336
+ label : 'Enter Proxy Address: (leave empty to disable)' ,
337
+ value : config . get ( "options.proxy" ) || example ,
338
+ inputAttrs : {
339
+ type : 'text'
340
+ } ,
341
+ type : 'input' ,
342
+ icon : iconPath ,
343
+ customStylesheet : "dark" ,
344
+ } ;
345
+ //TODO: custom bar on prompt need testing on macOS
346
+ if ( ! is . macOS ( ) ) {
347
+ Object . assign ( options , {
348
+ frame : false ,
349
+ customScript : path . join ( __dirname , "plugins" , "in-app-menu" , "prompt-custom-titlebar.js" ) ,
350
+ enableRemoteModule : true ,
351
+ height : 200 ,
352
+ width : 450 ,
353
+ } ) ;
354
+ }
355
+ prompt ( options , win )
356
+ . then ( input => {
357
+ if ( input !== null && input !== example ) {
358
+ config . set ( "options.proxy" , input ) ;
359
+ item . checked = input !== "" ;
360
+ } else { //user pressed cancel
361
+ item . checked = ! item . checked ; //reset checkbox
362
+ }
363
+ } )
364
+ . catch ( console . error ) ;
365
+ }
0 commit comments