소스 검색

Fix App Review Guideline 4.0 by allowing the main window to reopen from the Window menu.

Closing the main window hid it while keeping the app running, but there was no menu path to bring it back. Add Window > Printer App - All Printers (⌘0), wired through a shared showMainWindow helper also used for Dock reopen and Preferences.

Co-authored-by: Cursor <cursoragent@cursor.com>
Uzair Tahir 1 주 전
부모
커밋
3681e81342
2개의 변경된 파일44개의 추가작업 그리고 6개의 파일을 삭제
  1. 38 6
      smart_printer/AppDelegate.swift
  2. 6 0
      smart_printer/Base.lproj/Main.storyboard

+ 38 - 6
smart_printer/AppDelegate.swift

@@ -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
     }

+ 6 - 0
smart_printer/Base.lproj/Main.storyboard

@@ -634,6 +634,12 @@
                                 <modifierMask key="keyEquivalentModifierMask"/>
                                 <menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
                                     <items>
+                                        <menuItem title="Printer App - All Printers" keyEquivalent="0" id="SpW-Mn-Rw1">
+                                            <connections>
+                                                <action selector="showMainWindow:" target="Voe-Tx-rLC" id="SpW-Ac-001"/>
+                                            </connections>
+                                        </menuItem>
+                                        <menuItem isSeparatorItem="YES" id="SpW-Sep-001"/>
                                         <menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
                                             <connections>
                                                 <action selector="performMiniaturize:" target="Ady-hI-5gd" id="VwT-WD-YPe"/>