You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Musubi/App/Sources/AppSettings.swift

43 lines
1.6 KiB

import Foundation
import MusubiCore
import Observation
import ServiceManagement
import SystemConfiguration
/// Persistent app settings (UserDefaults).
@MainActor @Observable
final class AppSettings {
var role: Role {
didSet { UserDefaults.standard.set(role.rawValue, forKey: "role") }
}
/// BSD name of the technical network interface, e.g. "en7".
var interfaceName: String {
didSet { UserDefaults.standard.set(interfaceName, forKey: "interfaceName") }
}
/// BSD name of the clinic network interface for the intercom (e.g. "en0"); empty = intercom off.
var clinicInterfaceName: String {
didSet { UserDefaults.standard.set(clinicInterfaceName, forKey: "clinicInterfaceName") }
}
/// Name other Macs see (the computer name, e.g. "Mac mini von Samuel").
let machineName: String = (SCDynamicStoreCopyComputerName(nil, nil) as String?) ?? Host.current().localizedName ?? "Musubi"
init() {
role = Role(rawValue: UserDefaults.standard.string(forKey: "role") ?? "") ?? .control
interfaceName = UserDefaults.standard.string(forKey: "interfaceName") ?? "en0"
clinicInterfaceName = UserDefaults.standard.string(forKey: "clinicInterfaceName") ?? ""
}
var launchAtLogin: Bool {
get { SMAppService.mainApp.status == .enabled }
set {
do {
if newValue { try SMAppService.mainApp.register() } else { try SMAppService.mainApp.unregister() }
} catch {
Log.ndi.error("Login item: \(error.localizedDescription, privacy: .public)")
}
}
}
}

Powered by TurnKey Linux.