@@ -378,6 +378,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
378
378
return nil
379
379
}
380
380
381
+ #if targetEnvironment(macCatalyst)
382
+ var isMainOrMiniPlayerPlayerOpen : Bool {
383
+ return isMainWindowOpen || isShowingMiniPlayer
384
+ }
385
+
386
+ var isMainWindowOpen : Bool {
387
+ return !UIApplication. shared. connectedScenes
388
+ . flatMap { ( $0 as? UIWindowScene ) ? . windows ?? [ ] }
389
+ . filter { ( $0. rootViewController as? SplitVC ) != nil }
390
+ . isEmpty
391
+ }
392
+
381
393
func closeMainWindow( ) {
382
394
// Close all main sessions (this might be more than one with multiple tabs open)
383
395
UIApplication . shared. connectedScenes
@@ -395,25 +407,60 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
395
407
let defaultActivity = NSUserActivity ( activityType: defaultWindowActivityType)
396
408
UIApplication . shared. requestSceneSessionActivation ( nil , userActivity: defaultActivity, options: nil , errorHandler: nil )
397
409
}
398
-
399
- #if targetEnvironment(macCatalyst)
410
+
411
+ public func rebuildMainMenu( ) {
412
+ UIMenuSystem . main. setNeedsRebuild ( )
413
+ }
400
414
401
415
override func buildMenu( with builder: any UIMenuBuilder ) {
402
416
super. buildMenu ( with: builder)
403
417
404
418
guard builder. system == . main else { return }
405
419
406
- // Add a settings menu
407
- let settingsMenu = UIMenu ( options: . displayInline, children: [
408
- UIKeyCommand ( title: " Settings… " , action: #selector( showSettings) , input: " , " , modifierFlags: . command)
420
+ // Add File menu
421
+ let fileMenu = UIMenu ( title: " File " , children: [
422
+ UIMenu ( options: . displayInline, children: [
423
+ UIAction ( title: " Open Player Window " , attributes: self . isMainOrMiniPlayerPlayerOpen ? . disabled : [ ] ) { _ in
424
+ self . openMainWindow ( )
425
+ } ,
426
+ UIAction ( title: " Close Player Window " , attributes: !self . isMainOrMiniPlayerPlayerOpen ? . disabled : [ ] ) { _ in
427
+ if self . isMainWindowOpen {
428
+ self . closeMainWindow ( )
429
+ } else if self . isShowingMiniPlayer {
430
+ self . closeMiniPlayer ( )
431
+ }
432
+ }
433
+ ] ) ,
434
+ UIMenu ( options: . displayInline, children: [
435
+ UIAction ( title: " Switch Library/Mini Player " ) { _ in
436
+ if self . isShowingMiniPlayer {
437
+ self . closeMiniPlayer ( )
438
+ self . openMainWindow ( )
439
+ } else {
440
+ self . closeMainWindow ( )
441
+ self . showMiniPlayer ( )
442
+ }
443
+ }
444
+ ] ) ,
445
+ // Add a settings menu
446
+ UIMenu ( options: . displayInline, children: [
447
+ UIKeyCommand ( title: " Open Settings " , action: #selector( showSettings) , input: " , " , modifierFlags: . command)
448
+ ] )
409
449
] )
410
- builder. insertSibling ( settingsMenu, afterMenu: . about)
450
+ builder. insertSibling ( fileMenu, beforeMenu: . view)
451
+
411
452
// Add media controls
412
453
builder. insertSibling ( buildControlsMenu ( ) , afterMenu: . view)
413
454
414
- // Remove "new window" and toolbar options
455
+ // Remove not needed default menu items
415
456
builder. remove ( menu: . toolbar)
416
- builder. remove ( menu: . newScene)
457
+ builder. remove ( menu: . file)
458
+ builder. remove ( menu: . edit)
459
+ builder. remove ( menu: . format)
460
+ builder. remove ( menu: . font)
461
+ builder. remove ( menu: . text)
462
+ builder. remove ( menu: . services)
463
+ builder. remove ( menu: . help)
417
464
418
465
if ( self . focusedWindowTitle == windowSettingsTitle) || ( self . focusedWindowTitle == windowMiniPlayerTitle) {
419
466
// Do any settings specific menu setup here
@@ -499,25 +546,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
499
546
}
500
547
501
548
let section3 = [
502
- UIAction ( title: self . player . playerMode . nextMode . description ) { _ in
549
+ UIAction ( title: " Switch Music/Podcast mode " ) { _ in
503
550
self . player. setPlayerMode ( self . player. playerMode. nextMode)
504
551
}
505
552
]
506
553
507
- let section4 = [
508
- UIAction ( title: self . isShowingMiniPlayer ? " Main Window " : " Mini Player " ) { _ in
509
- if self . isShowingMiniPlayer {
510
- self . closeMiniPlayer ( )
511
- // Is automatically opened
512
- //self.openMainWindow()
513
- } else {
514
- self . closeMainWindow ( )
515
- self . showMiniPlayer ( )
516
- }
517
- }
518
- ]
519
-
520
- let sections : [ [ UIMenuElement ] ] = [ section1, section2, section3, section4]
554
+ let sections : [ [ UIMenuElement ] ] = [ section1, section2, section3]
521
555
522
556
return UIMenu ( title: " Controls " , children: sections. reduce ( [ ] , { ( result, section) in
523
557
result + [ UIMenu ( options: . displayInline) ] + section
@@ -547,7 +581,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
547
581
UIApplication . shared. requestSceneSessionDestruction ( $0. session, options: options, errorHandler: nil )
548
582
}
549
583
}
550
- #endif
584
+ #endif
551
585
}
552
586
553
587
#if targetEnvironment(macCatalyst)
0 commit comments