From 2fcabfd799ec7e5b2770de6de19d1382f7b5b737 Mon Sep 17 00:00:00 2001 From: Isaac Halvorson Date: Sat, 29 Apr 2023 18:45:42 -0500 Subject: [PATCH] Address app review comments + make app more better (#9) * Add Main Window button to Window menu item * Add make clean * More accurately decide if we should open the settings window * Bump build number to 6 * Exclude main window from Window menu so it can be manually added This is being done to comply with an App Review requirement * Bump build number to 7 * Bump version to 1.1.1 and build number to 9 --- CenterMouse.xcodeproj/project.pbxproj | 8 ++-- CenterMouse/Resources/Base.lproj/MainMenu.xib | 13 ++++-- CenterMouse/Sources/AppDelegate.swift | 44 ++++++++----------- CenterMouse/Sources/Settings.swift | 1 - Makefile | 4 ++ 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/CenterMouse.xcodeproj/project.pbxproj b/CenterMouse.xcodeproj/project.pbxproj index b4a0f84..26b5366 100644 --- a/CenterMouse.xcodeproj/project.pbxproj +++ b/CenterMouse.xcodeproj/project.pbxproj @@ -390,7 +390,7 @@ CODE_SIGN_IDENTITY = "-"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 5; + CURRENT_PROJECT_VERSION = 9; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = F2J52QJQ9Y; ENABLE_HARDENED_RUNTIME = YES; @@ -403,7 +403,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; PRODUCT_BUNDLE_IDENTIFIER = software.level.CenterMouse; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -419,7 +419,7 @@ CODE_SIGN_IDENTITY = "-"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 5; + CURRENT_PROJECT_VERSION = 9; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = F2J52QJQ9Y; ENABLE_HARDENED_RUNTIME = YES; @@ -432,7 +432,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; PRODUCT_BUNDLE_IDENTIFIER = software.level.CenterMouse; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; diff --git a/CenterMouse/Resources/Base.lproj/MainMenu.xib b/CenterMouse/Resources/Base.lproj/MainMenu.xib index c060194..a459da2 100644 --- a/CenterMouse/Resources/Base.lproj/MainMenu.xib +++ b/CenterMouse/Resources/Base.lproj/MainMenu.xib @@ -1,7 +1,7 @@ - + - + @@ -329,13 +329,20 @@ - + + + + + + + + diff --git a/CenterMouse/Sources/AppDelegate.swift b/CenterMouse/Sources/AppDelegate.swift index c2939cb..8333788 100644 --- a/CenterMouse/Sources/AppDelegate.swift +++ b/CenterMouse/Sources/AppDelegate.swift @@ -10,20 +10,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate { private var eventMonitor = EventMonitor() - /// Whether or not the app is relaunching after it has been launched and quit before - /// - /// We track this to know whether or not to open the Settings window. If this is a - /// fresh relaunch, we _don't_ want to open the Settings window right away. - private var isRelaunch = false - - func applicationWillFinishLaunching(_ notification: Notification) { - if Defaults[.firstTimeAppLaunched] { - Defaults[.firstTimeAppLaunched] = false - } else { - isRelaunch = true - } - } - func applicationDidFinishLaunching(_ notification: Notification) { window = NSWindow( contentRect: NSZeroRect, @@ -33,12 +19,25 @@ final class AppDelegate: NSObject, NSApplicationDelegate { ) window.title = "CenterMouse" + + // Excluding this from the Window menu so that it can be manually added. + // This is being done to comply with an App Review requirement. + window.isExcludedFromWindowsMenu = true + window.contentView = NSHostingView(rootView: SettingsView()) windowController = NSWindowController(window: window) + + if launchedAsLogInItem == false { + openSettingsWindow() + } } - func applicationDidBecomeActive(_ notification: Notification) { - openSettingsWindow() + private var launchedAsLogInItem: Bool { + // source: https://stackoverflow.com/a/19890943/4118208 + guard let event = NSAppleEventManager.shared().currentAppleEvent else { return false } + return + event.eventID == kAEOpenApplication && + event.paramDescriptor(forKeyword: keyAEPropData)?.enumCodeValue == keyAELaunchedAsLogInItem } func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { @@ -50,6 +49,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate { openSettingsWindow() } + @IBAction func windowMenuMainWindowItemActivated(_ sender: NSMenuItem) { + openSettingsWindow() + } + func openSettingsWindow() { // Works around an annoyance where the app always comes to the foreground when // being previewed in Xcode's SwiftUI Canvas. @@ -59,15 +62,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate { return } - // We only need to check whether this is a relaunch the first time this method - // is called (by `applicationDidBecomeActive(_:)`). After that, we'll want to - // open the Settings window whenever this method is called, so we set the value - // to `false`. - guard isRelaunch == false else { - isRelaunch = false - return - } - windowController.window?.center() windowController.showWindow(self) NSApp.activate(ignoringOtherApps: true) diff --git a/CenterMouse/Sources/Settings.swift b/CenterMouse/Sources/Settings.swift index 836b750..174d31a 100644 --- a/CenterMouse/Sources/Settings.swift +++ b/CenterMouse/Sources/Settings.swift @@ -4,7 +4,6 @@ import Defaults extension Defaults.Keys { static let hideDockIcon = Key("hideDockIcon", default: false) static let monitorSystemEvents = Key("monitorSystemEvents", default: true) - static let firstTimeAppLaunched = Key("firstTimeAppLaunched", default: true) } enum Settings { diff --git a/Makefile b/Makefile index 5730e3b..18e2144 100644 --- a/Makefile +++ b/Makefile @@ -8,3 +8,7 @@ build: @echo "Building project..." @$(scripts_dir)build.sh .PHONY: build + +clean: + rm -rf $(project_dir)DerivedData +.PHONY: clean