diff --git a/.changeset/charging-starts-in-a-moment.md b/.changeset/charging-starts-in-a-moment.md new file mode 100644 index 0000000..a33cf6d --- /dev/null +++ b/.changeset/charging-starts-in-a-moment.md @@ -0,0 +1,5 @@ +--- +"ewiz": patch +--- + +**Switching the limit off says charging is about to start.** On Macs that limit through macOS's own charge limit, macOS can take up to a minute to start charging again after the limit is released. The panel used to say "Plugged in, not charging" for that whole time, as if the switch had done nothing. It now says "Plugged in", with "Charging starts in a moment" (the same message shown while eWiz settles after wake), until current starts flowing. diff --git a/Sources/EWizKit/ChargeDisplay.swift b/Sources/EWizKit/ChargeDisplay.swift index ff4e8c9..b27ad46 100644 --- a/Sources/EWizKit/ChargeDisplay.swift +++ b/Sources/EWizKit/ChargeDisplay.swift @@ -253,6 +253,9 @@ public struct ChargeDisplay: Equatable, Sendable { // The cable is in and the helper has cut it; "Plugged in" would argue with the // menu bar's own battery icon, which says battery power. case .draining where !input.isPluggedIn: return "On battery" + // About to charge (after wake, or macOS picking up after a limit is released): + // "not charging" read as the switch having failed. + case .paused(.settling): return "Plugged in" default: return "Plugged in, not charging" } } @@ -303,7 +306,7 @@ public struct ChargeDisplay: Equatable, Sendable { case .paused(.heat): return "Charging paused, battery is warm" case .paused(.settling): - return "Charging resumes shortly after wake" + return "Charging resumes in a moment" case .paused(.schedule): return "A schedule is holding charging" // A user pause has its own row with a Resume button; a drain is the header's @@ -335,7 +338,7 @@ public struct ChargeDisplay: Equatable, Sendable { case .draining(let to): return "Draining to \(to)% ยท \(pct)%" case .paused(.user): return "Charging paused" case .paused(.heat): return "Charging paused, battery warm" - case .paused(.settling): return "Settling after wake" + case .paused(.settling): return "Charging starts in a moment" case .paused(.schedule): return "A schedule is holding charging" case .paused(.sleep): return "Charging cut for sleep" case .full: return "Fully charged" diff --git a/Sources/EWizKit/Control.swift b/Sources/EWizKit/Control.swift index cf11dec..26f03d6 100644 --- a/Sources/EWizKit/Control.swift +++ b/Sources/EWizKit/Control.swift @@ -407,7 +407,9 @@ public enum HelperBuild { /// on its own limit; the adapter stands in for up to 90 s until it has. /// v33: the cable reads as in through an adapter cut (ExternalChargeCapable), where /// ExternalConnected alone said unplugged. - public static let version = 33 + /// v34: for two minutes after eWiz releases macOS's limit, a battery not yet charging + /// is reported as about to ("settling"), since macOS can take a minute to start. + public static let version = 34 } public enum ControlError: Error, CustomStringConvertible { diff --git a/Sources/ewiz-helper/Daemon.swift b/Sources/ewiz-helper/Daemon.swift index 4060d32..55d3077 100644 --- a/Sources/ewiz-helper/Daemon.swift +++ b/Sources/ewiz-helper/Daemon.swift @@ -106,6 +106,10 @@ final class Daemon: @unchecked Sendable { /// How long macOS gets to act on its own limit before the stand-in steps back. Traced at /// 42 s from the limit being set to current stopping; 90 covers a slow PowerUIAgent. private let nativeBridgeWindow: TimeInterval = 90 + /// When eWiz last released macOS's limit, for the "charging starts in a moment" spell. + private var nativeReleasedAt: Date? + /// How long after a release a battery not yet charging counts as about to. + private let nativeResumeWindow: TimeInterval = 120 /// On the cable but running off the battery, because the battery is above the step /// macOS is holding and macOS brings it down. `pmset` says "AC attached; not charging" /// throughout, so without this the app would show a draining battery as "held". @@ -672,8 +676,15 @@ final class Daemon: @unchecked Sendable { nativeHolding = nativeApplied != nil && snap.onExternalPower && !adapterCut && !snap.isCharging nativeDraining = nativeHolding && PowerMonitor.read().dischargeWatts > 2 if !chargeControlSupported { + // Just after eWiz lets go of macOS's limit, macOS takes its time starting the + // charge again: traced at up to a minute at 93%. "Settling" is the word the app + // already has for "charging starts in a moment", and it beats "Plugged in, not + // charging", which read as the switch having done nothing. + let resuming = nativeReleasedAt.map { now.timeIntervalSince($0) < nativeResumeWindow } ?? false + && snap.onExternalPower && !snap.isCharging && !snap.isFullyCharged && level < 100 lastPauseReason = adapterHolding ? "hold" - : nativeHolding ? (paused ? "paused" : cfg.holdCharge ? "hold" : "limit") : nil + : nativeHolding ? (paused ? "paused" : cfg.holdCharge ? "hold" : "limit") + : resuming ? "settling" : nil } updateMagSafeLED(cfg, snap, takingCharge: takingCharge(cfg, snap, desired: desired, enable: enable), settling: settling) @@ -1288,6 +1299,7 @@ final class Daemon: @unchecked Sendable { if current?.limit == owned { guard native.disable() else { err("could not release the macOS charge limit"); return } log("macOS charge limit released") + nativeReleasedAt = now } nativeApplied = nil NativeChargeLimitOwnership.save(nil) diff --git a/Tests/EWizKitTests/ChargeDisplayTests.swift b/Tests/EWizKitTests/ChargeDisplayTests.swift index e3b5eb3..c1ad091 100644 --- a/Tests/EWizKitTests/ChargeDisplayTests.swift +++ b/Tests/EWizKitTests/ChargeDisplayTests.swift @@ -225,7 +225,9 @@ struct ChargeDisplayTests { let settling = ChargeDisplay(.init(percentage: 60, isCharging: false, isPluggedIn: true, limitEnabled: true, effectiveLimit: 80, pauseReason: "settling")) #expect(settling.state == .paused(.settling)) - #expect(settling.hint == "Charging resumes shortly after wake") + #expect(settling.hint == "Charging resumes in a moment") + #expect(settling.statusLine == "Plugged in") + #expect(settling.tooltip == "Charging starts in a moment") #expect(settling.mark == .none, "a few seconds of settling is not a hold") #expect(settling.headerNote == "Charging starts in a moment") let negotiating = ChargeDisplay(.init(percentage: 32, isCharging: false, isPluggedIn: true))