Ladelimit ist eine Anzeige, Akku-Kachel sagt etwas, Menüleiste bekommt Kürzel
Der Regler war eine Pseudobedienung. Der SMC lehnt Schreibzugriffe auf CHLT ab — der Helfer hat es mit korrekter Größe versucht und „geschrieben (false), zurückgelesen 85" gemeldet. Das Sicherheitsnetz hat also die Wahrheit gesagt; die Oberfläche hat sie nur nicht gezeigt. Weiter zu raten hieße, im Lade-Subsystem Keys durchzuprobieren, und das ist die eine Operation in diesem Projekt, die Hardware dauerhaft beschädigen kann. Also: das Limit wird gelesen und angezeigt, mit einem Weg in die Systemeinstellungen, wo es tatsächlich geht. Der Schreibpfad ist aus dem privilegierten Helfer entfernt — ein Root-Dienst trägt nur, was benutzt wird. Die Akku-Kachel zeigte „40 %" und einen Verlauf über die letzten Sekunden. Der Ladestand ändert sich in Minuten, nicht in Sekunden; der Graph war eine waagerechte Linie. Jetzt: verbleibende Zeit bzw. Zeit bis voll, Leistung in Watt mit Richtung, Ladelimit, Zustand, Zyklen — und der Energiesparmodus. Der erklärt, warum die Maschine langsamer wirkt, und ohne diesen Hinweis sucht man den Grund woanders. In der Menüleiste standen fünf nackte Prozentzahlen nebeneinander. Man sah Zahlen und wusste nicht, welche wozu gehört. Zwei neue Darstellungen: Kürzel und Wert („CPU 34 %") sowie Symbol und Wert. Beim Akku stehen sie zuoberst in der Auswahl. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ private let log = Logger(subsystem: "com.scarriffleservices.onyx", category: "Fa
|
|||||||
/// selbst misst. Diese Klasse hält nur die Verbindung und den Herzschlag.
|
/// selbst misst. Diese Klasse hält nur die Verbindung und den Herzschlag.
|
||||||
@MainActor
|
@MainActor
|
||||||
@Observable
|
@Observable
|
||||||
public final class FanControl: ChargeLimitControlling {
|
public final class FanControl: ChargeLimitReading {
|
||||||
|
|
||||||
public enum InstallState: Equatable {
|
public enum InstallState: Equatable {
|
||||||
case notInstalled
|
case notInstalled
|
||||||
@@ -178,13 +178,7 @@ public final class FanControl: ChargeLimitControlling {
|
|||||||
/// Setzt das Limit und übernimmt, was der Helfer **zurückgelesen** hat —
|
/// Setzt das Limit und übernimmt, was der Helfer **zurückgelesen** hat —
|
||||||
/// nicht das, was gewünscht war. Ein Schreibvorgang, den der SMC verwirft,
|
/// nicht das, was gewünscht war. Ein Schreibvorgang, den der SMC verwirft,
|
||||||
/// darf sich in der Oberfläche nicht als Erfolg zeigen.
|
/// darf sich in der Oberfläche nicht als Erfolg zeigen.
|
||||||
/// Ohne laufenden Helfer lässt sich nichts schreiben — der Regler wird
|
/// Ohne laufenden Helfer kommt kein Wert — dann steht ein Strich da statt
|
||||||
/// dann angezeigt, aber gesperrt, statt still zu versagen.
|
/// einer Zahl, die es nicht gibt.
|
||||||
public var canControlCharge: Bool { installState == .installed }
|
public var canReadCharge: Bool { installState == .installed }
|
||||||
|
|
||||||
public func setChargeLimit(_ percent: Int) {
|
|
||||||
proxy()?.setChargeLimit(percent: percent) { [weak self] result in
|
|
||||||
Task { @MainActor in self?.chargeLimit = result > 0 ? result : nil }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,6 +167,8 @@ final class FanMenuBarModule: MenuBarModule {
|
|||||||
let id = "fans"
|
let id = "fans"
|
||||||
var displayName: String { String(localized: "widget.fans.name") }
|
var displayName: String { String(localized: "widget.fans.name") }
|
||||||
|
|
||||||
|
var shortLabel: String { String(localized: "fans.menubar.short") }
|
||||||
|
|
||||||
private let control: FanControl
|
private let control: FanControl
|
||||||
private var view: FanStatusView?
|
private var view: FanStatusView?
|
||||||
private var isActive = false
|
private var isActive = false
|
||||||
@@ -234,6 +236,9 @@ private final class FanStatusView: NSView, WidthReporting {
|
|||||||
/// änderte das Element bei jeder Messung seine Breite.
|
/// änderte das Element bei jeder Messung seine Breite.
|
||||||
private var reference: String { presentation == .symbol ? "" : "9999" }
|
private var reference: String { presentation == .symbol ? "" : "9999" }
|
||||||
|
|
||||||
|
/// Der Lüfter zeigt ohnehin Symbol und Zahl — die neuen Darstellungen
|
||||||
|
/// ändern daran nichts, sie stehen nur in der Auswahl nicht zur Verfügung.
|
||||||
|
|
||||||
var onWidthChange: ((CGFloat) -> Void)?
|
var onWidthChange: ((CGFloat) -> Void)?
|
||||||
|
|
||||||
func update(rpm: Double?) {
|
func update(rpm: Double?) {
|
||||||
|
|||||||
@@ -19,24 +19,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"%@ °C" : {
|
|
||||||
"comment" : "A label showing the temperature of the hottest fan in the report, in degrees Celsius. The argument is the temperature in degrees Celsius.",
|
|
||||||
"isCommentAutoGenerated" : true,
|
|
||||||
"localizations" : {
|
|
||||||
"de" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "%@ °C"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "%@ °C"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"%@ U/min": {
|
"%@ U/min": {
|
||||||
"comment": "A label that shows the current speed of a fan. The argument is the current speed of the fan.",
|
"comment": "A label that shows the current speed of a fan. The argument is the current speed of the fan.",
|
||||||
"isCommentAutoGenerated": true,
|
"isCommentAutoGenerated": true,
|
||||||
@@ -55,6 +37,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"%@ °C": {
|
||||||
|
"comment": "A label showing the temperature of the hottest fan in the report, in degrees Celsius. The argument is the temperature in degrees Celsius.",
|
||||||
|
"isCommentAutoGenerated": true,
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "%@ °C"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "%@ °C"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"%@°": {
|
"%@°": {
|
||||||
"comment": "A temperature in °C.",
|
"comment": "A temperature in °C.",
|
||||||
"isCommentAutoGenerated": true,
|
"isCommentAutoGenerated": true,
|
||||||
@@ -74,6 +74,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"charge.limit": {
|
"charge.limit": {
|
||||||
|
"extractionState": "stale",
|
||||||
"localizations": {
|
"localizations": {
|
||||||
"de": {
|
"de": {
|
||||||
"stringUnit": {
|
"stringUnit": {
|
||||||
@@ -90,6 +91,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"charge.limit.hint": {
|
"charge.limit.hint": {
|
||||||
|
"extractionState": "stale",
|
||||||
"localizations": {
|
"localizations": {
|
||||||
"de": {
|
"de": {
|
||||||
"stringUnit": {
|
"stringUnit": {
|
||||||
@@ -106,6 +108,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"charge.limit.off": {
|
"charge.limit.off": {
|
||||||
|
"extractionState": "stale",
|
||||||
"localizations": {
|
"localizations": {
|
||||||
"de": {
|
"de": {
|
||||||
"stringUnit": {
|
"stringUnit": {
|
||||||
@@ -341,6 +344,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"fans.menubar.short": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Lüfter"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Fan"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"fans.mode.auto": {
|
"fans.mode.auto": {
|
||||||
"localizations": {
|
"localizations": {
|
||||||
"de": {
|
"de": {
|
||||||
@@ -776,6 +795,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"mixer.menubar.short": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Mix"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Mix"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"network.name": {
|
"network.name": {
|
||||||
"extractionState": "stale",
|
"extractionState": "stale",
|
||||||
"localizations": {
|
"localizations": {
|
||||||
@@ -1258,6 +1293,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"settings.menubar.labelAndValue": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Kürzel + Wert"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Label + value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"settings.menubar.symbol": {
|
"settings.menubar.symbol": {
|
||||||
"extractionState": "stale",
|
"extractionState": "stale",
|
||||||
"localizations": {
|
"localizations": {
|
||||||
@@ -1275,6 +1326,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"settings.menubar.symbolAndValue": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Symbol + Wert"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Symbol + value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"settings.menubar.value": {
|
"settings.menubar.value": {
|
||||||
"extractionState": "stale",
|
"extractionState": "stale",
|
||||||
"localizations": {
|
"localizations": {
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ final class MixerMenuBarModule: MenuBarModule {
|
|||||||
let id = "audio"
|
let id = "audio"
|
||||||
var displayName: String { String(localized: "mixer.menubar.name") }
|
var displayName: String { String(localized: "mixer.menubar.name") }
|
||||||
|
|
||||||
|
var shortLabel: String { String(localized: "mixer.menubar.short") }
|
||||||
|
|
||||||
private let mixer: AudioMixer
|
private let mixer: AudioMixer
|
||||||
private var view: MixerStatusView?
|
private var view: MixerStatusView?
|
||||||
private var isActive = false
|
private var isActive = false
|
||||||
|
|||||||
@@ -259,6 +259,10 @@ private struct ModuleRow: View {
|
|||||||
// Drehzahl als Zahl oder nur das Symbol — ein Verlauf der Drehzahl
|
// Drehzahl als Zahl oder nur das Symbol — ein Verlauf der Drehzahl
|
||||||
// sagt in 28 Punkten Breite nichts.
|
// sagt in 28 Punkten Breite nichts.
|
||||||
case "fans": [.value, .symbol]
|
case "fans": [.value, .symbol]
|
||||||
|
// Der Akku kann alles, und gerade dort will man Symbol oder Kürzel:
|
||||||
|
// eine nackte Prozentzahl neben vier anderen sagt nichts.
|
||||||
|
case "metric.battery": [.symbolAndValue, .labelAndValue, .value, .symbol,
|
||||||
|
.graph, .valueAndGraph]
|
||||||
default: MenuBarPresentation.allCases
|
default: MenuBarPresentation.allCases
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,6 +335,8 @@ extension MenuBarPresentation {
|
|||||||
case .bars: "settings.menubar.bars"
|
case .bars: "settings.menubar.bars"
|
||||||
case .valueAndGraph: "settings.menubar.valueAndGraph"
|
case .valueAndGraph: "settings.menubar.valueAndGraph"
|
||||||
case .symbol: "settings.menubar.symbol"
|
case .symbol: "settings.menubar.symbol"
|
||||||
|
case .labelAndValue: "settings.menubar.labelAndValue"
|
||||||
|
case .symbolAndValue: "settings.menubar.symbolAndValue"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,12 +104,6 @@ final class SMCAccess {
|
|||||||
write(key, bytes: [value])
|
write(key, bytes: [value])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Schreibt beliebige Bytes — für `CHLT`, das drei davon hat.
|
|
||||||
@discardableResult
|
|
||||||
func writeBytes(_ key: String, _ bytes: [UInt8]) -> Bool {
|
|
||||||
write(key, bytes: bytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
private func write(_ key: String, bytes: [UInt8]) -> Bool {
|
private func write(_ key: String, bytes: [UInt8]) -> Bool {
|
||||||
guard let info = keyInfo(for: key) else { return false }
|
guard let info = keyInfo(for: key) else { return false }
|
||||||
// Nur schreiben, wenn die Größe zur Firmware passt. Ein zu kurzer oder
|
// Nur schreiben, wenn die Größe zur Firmware passt. Ein zu kurzer oder
|
||||||
|
|||||||
@@ -138,21 +138,6 @@ final class FanService: NSObject, OnyxHelperProtocol {
|
|||||||
reply(percent)
|
reply(percent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setChargeLimit(percent: Int, reply: @escaping (Int) -> Void) {
|
|
||||||
lastHeartbeat = Date()
|
|
||||||
guard let smc else { reply(-1); return }
|
|
||||||
|
|
||||||
let wanted = ChargeSafety.clamp(percent)
|
|
||||||
let written = smc.writeBytes(ChargeSafety.key, ChargeSafety.encode(wanted))
|
|
||||||
|
|
||||||
// Immer zurücklesen. Ein Schreibvorgang, den der SMC stillschweigend
|
|
||||||
// verwirft, darf nicht als Erfolg gemeldet werden — sonst zeigt die
|
|
||||||
// Oberfläche eine Grenze an, die es nicht gibt.
|
|
||||||
let readBack = smc.readBytes(ChargeSafety.key).flatMap(ChargeSafety.decode) ?? -1
|
|
||||||
log.notice("Ladelimit: \(percent, privacy: .public) % gewünscht, \(wanted, privacy: .public) % geschrieben (\(written, privacy: .public)), zurückgelesen \(readBack, privacy: .public) %")
|
|
||||||
reply(readBack)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setFanAutomatic(index: Int, reply: @escaping (Data?) -> Void) {
|
func setFanAutomatic(index: Int, reply: @escaping (Data?) -> Void) {
|
||||||
lastHeartbeat = Date()
|
lastHeartbeat = Date()
|
||||||
requests[index] = nil
|
requests[index] = nil
|
||||||
|
|||||||
@@ -1,90 +1,72 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import AppKit
|
||||||
import OnyxDesign
|
import OnyxDesign
|
||||||
import OnyxHelperProtocol
|
import OnyxHelperProtocol
|
||||||
|
|
||||||
/// Wer das Ladelimit setzen kann.
|
/// Wer das Ladelimit **lesen** kann.
|
||||||
///
|
///
|
||||||
/// Ein Protokoll und kein direkter Zugriff: das Limit schreibt der privilegierte
|
/// Nur lesen, und das ist eine gemessene Grenze, keine Bequemlichkeit: der
|
||||||
/// Helfer, und der gehört zur App, nicht zu diesem Package. Die Akku-Ansicht
|
/// SMC lehnt Schreibzugriffe auf `CHLT` ab. Der Helfer hat es versucht und
|
||||||
/// soll ihn bedienen können, ohne ihn zu kennen.
|
/// `false` gemeldet, der Wert blieb unverändert. macOS setzt das Limit
|
||||||
|
/// offenbar auf einem anderen Weg als über den SMC-Userclient.
|
||||||
|
///
|
||||||
|
/// Ein Regler, der sich ziehen lässt und dann zurückspringt, ist schlimmer als
|
||||||
|
/// gar keiner — er behauptet eine Fähigkeit, die nicht existiert.
|
||||||
@MainActor
|
@MainActor
|
||||||
public protocol ChargeLimitControlling: AnyObject {
|
public protocol ChargeLimitReading: AnyObject {
|
||||||
/// Das eingestellte Limit in Prozent, `nil` wenn keines gilt.
|
/// Das eingestellte Limit in Prozent, `nil` wenn keines gilt.
|
||||||
var chargeLimit: Int? { get }
|
var chargeLimit: Int? { get }
|
||||||
/// Ob überhaupt geschrieben werden kann — ohne Helfer geht nichts.
|
/// Ob der Wert überhaupt gelesen werden kann — ohne Helfer nicht.
|
||||||
var canControlCharge: Bool { get }
|
var canReadCharge: Bool { get }
|
||||||
func refreshChargeLimit()
|
func refreshChargeLimit()
|
||||||
func setChargeLimit(_ percent: Int)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Der Ladelimit-Regler, wie er im Akku-Widget und im Akku-Popover steht.
|
/// Zeigt das Ladelimit und führt dorthin, wo man es ändern kann.
|
||||||
///
|
|
||||||
/// Ein Akku, der dauerhaft bei 100 % am Netz hängt, altert schneller. Deshalb
|
|
||||||
/// gibt es die Einstellung — und deshalb ist ihr Bereich so schmal: 80 bis
|
|
||||||
/// 100 % ist, was macOS selbst anbietet und wofür gemessen wurde, wie der
|
|
||||||
/// zuständige SMC-Key aussieht. Darunter wäre geraten.
|
|
||||||
public struct ChargeLimitControl: View {
|
public struct ChargeLimitControl: View {
|
||||||
|
|
||||||
private let control: any ChargeLimitControlling
|
private let control: any ChargeLimitReading
|
||||||
/// Im Popover ist Platz für die Erklärung, in der Kachel nicht.
|
/// Im Popover ist Platz für den Hinweis, in der Kachel nicht.
|
||||||
private let roomy: Bool
|
private let roomy: Bool
|
||||||
|
|
||||||
@State private var pending: Double?
|
public init(control: any ChargeLimitReading, roomy: Bool) {
|
||||||
|
|
||||||
public init(control: any ChargeLimitControlling, roomy: Bool) {
|
|
||||||
self.control = control
|
self.control = control
|
||||||
self.roomy = roomy
|
self.roomy = roomy
|
||||||
}
|
}
|
||||||
|
|
||||||
private var current: Double {
|
|
||||||
pending ?? Double(control.chargeLimit ?? ChargeSafety.noLimit)
|
|
||||||
}
|
|
||||||
|
|
||||||
private var isOff: Bool { current >= Double(ChargeSafety.noLimit) }
|
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
VStack(alignment: .leading, spacing: 5) {
|
|
||||||
HStack(spacing: 6) {
|
HStack(spacing: 6) {
|
||||||
Text("charge.limit", bundle: .module)
|
Text("charge.limit", bundle: .module)
|
||||||
.font(Onyx.Font.caption)
|
.font(Onyx.Font.caption)
|
||||||
.foregroundStyle(Onyx.Color.textSecondary)
|
.foregroundStyle(Onyx.Color.textSecondary)
|
||||||
|
|
||||||
Spacer(minLength: 4)
|
Spacer(minLength: 4)
|
||||||
Group {
|
|
||||||
// Hundert Prozent ist kein Limit — und soll auch nicht so
|
if let limit = control.chargeLimit, limit < ChargeSafety.noLimit {
|
||||||
// heißen, sonst sucht man den Ausschalter.
|
Text(verbatim: "\(limit) %")
|
||||||
if isOff {
|
|
||||||
Text("charge.limit.off", bundle: .module)
|
|
||||||
} else {
|
|
||||||
Text(verbatim: "\(Int(current)) %")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.font(Onyx.Font.metricSmall).monospacedDigit()
|
.font(Onyx.Font.metricSmall).monospacedDigit()
|
||||||
.foregroundStyle(isOff ? Onyx.Color.textTertiary : Onyx.Color.accent)
|
.foregroundStyle(Onyx.Color.accent)
|
||||||
|
} else if control.canReadCharge {
|
||||||
|
Text("charge.limit.off", bundle: .module)
|
||||||
|
.font(Onyx.Font.metricSmall)
|
||||||
|
.foregroundStyle(Onyx.Color.textTertiary)
|
||||||
|
} else {
|
||||||
|
Text(verbatim: "–")
|
||||||
|
.font(Onyx.Font.metricSmall)
|
||||||
|
.foregroundStyle(Onyx.Color.textTertiary)
|
||||||
}
|
}
|
||||||
|
|
||||||
Slider(value: Binding(get: { current }, set: { pending = ($0 / 5).rounded() * 5 }),
|
if roomy {
|
||||||
in: Double(ChargeSafety.minimumPercent)...Double(ChargeSafety.maximumPercent),
|
// Kein Regler, sondern der Weg dorthin, wo es wirklich geht.
|
||||||
onEditingChanged: { editing in
|
Button {
|
||||||
// Erst beim Loslassen schreiben. Bei jedem Zwischenwert
|
NSWorkspace.shared.open(
|
||||||
// in den Ladepfad zu schreiben wäre ein Dutzend
|
URL(string: "x-apple.systempreferences:com.apple.Battery-Settings.extension")!)
|
||||||
// Schreibvorgänge für eine einzige Entscheidung.
|
} label: {
|
||||||
guard !editing, let pending else { return }
|
Image(systemName: "arrow.up.forward.app")
|
||||||
control.setChargeLimit(Int(pending))
|
.font(.system(size: 10))
|
||||||
self.pending = nil
|
|
||||||
})
|
|
||||||
.controlSize(.mini)
|
|
||||||
.disabled(!control.canControlCharge)
|
|
||||||
|
|
||||||
if !control.canControlCharge {
|
|
||||||
Text("charge.limit.needsHelper", bundle: .module)
|
|
||||||
.font(Onyx.Font.metricSmall)
|
|
||||||
.foregroundStyle(Onyx.Color.textTertiary)
|
.foregroundStyle(Onyx.Color.textTertiary)
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
}
|
||||||
} else if roomy {
|
.buttonStyle(.plain)
|
||||||
Text("charge.limit.hint", bundle: .module)
|
.help(Text("charge.limit.inSystemSettings", bundle: .module))
|
||||||
.font(Onyx.Font.metricSmall)
|
|
||||||
.foregroundStyle(Onyx.Color.textTertiary)
|
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear { control.refreshChargeLimit() }
|
.onAppear { control.refreshChargeLimit() }
|
||||||
|
|||||||
@@ -56,6 +56,134 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"battery.charging": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Lädt"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Charging"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"battery.cycles": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Zyklen"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Cycles"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"battery.draining": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Verbrauch"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Draw"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"battery.health": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Zustand"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Health"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"battery.lowPower": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Energiesparmodus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Low Power Mode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"battery.pluggedIn": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Am Netz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Plugged in"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"battery.remaining %@": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "noch %@"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "%@ remaining"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"battery.untilFull %@": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "%@ bis voll"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "%@ until full"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"charge.limit": {
|
"charge.limit": {
|
||||||
"localizations": {
|
"localizations": {
|
||||||
"de": {
|
"de": {
|
||||||
@@ -88,6 +216,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"charge.limit.inSystemSettings": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "In den Systemeinstellungen einstellbar"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Set in System Settings"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"charge.limit.needsHelper": {
|
"charge.limit.needsHelper": {
|
||||||
"localizations": {
|
"localizations": {
|
||||||
"de": {
|
"de": {
|
||||||
@@ -120,6 +264,38 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"menubar.short.battery": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Akku"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Batt"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"menubar.short.temperature": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Temp"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Temp"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"metric.battery": {
|
"metric.battery": {
|
||||||
"localizations": {
|
"localizations": {
|
||||||
"de": {
|
"de": {
|
||||||
@@ -795,6 +971,38 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"settings.menubar.labelAndValue": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Kürzel + Wert"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Label + value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"settings.menubar.symbolAndValue": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Symbol + Wert"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Symbol + value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "1.1"
|
"version": "1.1"
|
||||||
|
|||||||
@@ -28,8 +28,20 @@ public final class MetricMenuBarModule: MenuBarModule {
|
|||||||
self.id = "metric.\(metric.rawValue)"
|
self.id = "metric.\(metric.rawValue)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Kurz genug für die Menüleiste. „Arbeitsspeicher" wäre dort ein Balken.
|
||||||
|
public var shortLabel: String {
|
||||||
|
switch metric {
|
||||||
|
case .cpu: "CPU"
|
||||||
|
case .gpu: "GPU"
|
||||||
|
case .memory: "RAM"
|
||||||
|
case .battery: String(localized: "menubar.short.battery", bundle: .module)
|
||||||
|
case .temperature: String(localized: "menubar.short.temperature", bundle: .module)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func makeStatusView(presentation: MenuBarPresentation) -> NSView {
|
public func makeStatusView(presentation: MenuBarPresentation) -> NSView {
|
||||||
let view = MetricStatusView(metric: metric, presentation: presentation)
|
let view = MetricStatusView(metric: metric, presentation: presentation,
|
||||||
|
label: shortLabel)
|
||||||
view.update(snapshot: model.snapshot, history: model.series(metric),
|
view.update(snapshot: model.snapshot, history: model.series(metric),
|
||||||
mode: model.displayMode(for: metric))
|
mode: model.displayMode(for: metric))
|
||||||
self.view = view
|
self.view = view
|
||||||
@@ -84,9 +96,12 @@ final class MetricStatusView: NSView, WidthReporting {
|
|||||||
private var history: [Double] = []
|
private var history: [Double] = []
|
||||||
private var mode: MetricDisplayMode = .usage
|
private var mode: MetricDisplayMode = .usage
|
||||||
|
|
||||||
init(metric: MetricKind, presentation: MenuBarPresentation) {
|
private let label: String
|
||||||
|
|
||||||
|
init(metric: MetricKind, presentation: MenuBarPresentation, label: String) {
|
||||||
self.metric = metric
|
self.metric = metric
|
||||||
self.presentation = presentation
|
self.presentation = presentation
|
||||||
|
self.label = label
|
||||||
super.init(frame: NSRect(x: 0, y: 0, width: 22, height: 22))
|
super.init(frame: NSRect(x: 0, y: 0, width: 22, height: 22))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +122,8 @@ final class MetricStatusView: NSView, WidthReporting {
|
|||||||
case .bars: barsWidth
|
case .bars: barsWidth
|
||||||
case .value: MenuBarText.width(for: reference)
|
case .value: MenuBarText.width(for: reference)
|
||||||
case .valueAndGraph: MenuBarText.width(for: reference) + 2 + 28
|
case .valueAndGraph: MenuBarText.width(for: reference) + 2 + 28
|
||||||
|
case .labelAndValue: MenuBarText.width(for: "\(label) \(reference)")
|
||||||
|
case .symbolAndValue: MenuBarText.width(for: reference, includesSymbol: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +175,16 @@ final class MetricStatusView: NSView, WidthReporting {
|
|||||||
drawGraph(color: color, in: bounds.insetBy(dx: 2, dy: 5))
|
drawGraph(color: color, in: bounds.insetBy(dx: 2, dy: 5))
|
||||||
case .bars:
|
case .bars:
|
||||||
drawBars(color: color)
|
drawBars(color: color)
|
||||||
|
case .labelAndValue:
|
||||||
|
drawText("\(label) \(MetricSummary.value(metric, snapshot, mode: mode))", color: color)
|
||||||
|
|
||||||
|
case .symbolAndValue:
|
||||||
|
MenuBarText.drawSymbol(metric.symbolName, color: color,
|
||||||
|
in: NSRect(x: 0, y: bounds.midY - 6.5,
|
||||||
|
width: 13, height: 13))
|
||||||
|
drawText(MetricSummary.value(metric, snapshot, mode: mode), color: color,
|
||||||
|
in: NSRect(x: 15, y: 0, width: bounds.width - 15, height: bounds.height))
|
||||||
|
|
||||||
case .valueAndGraph:
|
case .valueAndGraph:
|
||||||
let split = bounds.width * 0.55
|
let split = bounds.width * 0.55
|
||||||
drawText(MetricSummary.value(metric, snapshot, mode: mode), color: color,
|
drawText(MetricSummary.value(metric, snapshot, mode: mode), color: color,
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ private struct MemoryDetail: View {
|
|||||||
|
|
||||||
private struct BatteryDetail: View {
|
private struct BatteryDetail: View {
|
||||||
let snapshot: MetricsSnapshot
|
let snapshot: MetricsSnapshot
|
||||||
let control: (any ChargeLimitControlling)?
|
let control: (any ChargeLimitReading)?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if let battery = snapshot.battery {
|
if let battery = snapshot.battery {
|
||||||
|
|||||||
@@ -54,14 +54,8 @@ private struct MetricWidgetView: View {
|
|||||||
// alles andere zeigt Zahl und Verlauf.
|
// alles andere zeigt Zahl und Verlauf.
|
||||||
if metric == .temperature {
|
if metric == .temperature {
|
||||||
SensorList(snapshot: model.snapshot, detailed: true)
|
SensorList(snapshot: model.snapshot, detailed: true)
|
||||||
} else if metric == .battery, let control = model.chargeControl {
|
} else if metric == .battery {
|
||||||
// Die Akku-Kachel bekommt den Ladelimit-Regler direkt: dort
|
BatteryTile(model: model)
|
||||||
// schaut man ohnehin hin, wenn man ihn braucht.
|
|
||||||
VStack(alignment: .leading, spacing: 8) {
|
|
||||||
WideMetric(model: model, metric: metric)
|
|
||||||
Divider().overlay(Onyx.Color.hairline)
|
|
||||||
ChargeLimitControl(control: control, roomy: false)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
WideMetric(model: model, metric: metric)
|
WideMetric(model: model, metric: metric)
|
||||||
}
|
}
|
||||||
@@ -327,3 +321,97 @@ public enum MetricSummary {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Die Akku-Kachel.
|
||||||
|
///
|
||||||
|
/// „40 %" und ein Verlauf über die letzten Sekunden ist keine Auskunft — der
|
||||||
|
/// Ladestand ändert sich in Minuten, nicht in Sekunden, und ein Graph darüber
|
||||||
|
/// ist eine waagerechte Linie. Was man wissen will: wie lange noch, zieht oder
|
||||||
|
/// gibt der Akku gerade, läuft der Energiesparmodus, wo endet das Laden.
|
||||||
|
private struct BatteryTile: View {
|
||||||
|
let model: MetricsModel
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
let battery = model.snapshot.battery
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
|
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
||||||
|
Text(MetricFormat.percent(battery?.charge ?? 0))
|
||||||
|
.font(Onyx.Font.metric).monospacedDigit()
|
||||||
|
.foregroundStyle(tint(battery))
|
||||||
|
if let battery, battery.isCharging {
|
||||||
|
Image(systemName: "bolt.fill")
|
||||||
|
.font(.system(size: 11))
|
||||||
|
.foregroundStyle(Onyx.Color.positive)
|
||||||
|
}
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let battery {
|
||||||
|
if let remaining = battery.timeRemaining {
|
||||||
|
Text(battery.isCharging ? "battery.untilFull \(duration(remaining))"
|
||||||
|
: "battery.remaining \(duration(remaining))",
|
||||||
|
bundle: .module)
|
||||||
|
.font(Onyx.Font.caption)
|
||||||
|
.foregroundStyle(Onyx.Color.textSecondary)
|
||||||
|
} else if battery.isPluggedIn {
|
||||||
|
Text("battery.pluggedIn", bundle: .module)
|
||||||
|
.font(Onyx.Font.caption)
|
||||||
|
.foregroundStyle(Onyx.Color.textSecondary)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 3) {
|
||||||
|
if let watts = battery.watts, abs(watts) > 0.1 {
|
||||||
|
row(watts > 0 ? "battery.charging" : "battery.draining",
|
||||||
|
value: String(format: "%.1f W", abs(watts)))
|
||||||
|
}
|
||||||
|
if let limit = model.chargeControl?.chargeLimit, limit < 100 {
|
||||||
|
row("charge.limit", value: "\(limit) %")
|
||||||
|
}
|
||||||
|
if let health = battery.health {
|
||||||
|
row("battery.health", value: MetricFormat.percent(health))
|
||||||
|
}
|
||||||
|
if let cycles = battery.cycleCount {
|
||||||
|
row("battery.cycles", value: "\(cycles)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Der Energiesparmodus erklärt, warum die Maschine langsamer
|
||||||
|
// wirkt. Ohne diesen Hinweis sucht man den Grund woanders.
|
||||||
|
if battery.isLowPower {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Image(systemName: "leaf.fill").font(.system(size: 9))
|
||||||
|
Text("battery.lowPower", bundle: .module).font(Onyx.Font.metricSmall)
|
||||||
|
}
|
||||||
|
.foregroundStyle(Onyx.Color.warning)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func row(_ key: String.LocalizationValue, value: String) -> some View {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(String(localized: key, bundle: .module))
|
||||||
|
.foregroundStyle(Onyx.Color.textTertiary)
|
||||||
|
Spacer(minLength: 4)
|
||||||
|
Text(value).monospacedDigit().foregroundStyle(Onyx.Color.textSecondary)
|
||||||
|
}
|
||||||
|
.font(Onyx.Font.metricSmall)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func tint(_ battery: BatteryReading?) -> Color {
|
||||||
|
guard let battery else { return Onyx.Color.textPrimary }
|
||||||
|
if battery.isCharging { return Onyx.Color.positive }
|
||||||
|
return battery.charge < 0.2 ? Onyx.Color.critical : Onyx.Color.textPrimary
|
||||||
|
}
|
||||||
|
|
||||||
|
private func duration(_ seconds: TimeInterval) -> String {
|
||||||
|
let total = Int(seconds)
|
||||||
|
return total >= 3600 ? "\(total / 3600) h \(total % 3600 / 60) min"
|
||||||
|
: "\(total / 60) min"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public final class MetricsModel {
|
|||||||
|
|
||||||
/// Wer das Ladelimit setzen kann — die App reicht den Helfer herein.
|
/// Wer das Ladelimit setzen kann — die App reicht den Helfer herein.
|
||||||
/// `nil` heißt: kein Regler, weil es nichts zu regeln gibt.
|
/// `nil` heißt: kein Regler, weil es nichts zu regeln gibt.
|
||||||
public weak var chargeControl: (any ChargeLimitControlling)?
|
public weak var chargeControl: (any ChargeLimitReading)?
|
||||||
|
|
||||||
public private(set) var snapshot = MetricsSnapshot()
|
public private(set) var snapshot = MetricsSnapshot()
|
||||||
/// Verlauf für die Graphen, jüngster Wert zuletzt.
|
/// Verlauf für die Graphen, jüngster Wert zuletzt.
|
||||||
|
|||||||
@@ -72,6 +72,11 @@ public struct BatteryReading: Equatable, Sendable {
|
|||||||
public var health: Double? // 0 bis 1
|
public var health: Double? // 0 bis 1
|
||||||
public var watts: Double? // negativ = Entladung
|
public var watts: Double? // negativ = Entladung
|
||||||
public var timeRemaining: TimeInterval?
|
public var timeRemaining: TimeInterval?
|
||||||
|
/// Energiesparmodus. Erklärt, warum die Maschine langsamer wirkt — und
|
||||||
|
/// gehört deshalb sichtbar dorthin, wo man nach dem Grund sucht.
|
||||||
|
public var isLowPower = false
|
||||||
|
/// Temperatur der Zelle, falls der SMC sie hergibt.
|
||||||
|
public var celsius: Double?
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ein Programm mit seinem Speicherverbrauch.
|
/// Ein Programm mit seinem Speicherverbrauch.
|
||||||
@@ -334,6 +339,9 @@ public final class SystemMetrics: @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Leistung aus dem SMC: positiv beim Laden, negativ beim Entladen.
|
// Leistung aus dem SMC: positiv beim Laden, negativ beim Entladen.
|
||||||
|
reading.isLowPower = ProcessInfo.processInfo.isLowPowerModeEnabled
|
||||||
|
// TB0T ist die Akkutemperatur; nicht jede Maschine führt sie.
|
||||||
|
reading.celsius = smc?.float("TB0T").map { Double($0) }
|
||||||
if let watts = smc?.float("PPBR") {
|
if let watts = smc?.float("PPBR") {
|
||||||
reading.watts = reading.isCharging ? watts : -watts
|
reading.watts = reading.isCharging ? watts : -watts
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,22 @@
|
|||||||
{
|
{
|
||||||
"sourceLanguage": "en",
|
"sourceLanguage": "en",
|
||||||
"strings": {
|
"strings": {
|
||||||
|
"menubar.short.network": {
|
||||||
|
"localizations": {
|
||||||
|
"de": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Netz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Net"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"network.addresses": {
|
"network.addresses": {
|
||||||
"localizations": {
|
"localizations": {
|
||||||
"de": {
|
"de": {
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public final class NetworkMenuBarModule: MenuBarModule {
|
|||||||
|
|
||||||
public init(model: NetworkModel) { self.model = model }
|
public init(model: NetworkModel) { self.model = model }
|
||||||
|
|
||||||
|
public var shortLabel: String { String(localized: "menubar.short.network", bundle: .module) }
|
||||||
|
|
||||||
public func makeStatusView(presentation: MenuBarPresentation) -> NSView {
|
public func makeStatusView(presentation: MenuBarPresentation) -> NSView {
|
||||||
let view = NetworkStatusView(presentation: presentation)
|
let view = NetworkStatusView(presentation: presentation)
|
||||||
view.update(model.snapshot, history: model.series(download: true))
|
view.update(model.snapshot, history: model.series(download: true))
|
||||||
@@ -84,6 +86,8 @@ final class NetworkStatusView: NSView {
|
|||||||
case .graph, .bars: 28
|
case .graph, .bars: 28
|
||||||
case .value: ratesWidth
|
case .value: ratesWidth
|
||||||
case .valueAndGraph: ratesWidth + 26
|
case .valueAndGraph: ratesWidth + 26
|
||||||
|
// Die Raten tragen mit ↓ und ↑ ihre Beschriftung schon in sich.
|
||||||
|
case .labelAndValue, .symbolAndValue: ratesWidth + MenuBarText.symbolWidth + 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +121,12 @@ final class NetworkStatusView: NSView {
|
|||||||
case .graph, .bars:
|
case .graph, .bars:
|
||||||
drawGraph(color: color, in: bounds.insetBy(dx: 2, dy: 5))
|
drawGraph(color: color, in: bounds.insetBy(dx: 2, dy: 5))
|
||||||
|
|
||||||
|
case .labelAndValue, .symbolAndValue:
|
||||||
|
MenuBarText.drawSymbol(snapshot.interfaceKind.symbolName, color: color,
|
||||||
|
in: NSRect(x: 0, y: bounds.midY - 6.5, width: 13, height: 13))
|
||||||
|
drawRates(color: color,
|
||||||
|
in: NSRect(x: 15, y: 0, width: bounds.width - 15, height: bounds.height))
|
||||||
|
|
||||||
case .value, .valueAndGraph:
|
case .value, .valueAndGraph:
|
||||||
drawRates(color: color,
|
drawRates(color: color,
|
||||||
in: presentation == .value ? bounds
|
in: presentation == .value ? bounds
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ import Foundation
|
|||||||
|
|
||||||
/// Das aktuelle Ladelimit in Prozent, `-1` wenn keines gilt.
|
/// Das aktuelle Ladelimit in Prozent, `-1` wenn keines gilt.
|
||||||
///
|
///
|
||||||
|
/// Nur lesen. Der SMC lehnt Schreibzugriffe auf `CHLT` ab — nachgemessen,
|
||||||
|
/// siehe docs/spikes/A-smc.md. macOS setzt den Wert offenbar auf einem
|
||||||
|
/// anderen Weg als über den SMC-Userclient.
|
||||||
|
///
|
||||||
/// `Int` statt `Int?`: Optionals sind über `@objc` nicht darstellbar.
|
/// `Int` statt `Int?`: Optionals sind über `@objc` nicht darstellbar.
|
||||||
func chargeLimit(reply: @escaping (Int) -> Void)
|
func chargeLimit(reply: @escaping (Int) -> Void)
|
||||||
|
|
||||||
/// Setzt das Ladelimit. Der Helfer begrenzt auf den gemessenen Bereich und
|
|
||||||
/// liest nach dem Schreiben zurück — gemeldet wird, was tatsächlich steht.
|
|
||||||
func setChargeLimit(percent: Int, reply: @escaping (Int) -> Void)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Was der Helfer über einen Lüfter berichtet.
|
/// Was der Helfer über einen Lüfter berichtet.
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ public enum MenuBarPresentation: String, Codable, Sendable, CaseIterable, Identi
|
|||||||
case valueAndGraph
|
case valueAndGraph
|
||||||
/// Nur ein Glyph, nach Grenzwert eingefärbt.
|
/// Nur ein Glyph, nach Grenzwert eingefärbt.
|
||||||
case symbol
|
case symbol
|
||||||
|
/// Kürzel und Wert, z. B. `CPU 34 %`.
|
||||||
|
///
|
||||||
|
/// Fünf nackte Prozentzahlen nebeneinander sind unbrauchbar: man sieht
|
||||||
|
/// Zahlen und weiß nicht, welche wozu gehört.
|
||||||
|
case labelAndValue
|
||||||
|
/// Glyph und Wert, z. B. 🔋 `34 %`.
|
||||||
|
case symbolAndValue
|
||||||
|
|
||||||
public var id: String { rawValue }
|
public var id: String { rawValue }
|
||||||
}
|
}
|
||||||
@@ -25,6 +32,9 @@ public protocol MenuBarModule: AnyObject {
|
|||||||
var id: String { get }
|
var id: String { get }
|
||||||
var displayName: String { get }
|
var displayName: String { get }
|
||||||
|
|
||||||
|
/// Das Kürzel für die Menüleiste — kurz, sonst frisst es die Leiste auf.
|
||||||
|
var shortLabel: String { get }
|
||||||
|
|
||||||
/// Zeichnet den kompakten Zustand. Muss eine feste Breite je Darstellungsart
|
/// Zeichnet den kompakten Zustand. Muss eine feste Breite je Darstellungsart
|
||||||
/// liefern, sonst springt die ganze Menüleiste bei jedem Messwert.
|
/// liefern, sonst springt die ganze Menüleiste bei jedem Messwert.
|
||||||
func makeStatusView(presentation: MenuBarPresentation) -> NSView
|
func makeStatusView(presentation: MenuBarPresentation) -> NSView
|
||||||
|
|||||||
@@ -72,7 +72,39 @@ Vorhanden ist stattdessen ein umfangreicher `CH*`-Satz. Plausible Kandidaten:
|
|||||||
**Das bleibt Vermutung, und Vermutungen werden hier nicht geschrieben.** Ein falscher Wert im
|
**Das bleibt Vermutung, und Vermutungen werden hier nicht geschrieben.** Ein falscher Wert im
|
||||||
Lade-Subsystem ist die eine Operation in diesem Projekt, die Hardware dauerhaft beschädigen kann.
|
Lade-Subsystem ist die eine Operation in diesem Projekt, die Hardware dauerhaft beschädigen kann.
|
||||||
|
|
||||||
### Nächster Schritt: Differenzmessung statt Raten
|
### Nachtrag 11.08.2026: Key gefunden, aber nicht beschreibbar
|
||||||
|
|
||||||
|
Die Differenzmessung hat ihn geliefert. Der Key heißt **`CHLT`**, Typ `hex_`, drei Bytes:
|
||||||
|
|
||||||
|
| macOS-Einstellung | `CHLT` |
|
||||||
|
|---|---|
|
||||||
|
| 80 % | `50 01 00` |
|
||||||
|
| 85 % | `55 01 00` |
|
||||||
|
| 95 % | `5F 01 00` |
|
||||||
|
|
||||||
|
Erstes Byte ist die Prozentzahl, zweites offenbar „Limit aktiv", drittes unbenutzt.
|
||||||
|
Drei Messpunkte, weil einer Zufall sein kann: `BACC` passte beim ersten Vergleich ebenfalls —
|
||||||
|
ein Zähler, in dem gerade `50` stand. `ChargerConfiguration` aus `ioreg` sah mit niedrigem
|
||||||
|
Byte `0x50` ebenfalls wie eine Quelle aus, blieb aber unverändert, als `CHLT` längst auf 95
|
||||||
|
stand.
|
||||||
|
|
||||||
|
**Schreiben scheitert.** Der Helfer hat es mit korrekter Größe (3 Byte) versucht; der
|
||||||
|
SMC-Userclient gibt einen Fehler zurück, der Wert bleibt stehen:
|
||||||
|
|
||||||
|
```
|
||||||
|
Ladelimit: 95 % gewünscht, 95 % geschrieben (false), zurückgelesen 85 %
|
||||||
|
```
|
||||||
|
|
||||||
|
macOS setzt das Limit also auf einem anderen Weg. Welchem, ist offen — und weiter zu raten
|
||||||
|
hieße, im Lade-Subsystem Keys durchzuprobieren. Das ist die eine Operation in diesem Projekt,
|
||||||
|
die Hardware dauerhaft beschädigen kann, also unterbleibt es.
|
||||||
|
|
||||||
|
**Folge für Onyx:** das Ladelimit ist eine **Anzeige**. Der Wert wird gelesen und im
|
||||||
|
Akku-Widget sowie im Akku-Popover gezeigt, mit einem Weg in die Systemeinstellungen. Der
|
||||||
|
Schreibpfad ist aus dem privilegierten Helfer wieder entfernt — ein Root-Dienst trägt nur,
|
||||||
|
was benutzt wird.
|
||||||
|
|
||||||
|
### Damals geplanter Schritt: Differenzmessung statt Raten
|
||||||
|
|
||||||
macOS hat selbst eine Ladebegrenzung (Systemeinstellungen → Batterie → Batteriezustand →
|
macOS hat selbst eine Ladebegrenzung (Systemeinstellungen → Batterie → Batteriezustand →
|
||||||
„Optimiertes Laden" bzw. das 80-%-Limit). Wird sie umgeschaltet, muss sich der zuständige
|
„Optimiertes Laden" bzw. das 80-%-Limit). Wird sie umgeschaltet, muss sich der zuständige
|
||||||
|
|||||||
Reference in New Issue
Block a user