feat: keep launcher hidden when started at login
This commit is contained in:
@@ -93,6 +93,13 @@ private final class ApplicationDelegate: NSObject, NSApplicationDelegate {
|
||||
private lazy var launcher = LauncherWindowController()
|
||||
private lazy var shortcut = GlobalShortcut { [weak self] in self?.launcher.toggle() }
|
||||
private lazy var settings = SettingsWindowController(shortcut: shortcut)
|
||||
private var startupShortcutError: String?
|
||||
|
||||
private var isLoginLaunch: Bool {
|
||||
let event = NSAppleEventManager.shared().currentAppleEvent
|
||||
return event?.eventID == kAEOpenApplication
|
||||
&& event?.paramDescriptor(forKeyword: keyAEPropData)?.enumCodeValue == keyAELaunchedAsLogInItem
|
||||
}
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
let menu = NSMenu()
|
||||
@@ -102,21 +109,31 @@ private final class ApplicationDelegate: NSObject, NSApplicationDelegate {
|
||||
let quitItem = menu.addItem(withTitle: "Quit Conjure", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
|
||||
quitItem.target = NSApplication.shared
|
||||
launcher.window?.contentView?.menu = menu
|
||||
launcher.present()
|
||||
if !isLoginLaunch {
|
||||
launcher.present()
|
||||
}
|
||||
do {
|
||||
try shortcut.start()
|
||||
} catch {
|
||||
settings.present(error: error.localizedDescription)
|
||||
startupShortcutError = error.localizedDescription
|
||||
if !isLoginLaunch {
|
||||
showSettings(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows: Bool) -> Bool {
|
||||
guard !isLoginLaunch else { return false }
|
||||
launcher.present()
|
||||
if startupShortcutError != nil {
|
||||
showSettings(nil)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@objc func showSettings(_ sender: Any?) {
|
||||
settings.present()
|
||||
settings.present(error: startupShortcutError)
|
||||
startupShortcutError = nil
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ notification: Notification) {
|
||||
|
||||
Reference in New Issue
Block a user