|
|
@@ -23,6 +23,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
resolveMainWindowController()
|
|
|
configureMainWindow()
|
|
|
configurePreferencesMenu()
|
|
|
+ configureWindowMenu()
|
|
|
observeContactChanges()
|
|
|
prefetchContactsIfAuthorized()
|
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
|
@@ -49,11 +50,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
}
|
|
|
|
|
|
@objc func showSettings(_ sender: Any?) {
|
|
|
- NSApp.activate(ignoringOtherApps: true)
|
|
|
- mainWindow?.makeKeyAndOrderFront(nil)
|
|
|
+ showMainWindow(sender)
|
|
|
NotificationCenter.default.post(name: .showSettings, object: nil)
|
|
|
}
|
|
|
|
|
|
+ @objc func showMainWindow(_ sender: Any?) {
|
|
|
+ resolveMainWindowController()
|
|
|
+ mainWindowController?.showWindow(sender)
|
|
|
+ mainWindow?.makeKeyAndOrderFront(sender)
|
|
|
+ NSApp.activate(ignoringOtherApps: true)
|
|
|
+ }
|
|
|
+
|
|
|
private func configurePreferencesMenu() {
|
|
|
guard let preferencesItem = NSApp.mainMenu?
|
|
|
.item(withTitle: AppStoreConfig.displayName)?
|
|
|
@@ -63,16 +70,41 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
preferencesItem.action = #selector(showSettings(_:))
|
|
|
}
|
|
|
|
|
|
+ /// Ensures Window > [app name] can reopen the main window after it is closed.
|
|
|
+ private func configureWindowMenu() {
|
|
|
+ guard let windowMenu = NSApp.windowsMenu
|
|
|
+ ?? NSApp.mainMenu?.item(withTitle: "Window")?.submenu else { return }
|
|
|
+
|
|
|
+ let title = AppStoreConfig.displayName
|
|
|
+ if let existing = windowMenu.items.first(where: {
|
|
|
+ $0.title == title || $0.action == #selector(showMainWindow(_:))
|
|
|
+ }) {
|
|
|
+ existing.title = title
|
|
|
+ existing.target = self
|
|
|
+ existing.action = #selector(showMainWindow(_:))
|
|
|
+ if existing.keyEquivalent.isEmpty {
|
|
|
+ existing.keyEquivalent = "0"
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let showItem = NSMenuItem(
|
|
|
+ title: title,
|
|
|
+ action: #selector(showMainWindow(_:)),
|
|
|
+ keyEquivalent: "0"
|
|
|
+ )
|
|
|
+ showItem.target = self
|
|
|
+ windowMenu.insertItem(showItem, at: 0)
|
|
|
+ windowMenu.insertItem(.separator(), at: 1)
|
|
|
+ }
|
|
|
+
|
|
|
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
|
|
false
|
|
|
}
|
|
|
|
|
|
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
|
|
if !flag {
|
|
|
- resolveMainWindowController()
|
|
|
- mainWindowController?.showWindow(self)
|
|
|
- mainWindowController?.window?.makeKeyAndOrderFront(self)
|
|
|
- NSApp.activate(ignoringOtherApps: true)
|
|
|
+ showMainWindow(sender)
|
|
|
}
|
|
|
return true
|
|
|
}
|