Преглед изворни кода

Add Window menu item to reopen the main window after close.

Address App Store review feedback: when the user closes the main window
with the red button the app stays in the Dock but previously offered no
menu-bar path to bring the window back. Add a persistent "App for Indeed"
entry at the top of the Window menu that is enabled when the window is
hidden and shows a checkmark when it is visible. Reuse the same
showMainWindow action for Dock icon reopen. Extend mainWindow lookup so
hidden windows are found reliably.

Also bump CURRENT_PROJECT_VERSION to 3 for resubmission.

Co-authored-by: Cursor <cursoragent@cursor.com>
Uzair Tahir пре 1 месец
родитељ
комит
eea5a86429

+ 4 - 4
App for Indeed.xcodeproj/project.pbxproj

@@ -269,8 +269,8 @@
 				CODE_SIGN_ENTITLEMENTS = "App for Indeed/App for Indeed.entitlements";
 				CODE_SIGN_STYLE = Automatic;
 				COMBINE_HIDPI_IMAGES = YES;
-				CURRENT_PROJECT_VERSION = 1;
-				DEVELOPMENT_TEAM = "";
+				CURRENT_PROJECT_VERSION = 3;
+				DEVELOPMENT_TEAM = NNC7V99779;
 				ENABLE_APP_SANDBOX = YES;
 				ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES;
 				ENABLE_USER_SELECTED_FILES = readonly;
@@ -309,8 +309,8 @@
 				CODE_SIGN_ENTITLEMENTS = "App for Indeed/App for Indeed.entitlements";
 				CODE_SIGN_STYLE = Automatic;
 				COMBINE_HIDPI_IMAGES = YES;
-				CURRENT_PROJECT_VERSION = 1;
-				DEVELOPMENT_TEAM = "";
+				CURRENT_PROJECT_VERSION = 3;
+				DEVELOPMENT_TEAM = NNC7V99779;
 				ENABLE_APP_SANDBOX = YES;
 				ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES;
 				ENABLE_USER_SELECTED_FILES = readonly;

+ 1 - 1
App for Indeed.xcodeproj/xcshareddata/xcschemes/App for Indeed.xcscheme

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
    LastUpgradeVersion = "2640"
-   version = "1.7">
+   version = "1.8">
    <BuildAction
       parallelizeBuildables = "YES"
       buildImplicitDependencies = "YES"

+ 38 - 5
App for Indeed/AppDelegate.swift

@@ -39,15 +39,19 @@ enum AppWindowConfiguration {
         app.mainWindow
             ?? app.keyWindow
             ?? app.windows.first(where: { $0.isVisible && $0.canBecomeKey })
+            ?? app.windows.first(where: { $0.canBecomeKey })
     }
 }
 
 @main
-class AppDelegate: NSObject, NSApplicationDelegate {
+class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
 
     /// Avoids hammering StoreKit when `didBecomeActive` fires in quick succession (e.g. after system sheets).
     private var lastSubscriptionRefreshAt: Date?
 
+    /// Window menu item that re-opens the main window after the user closes it with the red button.
+    private var showMainWindowMenuItem: NSMenuItem?
+
     func applicationWillFinishLaunching(_ notification: Notification) {
         AppLanguageManager.shared.applyStoredPreferenceOnLaunch()
         AppAppearanceManager.shared.apply()
@@ -73,6 +77,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
         }
 
         // Initial StoreKit refresh runs on `LoadingViewController` before the dashboard is shown.
+        installMainWindowMenuItem()
         NSApp.activate(ignoringOtherApps: true)
         applyDefaultWindowSize()
     }
@@ -111,12 +116,40 @@ class AppDelegate: NSObject, NSApplicationDelegate {
     /// Clicking the Dock icon after closing the window should bring it back.
     func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
         guard !flag else { return true }
-        let window = AppWindowConfiguration.mainWindow(in: sender)
-            ?? sender.windows.first(where: { $0.canBecomeKey })
-        window?.makeKeyAndOrderFront(self)
-        sender.activate(ignoringOtherApps: true)
+        showMainWindow(self)
         return true
     }
+
+    /// Adds a persistent Window menu entry so reviewers and users can reopen the app after closing its window.
+    private func installMainWindowMenuItem() {
+        guard let windowMenu = NSApp.windowsMenu else { return }
+        guard showMainWindowMenuItem == nil else { return }
+
+        let item = NSMenuItem(
+            title: AppMarketingLinks.appDisplayName,
+            action: #selector(showMainWindow(_:)),
+            keyEquivalent: ""
+        )
+        item.target = self
+        showMainWindowMenuItem = item
+        windowMenu.insertItem(item, at: 0)
+        windowMenu.insertItem(NSMenuItem.separator(), at: 1)
+        windowMenu.delegate = self
+    }
+
+    @objc func showMainWindow(_ sender: Any?) {
+        guard let window = AppWindowConfiguration.mainWindow() else { return }
+        window.makeKeyAndOrderFront(sender)
+        NSApp.activate(ignoringOtherApps: true)
+    }
+
+    func menuNeedsUpdate(_ menu: NSMenu) {
+        guard menu === NSApp.windowsMenu, let item = showMainWindowMenuItem else { return }
+        let window = AppWindowConfiguration.mainWindow()
+        let isVisible = window?.isVisible == true
+        item.isEnabled = !isVisible
+        item.state = isVisible ? .on : .off
+    }
 }
 
 // MARK: - Main window close (hide on red button, do not quit)