|
1 | 1 | import AppKit |
2 | 2 | import KestrelBarLib |
| 3 | +import ServiceManagement |
3 | 4 |
|
4 | 5 | class AppDelegate: NSObject, NSApplicationDelegate { |
5 | 6 | private var statusItem: NSStatusItem! |
@@ -276,6 +277,23 @@ class AppDelegate: NSObject, NSApplicationDelegate { |
276 | 277 |
|
277 | 278 | settingsSub.addItem(NSMenuItem.separator()) |
278 | 279 |
|
| 280 | + // Launch at Login |
| 281 | + let launchAtLogin = SMAppService.mainApp.status == .enabled |
| 282 | + let launchCheck = launchAtLogin ? "\u{2713} " : " " |
| 283 | + let launchItem = NSMenuItem( |
| 284 | + title: "\(launchCheck)Launch at Login", |
| 285 | + action: #selector(toggleLaunchAtLogin), |
| 286 | + keyEquivalent: "" |
| 287 | + ) |
| 288 | + launchItem.target = self |
| 289 | + launchItem.attributedTitle = NSAttributedString( |
| 290 | + string: "\(launchCheck)Launch at Login", |
| 291 | + attributes: [.font: NSFont.systemFont(ofSize: 12, weight: launchAtLogin ? .semibold : .regular)] |
| 292 | + ) |
| 293 | + settingsSub.addItem(launchItem) |
| 294 | + |
| 295 | + settingsSub.addItem(NSMenuItem.separator()) |
| 296 | + |
279 | 297 | // Project link |
280 | 298 | let linkItem = NSMenuItem( |
281 | 299 | title: "About Kestrel...", |
@@ -561,6 +579,19 @@ class AppDelegate: NSObject, NSApplicationDelegate { |
561 | 579 | buildMenu() |
562 | 580 | } |
563 | 581 |
|
| 582 | + @objc private func toggleLaunchAtLogin() { |
| 583 | + do { |
| 584 | + if SMAppService.mainApp.status == .enabled { |
| 585 | + try SMAppService.mainApp.unregister() |
| 586 | + } else { |
| 587 | + try SMAppService.mainApp.register() |
| 588 | + } |
| 589 | + } catch { |
| 590 | + print("[KestrelBar] launch at login toggle failed: \(error)") |
| 591 | + } |
| 592 | + buildMenu() |
| 593 | + } |
| 594 | + |
564 | 595 | @objc private func openProject() { |
565 | 596 | NSWorkspace.shared.open(URL(string: "https://github.com/akuligowski9/kestrel")!) |
566 | 597 | } |
|
0 commit comments