Skip to content

Commit

Permalink
Add wasLaunchedAtLogin property
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Dec 21, 2023
1 parent db030a1 commit a04ec1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Sources/LaunchAtLogin/LaunchAtLogin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ public enum LaunchAtLogin {
}
}
}

/**
Whether the app was launched at login.

- Important: This property must only be checked in `NSApplicationDelegate#applicationDidFinishLaunching`.
*/
public static var wasLaunchedAtLogin: Bool {
let event = NSAppleEventManager.shared().currentAppleEvent
return event?.eventID == kAEOpenApplication
&& event?.paramDescriptor(forKeyword: keyAEPropData)?.enumCodeValue == keyAELaunchedAsLogInItem
}
}

extension LaunchAtLogin {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# LaunchAtLogin *(Modern)*
# LaunchAtLogin

> Add “Launch at Login” functionality to your macOS app in seconds
Expand Down

0 comments on commit a04ec1c

Please sign in to comment.