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:
@@ -1,90 +1,72 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
import OnyxDesign
|
||||
import OnyxHelperProtocol
|
||||
|
||||
/// Wer das Ladelimit setzen kann.
|
||||
/// Wer das Ladelimit **lesen** kann.
|
||||
///
|
||||
/// Ein Protokoll und kein direkter Zugriff: das Limit schreibt der privilegierte
|
||||
/// Helfer, und der gehört zur App, nicht zu diesem Package. Die Akku-Ansicht
|
||||
/// soll ihn bedienen können, ohne ihn zu kennen.
|
||||
/// Nur lesen, und das ist eine gemessene Grenze, keine Bequemlichkeit: der
|
||||
/// SMC lehnt Schreibzugriffe auf `CHLT` ab. Der Helfer hat es versucht und
|
||||
/// `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
|
||||
public protocol ChargeLimitControlling: AnyObject {
|
||||
public protocol ChargeLimitReading: AnyObject {
|
||||
/// Das eingestellte Limit in Prozent, `nil` wenn keines gilt.
|
||||
var chargeLimit: Int? { get }
|
||||
/// Ob überhaupt geschrieben werden kann — ohne Helfer geht nichts.
|
||||
var canControlCharge: Bool { get }
|
||||
/// Ob der Wert überhaupt gelesen werden kann — ohne Helfer nicht.
|
||||
var canReadCharge: Bool { get }
|
||||
func refreshChargeLimit()
|
||||
func setChargeLimit(_ percent: Int)
|
||||
}
|
||||
|
||||
/// Der Ladelimit-Regler, wie er im Akku-Widget und im Akku-Popover steht.
|
||||
///
|
||||
/// 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.
|
||||
/// Zeigt das Ladelimit und führt dorthin, wo man es ändern kann.
|
||||
public struct ChargeLimitControl: View {
|
||||
|
||||
private let control: any ChargeLimitControlling
|
||||
/// Im Popover ist Platz für die Erklärung, in der Kachel nicht.
|
||||
private let control: any ChargeLimitReading
|
||||
/// Im Popover ist Platz für den Hinweis, in der Kachel nicht.
|
||||
private let roomy: Bool
|
||||
|
||||
@State private var pending: Double?
|
||||
|
||||
public init(control: any ChargeLimitControlling, roomy: Bool) {
|
||||
public init(control: any ChargeLimitReading, roomy: Bool) {
|
||||
self.control = control
|
||||
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 {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
HStack(spacing: 6) {
|
||||
Text("charge.limit", bundle: .module)
|
||||
.font(Onyx.Font.caption)
|
||||
.foregroundStyle(Onyx.Color.textSecondary)
|
||||
Spacer(minLength: 4)
|
||||
Group {
|
||||
// Hundert Prozent ist kein Limit — und soll auch nicht so
|
||||
// heißen, sonst sucht man den Ausschalter.
|
||||
if isOff {
|
||||
Text("charge.limit.off", bundle: .module)
|
||||
} else {
|
||||
Text(verbatim: "\(Int(current)) %")
|
||||
}
|
||||
}
|
||||
.font(Onyx.Font.metricSmall).monospacedDigit()
|
||||
.foregroundStyle(isOff ? Onyx.Color.textTertiary : Onyx.Color.accent)
|
||||
HStack(spacing: 6) {
|
||||
Text("charge.limit", bundle: .module)
|
||||
.font(Onyx.Font.caption)
|
||||
.foregroundStyle(Onyx.Color.textSecondary)
|
||||
|
||||
Spacer(minLength: 4)
|
||||
|
||||
if let limit = control.chargeLimit, limit < ChargeSafety.noLimit {
|
||||
Text(verbatim: "\(limit) %")
|
||||
.font(Onyx.Font.metricSmall).monospacedDigit()
|
||||
.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 }),
|
||||
in: Double(ChargeSafety.minimumPercent)...Double(ChargeSafety.maximumPercent),
|
||||
onEditingChanged: { editing in
|
||||
// Erst beim Loslassen schreiben. Bei jedem Zwischenwert
|
||||
// in den Ladepfad zu schreiben wäre ein Dutzend
|
||||
// Schreibvorgänge für eine einzige Entscheidung.
|
||||
guard !editing, let pending else { return }
|
||||
control.setChargeLimit(Int(pending))
|
||||
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)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
} else if roomy {
|
||||
Text("charge.limit.hint", bundle: .module)
|
||||
.font(Onyx.Font.metricSmall)
|
||||
.foregroundStyle(Onyx.Color.textTertiary)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
if roomy {
|
||||
// Kein Regler, sondern der Weg dorthin, wo es wirklich geht.
|
||||
Button {
|
||||
NSWorkspace.shared.open(
|
||||
URL(string: "x-apple.systempreferences:com.apple.Battery-Settings.extension")!)
|
||||
} label: {
|
||||
Image(systemName: "arrow.up.forward.app")
|
||||
.font(.system(size: 10))
|
||||
.foregroundStyle(Onyx.Color.textTertiary)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.help(Text("charge.limit.inSystemSettings", bundle: .module))
|
||||
}
|
||||
}
|
||||
.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": {
|
||||
"localizations": {
|
||||
"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": {
|
||||
"localizations": {
|
||||
"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": {
|
||||
"localizations": {
|
||||
"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"
|
||||
|
||||
@@ -28,8 +28,20 @@ public final class MetricMenuBarModule: MenuBarModule {
|
||||
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 {
|
||||
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),
|
||||
mode: model.displayMode(for: metric))
|
||||
self.view = view
|
||||
@@ -84,9 +96,12 @@ final class MetricStatusView: NSView, WidthReporting {
|
||||
private var history: [Double] = []
|
||||
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.presentation = presentation
|
||||
self.label = label
|
||||
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 .value: MenuBarText.width(for: reference)
|
||||
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))
|
||||
case .bars:
|
||||
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:
|
||||
let split = bounds.width * 0.55
|
||||
drawText(MetricSummary.value(metric, snapshot, mode: mode), color: color,
|
||||
|
||||
@@ -232,7 +232,7 @@ private struct MemoryDetail: View {
|
||||
|
||||
private struct BatteryDetail: View {
|
||||
let snapshot: MetricsSnapshot
|
||||
let control: (any ChargeLimitControlling)?
|
||||
let control: (any ChargeLimitReading)?
|
||||
|
||||
var body: some View {
|
||||
if let battery = snapshot.battery {
|
||||
|
||||
@@ -54,14 +54,8 @@ private struct MetricWidgetView: View {
|
||||
// alles andere zeigt Zahl und Verlauf.
|
||||
if metric == .temperature {
|
||||
SensorList(snapshot: model.snapshot, detailed: true)
|
||||
} else if metric == .battery, let control = model.chargeControl {
|
||||
// Die Akku-Kachel bekommt den Ladelimit-Regler direkt: dort
|
||||
// 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 if metric == .battery {
|
||||
BatteryTile(model: model)
|
||||
} else {
|
||||
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.
|
||||
/// `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()
|
||||
/// 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 watts: Double? // negativ = Entladung
|
||||
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.
|
||||
@@ -334,6 +339,9 @@ public final class SystemMetrics: @unchecked Sendable {
|
||||
}
|
||||
|
||||
// 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") {
|
||||
reading.watts = reading.isCharging ? watts : -watts
|
||||
}
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
{
|
||||
"sourceLanguage": "en",
|
||||
"strings": {
|
||||
"menubar.short.network": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Netz"
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Net"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"network.addresses": {
|
||||
"localizations": {
|
||||
"de": {
|
||||
|
||||
@@ -21,6 +21,8 @@ public final class NetworkMenuBarModule: MenuBarModule {
|
||||
|
||||
public init(model: NetworkModel) { self.model = model }
|
||||
|
||||
public var shortLabel: String { String(localized: "menubar.short.network", bundle: .module) }
|
||||
|
||||
public func makeStatusView(presentation: MenuBarPresentation) -> NSView {
|
||||
let view = NetworkStatusView(presentation: presentation)
|
||||
view.update(model.snapshot, history: model.series(download: true))
|
||||
@@ -84,6 +86,8 @@ final class NetworkStatusView: NSView {
|
||||
case .graph, .bars: 28
|
||||
case .value: ratesWidth
|
||||
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:
|
||||
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:
|
||||
drawRates(color: color,
|
||||
in: presentation == .value ? bounds
|
||||
|
||||
@@ -31,12 +31,12 @@ import Foundation
|
||||
|
||||
/// 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.
|
||||
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.
|
||||
|
||||
@@ -12,6 +12,13 @@ public enum MenuBarPresentation: String, Codable, Sendable, CaseIterable, Identi
|
||||
case valueAndGraph
|
||||
/// Nur ein Glyph, nach Grenzwert eingefärbt.
|
||||
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 }
|
||||
}
|
||||
@@ -25,6 +32,9 @@ public protocol MenuBarModule: AnyObject {
|
||||
var id: 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
|
||||
/// liefern, sonst springt die ganze Menüleiste bei jedem Messwert.
|
||||
func makeStatusView(presentation: MenuBarPresentation) -> NSView
|
||||
|
||||
Reference in New Issue
Block a user