punchnet-macos/punchnet/Core/LaunchManager.swift
2026-03-23 16:05:46 +08:00

39 lines
958 B
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LaunchManager.swift
// punchnet
//
// Created by on 2026/3/23.
//
import ServiceManagement
import Observation
@Observable
class LaunchManager {
// App
private let service = SMAppService.mainApp
//
var launchAtLogin: Bool
init() {
self.launchAtLogin = (service.status == .enabled)
}
func toggleLaunchAtLogin(enabled: Bool) throws {
if enabled {
try service.register()
} else {
try service.unregister()
}
// 3. View
self.launchAtLogin = (service.status == .enabled)
}
// 4.
func refreshLaunchStatus() {
self.launchAtLogin = (service.status == .enabled)
}
}