vibetunnel/VibeTunnel/Core/Services/StartupManager.swift
Peter Steinberger 702b623d7f Fix settings window not appearing from menu bar
Replace deprecated showSettingsWindow: selector with NSApp.openSettings() to properly show the Settings window when clicking "Settings..." in the menu bar. This aligns with the correct SwiftUI pattern used in VibeMeter.
2025-06-15 23:54:17 +02:00

44 lines
1.4 KiB
Swift

import Foundation
import os
import ServiceManagement
/// Protocol defining the interface for managing launch at login functionality.
@MainActor
public protocol StartupControlling: Sendable {
func setLaunchAtLogin(enabled: Bool)
var isLaunchAtLoginEnabled: Bool { get }
}
/// Default implementation of startup management using ServiceManagement framework.
///
/// This struct handles:
/// - Enabling/disabling launch at login
/// - Checking current launch at login status
/// - Integration with macOS ServiceManagement APIs
@MainActor
public struct StartupManager: StartupControlling {
private let logger = Logger(subsystem: "com.amantus.vibetunnel", category: "startup")
public init() {}
public func setLaunchAtLogin(enabled: Bool) {
do {
if enabled {
try SMAppService.mainApp.register()
logger.info("Successfully registered for launch at login.")
} else {
try SMAppService.mainApp.unregister()
logger.info("Successfully unregistered for launch at login.")
}
} catch {
logger
.error(
"Failed to \(enabled ? "register" : "unregister") for launch at login: \(error.localizedDescription)"
)
}
}
public var isLaunchAtLoginEnabled: Bool {
SMAppService.mainApp.status == .enabled
}
}