Refactor and Rename to CommandNotch
This commit is contained in:
24
Downterm/CommandNotch/Managers/LaunchAtLoginHelper.swift
Normal file
24
Downterm/CommandNotch/Managers/LaunchAtLoginHelper.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
import ServiceManagement
|
||||
|
||||
/// Registers / unregisters the app as a login item using the
|
||||
/// modern SMAppService API (macOS 13+).
|
||||
enum LaunchAtLoginHelper {
|
||||
|
||||
static func setEnabled(_ enabled: Bool) {
|
||||
let service = SMAppService.mainApp
|
||||
do {
|
||||
if enabled {
|
||||
try service.register()
|
||||
} else {
|
||||
try service.unregister()
|
||||
}
|
||||
} catch {
|
||||
print("[LaunchAtLogin] Failed to \(enabled ? "register" : "unregister"): \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads the current registration state from the system.
|
||||
static var isEnabled: Bool {
|
||||
SMAppService.mainApp.status == .enabled
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user