Phase 6: Lüftersteuerung über privilegierten Helfer
Das Sicherheitsnetz kommt zuerst und liegt als reine Funktion vor — 17 Tests, kein Hardwarezugriff nötig. Es sitzt im Helfer, nicht in der Oberfläche: die kann abstürzen, hängen oder beendet sein, während die Lüfter auf einem festen Wert stehen. Genau dafür ist es da. Vier Regeln, nicht abschaltbar: nie unter das Firmware-Minimum, Rückfall auf Automatik ab 95 °C, Rückfall wenn der Herzschlag fünf Sekunden ausbleibt, Rückfall beim Beenden. Ohne lesbare Temperatur wird gar nicht gesteuert — blind eine feste Drehzahl zu halten wäre die falsche Antwort auf fehlende Information. Die App sagt dem Helfer NICHT, wie warm es ist. Er misst selbst. Sonst hinge das Netz an der Ehrlichkeit eines Prozesses, der abstürzen, hängen oder — bei einer manipulierten Kopie — schlicht lügen kann. Der Herzschlag sagt nur "ich lebe noch". Der Helfer entscheidet jede Sekunde neu, nicht nur beim Setzen: nur so greifen Wachhund und Temperaturwächter auch dann, wenn von der App nie wieder etwas kommt. Geschrieben wird nur bei Änderung — jeder SMC-Schreibvorgang ist ein Eingriff. Der Schreibpfad existiert ausschließlich im Helfer, als eigene Kopie statt geteilter Bibliothek. Was im App-Prozess nicht vorhanden ist, kann dort auch nicht versehentlich aufgerufen werden. XPC prüft die Signatur in BEIDE Richtungen. Ohne das könnte jedes Programm auf dem Rechner die Lüfter eines root-Dienstes steuern — der Mach-Dienst ist systemweit sichtbar. Drei Fallstricke beim Einbetten, alle nachgemessen: Xcode signiert Kommandozeilenprogramme unter dem Dateinamen. Der Helfer hieß damit "OnyxHelper" statt com.scarriffleservices.onyx.helper, und die App hätte ihren eigenen Helfer abgelehnt. Behoben über eine in die Binary eingebettete Info.plist (CREATE_INFOPLIST_SECTION_IN_BINARY). Der Build-Schritt läuft nach Xcodes Signatur; das Kopieren bricht das Siegel des App-Bundles. Also wird zum Schluss neu signiert — mit denselben Entitlements, sonst gingen App-Group, WeatherKit und die TCC-Berechtigungen verloren. Mit deklarierten outputFiles übersprang Xcode den Schritt, obwohl sich das Programm geändert hatte. Geprüft: App-Siegel gültig (deep), beide Signaturanforderungen erfüllt, alle sieben Entitlements erhalten. 162 Tests grün.
This commit is contained in:
163
Onyx/FanControl.swift
Normal file
163
Onyx/FanControl.swift
Normal file
@@ -0,0 +1,163 @@
|
||||
import Foundation
|
||||
import ServiceManagement
|
||||
import OSLog
|
||||
import OnyxHelperProtocol
|
||||
|
||||
private let log = Logger(subsystem: "com.scarriffleservices.onyx", category: "FanControl")
|
||||
|
||||
/// Die App-Seite der Lüftersteuerung.
|
||||
///
|
||||
/// Sie darf **wünschen**, nicht bestimmen. Ob eine Drehzahl gesetzt wird,
|
||||
/// entscheidet allein das Sicherheitsnetz im Helfer — mit Temperaturen, die er
|
||||
/// selbst misst. Diese Klasse hält nur die Verbindung und den Herzschlag.
|
||||
@MainActor
|
||||
@Observable
|
||||
public final class FanControl {
|
||||
|
||||
public enum InstallState: Equatable {
|
||||
case notInstalled
|
||||
case requiresApproval
|
||||
case installed
|
||||
case failed(String)
|
||||
}
|
||||
|
||||
public private(set) var installState: InstallState = .notInstalled
|
||||
public private(set) var report: FanStatusReport?
|
||||
public private(set) var lastError: String?
|
||||
|
||||
private var connection: NSXPCConnection?
|
||||
private var heartbeatTimer: Timer?
|
||||
private var statusTimer: Timer?
|
||||
|
||||
private var service: SMAppService {
|
||||
SMAppService.daemon(plistName: "com.scarriffleservices.onyx.helper.plist")
|
||||
}
|
||||
|
||||
public init() { refreshInstallState() }
|
||||
|
||||
// MARK: - Einrichtung
|
||||
|
||||
public func refreshInstallState() {
|
||||
switch service.status {
|
||||
case .enabled: installState = .installed
|
||||
case .requiresApproval: installState = .requiresApproval
|
||||
case .notRegistered, .notFound: installState = .notInstalled
|
||||
@unknown default: installState = .notInstalled
|
||||
}
|
||||
}
|
||||
|
||||
/// Registriert den Helfer. macOS fragt dabei nach Zustimmung.
|
||||
public func install() {
|
||||
do {
|
||||
try service.register()
|
||||
refreshInstallState()
|
||||
log.notice("Helfer registriert: \(String(describing: self.installState))")
|
||||
} catch {
|
||||
// `requiresApproval` kommt hier als Fehler an und ist keiner: der
|
||||
// Nutzer muss den Dienst nur noch in den Systemeinstellungen
|
||||
// freigeben.
|
||||
refreshInstallState()
|
||||
if installState != .requiresApproval {
|
||||
installState = .failed(error.localizedDescription)
|
||||
log.error("Helfer nicht registrierbar: \(error.localizedDescription, privacy: .public)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Entfernt den Helfer wieder. Die Lüfter fallen dabei auf Automatik.
|
||||
public func uninstall() async {
|
||||
for fan in report?.fans ?? [] { setAutomatic(index: fan.index) }
|
||||
disconnect()
|
||||
try? await service.unregister()
|
||||
refreshInstallState()
|
||||
}
|
||||
|
||||
/// Öffnet die Stelle, an der macOS den Dienst freigeben lässt.
|
||||
public func openApprovalSettings() {
|
||||
SMAppService.openSystemSettingsLoginItems()
|
||||
}
|
||||
|
||||
// MARK: - Verbindung
|
||||
|
||||
private func proxy() -> OnyxHelperProtocol? {
|
||||
if connection == nil {
|
||||
let connection = NSXPCConnection(machServiceName: OnyxHelper.machServiceName,
|
||||
options: .privileged)
|
||||
connection.remoteObjectInterface = NSXPCInterface(with: OnyxHelperProtocol.self)
|
||||
// In beide Richtungen prüfen: die App spricht nur mit einem Helfer,
|
||||
// der ebenso signiert ist wie sie. Sonst könnte ein untergeschobener
|
||||
// Dienst unter demselben Namen die Antworten liefern.
|
||||
try? connection.setCodeSigningRequirement(OnyxHelper.helperRequirement)
|
||||
|
||||
connection.invalidationHandler = { [weak self] in
|
||||
Task { @MainActor in self?.connection = nil }
|
||||
}
|
||||
connection.interruptionHandler = { [weak self] in
|
||||
Task { @MainActor in self?.connection = nil }
|
||||
}
|
||||
connection.resume()
|
||||
self.connection = connection
|
||||
}
|
||||
return connection?.remoteObjectProxyWithErrorHandler { [weak self] error in
|
||||
Task { @MainActor in
|
||||
self?.lastError = error.localizedDescription
|
||||
log.error("Helfer nicht erreichbar: \(error.localizedDescription, privacy: .public)")
|
||||
}
|
||||
} as? OnyxHelperProtocol
|
||||
}
|
||||
|
||||
private func disconnect() {
|
||||
heartbeatTimer?.invalidate(); heartbeatTimer = nil
|
||||
statusTimer?.invalidate(); statusTimer = nil
|
||||
connection?.invalidate(); connection = nil
|
||||
report = nil
|
||||
}
|
||||
|
||||
/// Beginnt zu beobachten und den Herzschlag zu senden.
|
||||
///
|
||||
/// Der Herzschlag ist die Lebensversicherung: bleibt er aus — weil Onyx
|
||||
/// abstürzt, beendet wird oder hängt — fallen die Lüfter im Helfer nach
|
||||
/// fünf Sekunden auf Automatik zurück.
|
||||
public func start() {
|
||||
guard installState == .installed, heartbeatTimer == nil else { return }
|
||||
|
||||
heartbeatTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { _ in
|
||||
MainActor.assumeIsolated { [weak self] in
|
||||
self?.proxy()?.heartbeat { _ in }
|
||||
}
|
||||
}
|
||||
statusTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { _ in
|
||||
MainActor.assumeIsolated { [weak self] in self?.refreshStatus() }
|
||||
}
|
||||
refreshStatus()
|
||||
}
|
||||
|
||||
public func stop() { disconnect() }
|
||||
|
||||
private func refreshStatus() {
|
||||
proxy()?.fanStatus { [weak self] data in
|
||||
Task { @MainActor in self?.apply(data) }
|
||||
}
|
||||
}
|
||||
|
||||
private func apply(_ data: Data?) {
|
||||
guard let data, let decoded = try? JSONDecoder().decode(FanStatusReport.self, from: data)
|
||||
else { return }
|
||||
report = decoded
|
||||
lastError = nil
|
||||
}
|
||||
|
||||
// MARK: - Steuern
|
||||
|
||||
public func setTarget(index: Int, rpm: Double) {
|
||||
proxy()?.setFan(index: index, targetRPM: rpm) { [weak self] data in
|
||||
Task { @MainActor in self?.apply(data) }
|
||||
}
|
||||
}
|
||||
|
||||
public func setAutomatic(index: Int) {
|
||||
proxy()?.setFanAutomatic(index: index) { [weak self] data in
|
||||
Task { @MainActor in self?.apply(data) }
|
||||
}
|
||||
}
|
||||
}
|
||||
182
Onyx/FanSettingsView.swift
Normal file
182
Onyx/FanSettingsView.swift
Normal file
@@ -0,0 +1,182 @@
|
||||
import SwiftUI
|
||||
import OnyxHelperProtocol
|
||||
|
||||
/// Die Lüftersteuerung in den Einstellungen.
|
||||
///
|
||||
/// Bewusst hier und nicht im Notch-Panel: ein Regler, der die Kühlung des
|
||||
/// Rechners verstellt, gehört nicht dorthin, wo man mit dem Mauszeiger
|
||||
/// versehentlich hinkommt.
|
||||
struct FanSettingsView: View {
|
||||
@Bindable var control: FanControl
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
switch control.installState {
|
||||
case .notInstalled, .failed:
|
||||
installSection
|
||||
case .requiresApproval:
|
||||
approvalSection
|
||||
case .installed:
|
||||
controlSection
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.padding()
|
||||
.onAppear {
|
||||
control.refreshInstallState()
|
||||
control.start()
|
||||
}
|
||||
.onDisappear { control.stop() }
|
||||
}
|
||||
|
||||
// MARK: - Einrichtung
|
||||
|
||||
private var installSection: some View {
|
||||
Section {
|
||||
Text("fans.intro")
|
||||
.font(.callout)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
|
||||
// Das Risiko benennen, bevor jemand zustimmt — nicht danach.
|
||||
Label("fans.warning", systemImage: "exclamationmark.triangle.fill")
|
||||
.font(.callout)
|
||||
.foregroundStyle(.orange)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
|
||||
Text("fans.safety")
|
||||
.font(.callout)
|
||||
.foregroundStyle(.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
|
||||
if case .failed(let message) = control.installState {
|
||||
Text(message).font(.callout).foregroundStyle(.red)
|
||||
}
|
||||
|
||||
Button("fans.install") { control.install() }
|
||||
}
|
||||
}
|
||||
|
||||
private var approvalSection: some View {
|
||||
Section {
|
||||
Label("fans.approval.needed", systemImage: "hand.raised")
|
||||
.font(.callout)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
Button("fans.approval.open") { control.openApprovalSettings() }
|
||||
Button("fans.approval.recheck") { control.refreshInstallState() }
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Steuerung
|
||||
|
||||
@ViewBuilder
|
||||
private var controlSection: some View {
|
||||
if let report = control.report {
|
||||
Section {
|
||||
if let hottest = report.hottestCelsius {
|
||||
HStack {
|
||||
Label("fans.hottest", systemImage: "thermometer")
|
||||
Spacer()
|
||||
Text("\(Int(hottest))°").monospacedDigit()
|
||||
.foregroundStyle(hottest >= FanSafety.criticalCelsius
|
||||
? .red : .secondary)
|
||||
}
|
||||
}
|
||||
ForEach(report.fans, id: \.index) { fan in
|
||||
FanRow(fan: fan, control: control)
|
||||
}
|
||||
}
|
||||
|
||||
Section {
|
||||
Text("fans.safety.active")
|
||||
.font(.callout).foregroundStyle(.secondary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
Button("fans.uninstall", role: .destructive) {
|
||||
Task { await control.uninstall() }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Section {
|
||||
HStack {
|
||||
ProgressView().controlSize(.small)
|
||||
Text("fans.connecting").foregroundStyle(.secondary)
|
||||
}
|
||||
if let error = control.lastError {
|
||||
Text(error).font(.callout).foregroundStyle(.red)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct FanRow: View {
|
||||
let fan: FanStatus
|
||||
let control: FanControl
|
||||
|
||||
@State private var target: Double = 0
|
||||
@State private var editing = false
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
HStack {
|
||||
Label(name, systemImage: "fan")
|
||||
Spacer()
|
||||
Text("\(Int(fan.currentRPM)) U/min").monospacedDigit().foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Picker("", selection: Binding(
|
||||
get: { fan.isManual },
|
||||
set: { manual in
|
||||
if manual {
|
||||
control.setTarget(index: fan.index, rpm: max(target, fan.limits.minimum))
|
||||
} else {
|
||||
control.setAutomatic(index: fan.index)
|
||||
}
|
||||
})) {
|
||||
Text("fans.mode.auto").tag(false)
|
||||
Text("fans.mode.manual").tag(true)
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.labelsHidden()
|
||||
|
||||
if fan.isManual, fan.limits.isUsable {
|
||||
HStack {
|
||||
Text("\(Int(fan.limits.minimum))").font(.caption2).foregroundStyle(.secondary)
|
||||
Slider(value: $target,
|
||||
in: fan.limits.minimum...fan.limits.maximum,
|
||||
onEditingChanged: { active in
|
||||
editing = active
|
||||
// Erst beim Loslassen setzen: jede Bewegung des
|
||||
// Reglers wäre sonst ein SMC-Schreibvorgang.
|
||||
if !active { control.setTarget(index: fan.index, rpm: target) }
|
||||
})
|
||||
Text("\(Int(fan.limits.maximum))").font(.caption2).foregroundStyle(.secondary)
|
||||
}
|
||||
Text("\(Int(target)) U/min").font(.caption).monospacedDigit()
|
||||
}
|
||||
|
||||
// Ein erzwungener Rückfall wird erklärt, nicht verschwiegen.
|
||||
if let reason = fan.automaticReason, reason != "noRequest" {
|
||||
Label(explanation(for: reason), systemImage: "shield.lefthalf.filled")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.orange)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
.onAppear { if !editing { target = max(fan.targetRPM, fan.limits.minimum) } }
|
||||
.onChange(of: fan.targetRPM) { _, new in if !editing { target = new } }
|
||||
}
|
||||
|
||||
private var name: String {
|
||||
fan.index == 0 ? String(localized: "fans.left") : String(localized: "fans.right")
|
||||
}
|
||||
|
||||
private func explanation(for reason: String) -> LocalizedStringKey {
|
||||
switch reason {
|
||||
case "watchdog": "fans.reason.watchdog"
|
||||
case "temperature": "fans.reason.temperature"
|
||||
case "noTemperature": "fans.reason.noTemperature"
|
||||
case "unknownLimits": "fans.reason.unknownLimits"
|
||||
default: "fans.reason.other"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -772,6 +772,342 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"settings.tab.fans": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Lüfter"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Fans"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.intro": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Onyx kann die Lüfterdrehzahl fest vorgeben, statt sie macOS zu überlassen. Dafür wird ein Hilfsdienst mit Systemrechten eingerichtet — Schreibzugriff auf den SMC geht nicht anders."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Onyx can set a fixed fan speed instead of leaving it to macOS. This requires a helper service with system privileges — writing to the SMC is not possible otherwise."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.warning": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Eine zu niedrige Drehzahl kann den Rechner überhitzen lassen. Die Automatik regelt nach Temperatur, ein fester Wert nicht."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "A fan speed set too low can let the Mac overheat. The automatic control adjusts to temperature; a fixed value does not."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.safety": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Deshalb greift ein Sicherheitsnetz, das sich nicht abschalten lässt: nie unter das Minimum der Firmware, Rückfall auf Automatik ab 95 °C, Rückfall wenn Onyx sich fünf Sekunden nicht meldet, und Rückfall beim Beenden."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "A safety net you cannot switch off is therefore always active: never below the firmware minimum, back to automatic above 95 °C, back to automatic if Onyx goes silent for five seconds, and back to automatic on quit."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.install": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Hilfsdienst einrichten"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Install helper"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.approval.needed": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "macOS wartet auf deine Freigabe. Öffne die Systemeinstellungen und erlaube den Hintergrunddienst von Onyx."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "macOS is waiting for your approval. Open System Settings and allow Onyx's background service."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.approval.open": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Systemeinstellungen öffnen"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Open System Settings"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.approval.recheck": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Erneut prüfen"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Check again"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.connecting": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Verbinde mit dem Hilfsdienst …"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Connecting to the helper…"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.hottest": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Wärmster Kern"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Hottest core"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.left": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Lüfter links"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Left fan"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.right": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Lüfter rechts"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Right fan"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.mode.auto": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Automatik"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Automatic"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.mode.manual": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Manuell"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Manual"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.safety.active": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Das Sicherheitsnetz läuft im Hilfsdienst, nicht in Onyx. Es greift auch dann, wenn Onyx abstürzt oder beendet wird."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "The safety net runs in the helper, not in Onyx. It works even if Onyx crashes or is quit."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.uninstall": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Hilfsdienst entfernen"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Remove helper"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.reason.watchdog": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Zurück auf Automatik: Onyx hat sich zu lange nicht gemeldet."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Back to automatic: Onyx went silent for too long."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.reason.temperature": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Zurück auf Automatik: zu heiß für eine feste Drehzahl."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Back to automatic: too hot for a fixed speed."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.reason.noTemperature": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Zurück auf Automatik: keine Temperatur messbar, damit lässt sich Sicherheit nicht beurteilen."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Back to automatic: no temperature reading, so safety cannot be judged."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.reason.unknownLimits": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Zurück auf Automatik: der erlaubte Drehzahlbereich ist nicht lesbar."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Back to automatic: the permitted speed range cannot be read."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"fans.reason.other": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Zurück auf Automatik."
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Back to automatic."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": "1.1"
|
||||
|
||||
@@ -39,6 +39,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private var metricsModel: MetricsModel?
|
||||
private var networkModel: NetworkModel?
|
||||
private let settingsWindow = SettingsWindowController()
|
||||
private let fanControl = FanControl()
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
NSApp.setActivationPolicy(.accessory)
|
||||
@@ -135,6 +136,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
func applicationWillTerminate(_ notification: Notification) {
|
||||
coordinator?.stop()
|
||||
menuBar?.stop()
|
||||
// Der Herzschlag endet damit. Der Helfer stellt die Lüfter binnen fünf
|
||||
// Sekunden auf Automatik zurück — auch wenn Onyx abstürzt statt sauber
|
||||
// zu beenden.
|
||||
fanControl.stop()
|
||||
}
|
||||
|
||||
/// Echte Widgets zuerst, danach die Platzhalter für alles, was noch fehlt.
|
||||
@@ -258,7 +263,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private func showSettings(tab: SettingsTab) {
|
||||
guard let model, let calendarModel, let weatherModel else { return }
|
||||
settingsWindow.show(model: model, calendarModel: calendarModel,
|
||||
weatherModel: weatherModel, metricsModel: metricsModel, tab: tab)
|
||||
weatherModel: weatherModel, metricsModel: metricsModel,
|
||||
fanControl: fanControl, tab: tab)
|
||||
}
|
||||
|
||||
@objc private func quit() { NSApp.terminate(nil) }
|
||||
|
||||
@@ -5,10 +5,11 @@ import OnyxWidgetKit
|
||||
import CalendarProvider
|
||||
import OnyxMenuBar
|
||||
import MetricsProvider
|
||||
import OnyxHelperProtocol
|
||||
import WeatherProvider
|
||||
|
||||
enum SettingsTab: Hashable {
|
||||
case widgets, display, menubar, permissions
|
||||
case widgets, display, menubar, fans, permissions
|
||||
}
|
||||
|
||||
struct SettingsView: View {
|
||||
@@ -16,6 +17,7 @@ struct SettingsView: View {
|
||||
let calendarModel: CalendarModel
|
||||
let weatherModel: WeatherModel
|
||||
let metricsModel: MetricsModel?
|
||||
let fanControl: FanControl
|
||||
@Binding var selectedTab: SettingsTab
|
||||
|
||||
var body: some View {
|
||||
@@ -29,6 +31,9 @@ struct SettingsView: View {
|
||||
MenuBarSettings(model: model, metricsModel: metricsModel)
|
||||
.tabItem { Label("settings.tab.menubar", systemImage: "menubar.rectangle") }
|
||||
.tag(SettingsTab.menubar)
|
||||
FanSettingsView(control: fanControl)
|
||||
.tabItem { Label("settings.tab.fans", systemImage: "fan") }
|
||||
.tag(SettingsTab.fans)
|
||||
PermissionSettings(calendarModel: calendarModel, weatherModel: weatherModel)
|
||||
.tabItem { Label("settings.tab.permissions", systemImage: "hand.raised") }
|
||||
.tag(SettingsTab.permissions)
|
||||
|
||||
@@ -26,7 +26,8 @@ final class SettingsWindowController: NSObject, NSWindowDelegate {
|
||||
var keepsDockIcon = false
|
||||
|
||||
func show(model: AppModel, calendarModel: CalendarModel, weatherModel: WeatherModel,
|
||||
metricsModel: MetricsModel?, tab: SettingsTab = .widgets) {
|
||||
metricsModel: MetricsModel?, fanControl: FanControl,
|
||||
tab: SettingsTab = .widgets) {
|
||||
selectedTab = tab
|
||||
keepsDockIcon = model.showsDockIcon
|
||||
|
||||
@@ -44,6 +45,7 @@ final class SettingsWindowController: NSObject, NSWindowDelegate {
|
||||
calendarModel: calendarModel,
|
||||
weatherModel: weatherModel,
|
||||
metricsModel: metricsModel,
|
||||
fanControl: fanControl,
|
||||
selectedTab: Binding(
|
||||
get: { [weak self] in self?.selectedTab ?? .widgets },
|
||||
set: { [weak self] in self?.selectedTab = $0 })))
|
||||
|
||||
Reference in New Issue
Block a user