Files
SpotiFLAC-Mobile/macos/Runner/AppDelegate.swift
T
zarzet 91e00e8735 fix(macos): give the Window menu the system tiling items
Flutter's menu bar replaces the main menu, and its Window menu was never
registered as the app's windows menu. macOS therefore left out Fill,
Center, Move & Resize and Full Screen Tile, and their keyboard shortcuts
did nothing in Mornye.

The app delegate now points NSApp.windowsMenu at the menu holding Bring
All to Front, found by its action so any localized title works, and does
so again whenever Flutter rebuilds the menu bar.
2026-10-22 00:51:13 +07:00

52 lines
1.9 KiB
Swift

import Cocoa
import FlutterMacOS
@main
class AppDelegate: FlutterAppDelegate {
override func applicationWillFinishLaunching(_ notification: Notification) {
#if !DEBUG
// macOS only keeps one instance per app copy. With a second copy (an
// old download next to /Applications, a mounted dmg), a notification or
// URL can start it too; hand over to the running instance instead.
if let bundleId = Bundle.main.bundleIdentifier,
let running = NSRunningApplication.runningApplications(
withBundleIdentifier: bundleId
).first(where: { $0 != NSRunningApplication.current })
{
running.activate()
exit(0)
}
#endif
super.applicationWillFinishLaunching(notification)
NotificationCenter.default.addObserver(
forName: NSApplication.didUpdateNotification, object: nil, queue: nil
) { [weak self] _ in
self?.adoptWindowsMenu()
}
}
/// Flutter's menu bar replaces the main menu, and its Window menu is not
/// the app's windows menu, so macOS leaves out the window tiling items
/// (Fill, Center, Move & Resize) and their shortcuts. The Window menu is
/// the one holding Bring All to Front, whatever its localized title.
private func adoptWindowsMenu() {
guard let mainMenu = NSApp.mainMenu else { return }
let menus = mainMenu.items.compactMap(\.submenu)
if let current = NSApp.windowsMenu, menus.contains(where: { $0 === current }) {
return
}
let arrange = #selector(NSApplication.arrangeInFront(_:))
guard let menu = menus.first(where: { $0.items.contains { $0.action == arrange } })
else { return }
NSApp.windowsMenu = menu
}
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}
override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
}