@@ -10,20 +10,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
1010
1111 private var eventMonitor = EventMonitor ( )
1212
13- /// Whether or not the app is relaunching after it has been launched and quit before
14- ///
15- /// We track this to know whether or not to open the Settings window. If this is a
16- /// fresh relaunch, we _don't_ want to open the Settings window right away.
17- private var isRelaunch = false
18-
19- func applicationWillFinishLaunching( _ notification: Notification ) {
20- if Defaults [ . firstTimeAppLaunched] {
21- Defaults [ . firstTimeAppLaunched] = false
22- } else {
23- isRelaunch = true
24- }
25- }
26-
2713 func applicationDidFinishLaunching( _ notification: Notification ) {
2814 window = NSWindow (
2915 contentRect: NSZeroRect,
@@ -33,12 +19,25 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
3319 )
3420
3521 window. title = " CenterMouse "
22+
23+ // Excluding this from the Window menu so that it can be manually added.
24+ // This is being done to comply with an App Review requirement.
25+ window. isExcludedFromWindowsMenu = true
26+
3627 window. contentView = NSHostingView ( rootView: SettingsView ( ) )
3728 windowController = NSWindowController ( window: window)
29+
30+ if launchedAsLogInItem == false {
31+ openSettingsWindow ( )
32+ }
3833 }
3934
40- func applicationDidBecomeActive( _ notification: Notification ) {
41- openSettingsWindow ( )
35+ private var launchedAsLogInItem : Bool {
36+ // source: https://stackoverflow.com/a/19890943/4118208
37+ guard let event = NSAppleEventManager . shared ( ) . currentAppleEvent else { return false }
38+ return
39+ event. eventID == kAEOpenApplication &&
40+ event. paramDescriptor ( forKeyword: keyAEPropData) ? . enumCodeValue == keyAELaunchedAsLogInItem
4241 }
4342
4443 func applicationShouldHandleReopen( _ sender: NSApplication , hasVisibleWindows flag: Bool ) -> Bool {
@@ -50,6 +49,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
5049 openSettingsWindow ( )
5150 }
5251
52+ @IBAction func windowMenuMainWindowItemActivated( _ sender: NSMenuItem ) {
53+ openSettingsWindow ( )
54+ }
55+
5356 func openSettingsWindow( ) {
5457 // Works around an annoyance where the app always comes to the foreground when
5558 // being previewed in Xcode's SwiftUI Canvas.
@@ -59,15 +62,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
5962 return
6063 }
6164
62- // We only need to check whether this is a relaunch the first time this method
63- // is called (by `applicationDidBecomeActive(_:)`). After that, we'll want to
64- // open the Settings window whenever this method is called, so we set the value
65- // to `false`.
66- guard isRelaunch == false else {
67- isRelaunch = false
68- return
69- }
70-
7165 windowController. window? . center ( )
7266 windowController. showWindow ( self )
7367 NSApp . activate ( ignoringOtherApps: true )
0 commit comments