curtain/Sources/Curtain/LoginItem.swift
acamarata 30d5a77ffa v1.1 — settings window, modular lifecycle actions, login item, logo
Rework Curtain into a proper menu-bar app (Caffeine-style):
- SwiftUI settings window: app, on-start, on-idle, on-end, security, displays
- Modular ActionSet/ActionRunner — per-event toggles (disconnect/lock/screen-off/deactivate)
- Configurable idle timeout; open-at-login via SMAppService; optional menu bar
- Settings persisted in UserDefaults (shared with @AppStorage); salted-SHA256 password
- Drawn curtains logo (menu-bar template + offscreen-rendered app icon)
- Split into single-responsibility modules with comment blocks
2026-06-01 15:51:20 -04:00

18 lines
707 B
Swift

import Foundation
import ServiceManagement
/// Purpose: Toggle "open at login" via the modern SMAppService API (macOS 13+).
/// Only works for a real installed app bundle; a no-op when run loose.
/// SPORT: MASTER-LOGINITEM
enum LoginItem {
static var isEnabled: Bool { SMAppService.mainApp.status == .enabled }
static func set(_ 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 {
NSLog("Curtain: login item toggle failed: \(error.localizedDescription)")
}
}
}