import Foundation import ServiceManagement // LaunchAtLogin controls the login item of EPOD Window Bar. The helper uses // SMAppService.mainApp. The helper logs an error and does not crash if the // register call or the unregister call fails. @MainActor enum LaunchAtLogin { // isEnabled is true if the app starts at login. static var isEnabled: Bool { return SMAppService.mainApp.status == .enabled } // setEnabled turns the login item on or off. static func setEnabled(_ on: Bool) { do { if on { if SMAppService.mainApp.status != .enabled { try SMAppService.mainApp.register() } } else { if SMAppService.mainApp.status == .enabled { try SMAppService.mainApp.unregister() } } } catch { Log.app.error("Launch at login change failed: \(error.localizedDescription, privacy: .public)") } } }