1
1
import is from 'electron-is' ;
2
- import {
3
- app ,
4
- BrowserWindow ,
5
- clipboard ,
6
- dialog ,
7
- Menu ,
8
- MenuItem ,
9
- shell ,
10
- } from 'electron' ;
2
+ import { app , BrowserWindow , clipboard , dialog , Menu , MenuItem , shell , } from 'electron' ;
11
3
import prompt from 'custom-electron-prompt' ;
12
4
import { satisfies } from 'semver' ;
13
5
@@ -235,16 +227,41 @@ export const mainMenuTemplate = async (
235
227
'main.menu.options.submenu.visual-tweaks.submenu.theme.label' ,
236
228
) ,
237
229
submenu : [
238
- {
239
- label : t (
240
- 'main.menu.options.submenu.visual-tweaks.submenu.theme.submenu.no-theme' ,
241
- ) ,
242
- type : 'radio' ,
243
- checked : config . get ( 'options.themes' ) ?. length === 0 , // Todo rename "themes"
244
- click ( ) {
245
- config . set ( 'options.themes' , [ ] ) ;
246
- } ,
247
- } ,
230
+ ...( ( config . get ( 'options.themes' ) ?. length ?? 0 ) === 0
231
+ ? [
232
+ {
233
+ label : t (
234
+ 'main.menu.options.submenu.visual-tweaks.submenu.theme.submenu.no-theme' ,
235
+ ) ,
236
+ }
237
+ ]
238
+ : [ ] ) ,
239
+ ...config . get ( 'options.themes' ) ?. map ( ( theme : string ) => ( {
240
+ type : 'normal' as const ,
241
+ label : theme ,
242
+ async click ( ) {
243
+ const { response } = await dialog . showMessageBox ( win , {
244
+ type : 'question' ,
245
+ defaultId : 1 ,
246
+ title : t (
247
+ 'main.menu.options.submenu.visual-tweaks.submenu.theme.dialog.remove-theme' ,
248
+ ) ,
249
+ message : t (
250
+ 'main.menu.options.submenu.visual-tweaks.submenu.theme.dialog.remove-theme-message' ,
251
+ { theme } ,
252
+ ) ,
253
+ buttons : [
254
+ t ( 'main.menu.options.submenu.visual-tweaks.submenu.theme.dialog.button.cancel' ) ,
255
+ t ( 'main.menu.options.submenu.visual-tweaks.submenu.theme.dialog.button.remove' ) ,
256
+ ] ,
257
+ } ) ;
258
+
259
+ if ( response === 1 ) {
260
+ config . set ( 'options.themes' , config . get ( 'options.themes' ) ?. filter ( ( t ) => t !== theme ) ) ;
261
+ innerRefreshMenu ( ) ;
262
+ }
263
+ }
264
+ } ) ) ,
248
265
{ type : 'separator' } ,
249
266
{
250
267
label : t (
@@ -258,6 +275,7 @@ export const mainMenuTemplate = async (
258
275
} ) ;
259
276
if ( filePaths ) {
260
277
config . set ( 'options.themes' , filePaths ) ;
278
+ innerRefreshMenu ( ) ;
261
279
}
262
280
} ,
263
281
} ,
@@ -288,40 +306,40 @@ export const mainMenuTemplate = async (
288
306
} ,
289
307
...( ( is . windows ( ) || is . linux ( )
290
308
? [
291
- {
292
- label : t ( 'main.menu.options.submenu.hide-menu.label' ) ,
293
- type : 'checkbox' ,
294
- checked : config . get ( 'options.hideMenu' ) ,
295
- click ( item ) {
296
- config . setMenuOption ( 'options.hideMenu' , item . checked ) ;
297
- if ( item . checked && ! config . get ( 'options.hideMenuWarned' ) ) {
298
- dialog . showMessageBox ( win , {
299
- type : 'info' ,
300
- title : t (
301
- 'main.menu.options.submenu.hide-menu.dialog.title' ,
302
- ) ,
303
- message : t (
304
- 'main.menu.options.submenu.hide-menu.dialog.message' ,
305
- ) ,
306
- } ) ;
307
- }
308
- } ,
309
+ {
310
+ label : t ( 'main.menu.options.submenu.hide-menu.label' ) ,
311
+ type : 'checkbox' ,
312
+ checked : config . get ( 'options.hideMenu' ) ,
313
+ click ( item ) {
314
+ config . setMenuOption ( 'options.hideMenu' , item . checked ) ;
315
+ if ( item . checked && ! config . get ( 'options.hideMenuWarned' ) ) {
316
+ dialog . showMessageBox ( win , {
317
+ type : 'info' ,
318
+ title : t (
319
+ 'main.menu.options.submenu.hide-menu.dialog.title' ,
320
+ ) ,
321
+ message : t (
322
+ 'main.menu.options.submenu.hide-menu.dialog.message' ,
323
+ ) ,
324
+ } ) ;
325
+ }
309
326
} ,
310
- ]
327
+ } ,
328
+ ]
311
329
: [ ] ) satisfies Electron . MenuItemConstructorOptions [ ] ) ,
312
330
...( ( is . windows ( ) || is . macOS ( )
313
331
? // Only works on Win/Mac
314
332
// https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows
315
- [
316
- {
317
- label : t ( 'main.menu.options.submenu.start-at-login' ) ,
318
- type : 'checkbox' ,
319
- checked : config . get ( 'options.startAtLogin' ) ,
320
- click ( item ) {
321
- config . setMenuOption ( 'options.startAtLogin' , item . checked ) ;
322
- } ,
333
+ [
334
+ {
335
+ label : t ( 'main.menu.options.submenu.start-at-login' ) ,
336
+ type : 'checkbox' ,
337
+ checked : config . get ( 'options.startAtLogin' ) ,
338
+ click ( item ) {
339
+ config . setMenuOption ( 'options.startAtLogin' , item . checked ) ;
323
340
} ,
324
- ]
341
+ } ,
342
+ ]
325
343
: [ ] ) satisfies Electron . MenuItemConstructorOptions [ ] ) ,
326
344
{
327
345
label : t ( 'main.menu.options.submenu.tray.label' ) ,
@@ -475,25 +493,25 @@ export const mainMenuTemplate = async (
475
493
{ type : 'separator' } ,
476
494
is . macOS ( )
477
495
? {
478
- label : t (
479
- 'main.menu.options.submenu.advanced-options.submenu.toggle-dev-tools' ,
480
- ) ,
481
- // Cannot use "toggleDevTools" role in macOS
482
- click ( ) {
483
- const { webContents } = win ;
484
- if ( webContents . isDevToolsOpened ( ) ) {
485
- webContents . closeDevTools ( ) ;
486
- } else {
487
- webContents . openDevTools ( ) ;
488
- }
489
- } ,
490
- }
491
- : {
492
- label : t (
493
- 'main.menu.options.submenu.advanced-options.submenu.toggle-dev-tools' ,
494
- ) ,
495
- role : 'toggleDevTools' ,
496
+ label : t (
497
+ 'main.menu.options.submenu.advanced-options.submenu.toggle-dev-tools' ,
498
+ ) ,
499
+ // Cannot use "toggleDevTools" role in macOS
500
+ click ( ) {
501
+ const { webContents } = win ;
502
+ if ( webContents . isDevToolsOpened ( ) ) {
503
+ webContents . closeDevTools ( ) ;
504
+ } else {
505
+ webContents . openDevTools ( ) ;
506
+ }
496
507
} ,
508
+ }
509
+ : {
510
+ label : t (
511
+ 'main.menu.options.submenu.advanced-options.submenu.toggle-dev-tools' ,
512
+ ) ,
513
+ role : 'toggleDevTools' ,
514
+ } ,
497
515
{
498
516
label : t (
499
517
'main.menu.options.submenu.advanced-options.submenu.edit-config-json' ,
0 commit comments