Files
swiftcontrol/ios/Shared/GearSnapshot+LiveActivity.swift
Jonas Bark ff57b005d5 feat(shifting): show 2×N gear position when the front derailleur is active
With the virtual front derailleur on, the compact gear readout switches
from rear gear/total (14/25) to head-unit-style front×rear position
notation (small ring 1×N, large ring 2×N, e.g. 2×14) — matching how
Garmin/Wahoo display Di2/AXS gearing. With it off, it stays 14/25.

- Add tested formatGearReadout helper.
- Wire into the proxy card, debug menu, desktop second window + Android
  PiP/overlay (trainer_overlay_view), and the gear hero card (2× · 50T).
- Carry frontShiftEnabled + frontRingLarge through TrainerOverlayState
  (json, ==, hashCode, activity map) so the snapshot reaches the overlay
  and the iOS surfaces.
- iOS PiP + Live Activity: format 2×N centrally in GearSnapshot.
- Standardize the off-state readout to 14/25 across all surfaces.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 15:02:40 +02:00

32 lines
1.6 KiB
Swift

import ActivityKit
import Foundation
@available(iOS 16.1, *)
extension GearSnapshot {
/// Read the live_activities plugin's id-prefixed App Group keys (used by the
/// Lock-Screen / Dynamic Island widget). Lives in a TrainerActivity-target-ONLY
/// file (NOT compiled into Runner) because `LiveActivitiesAppAttributes` is
/// defined in the widget extension target. Keeping it out of the shared
/// `GearSnapshot.swift` lets that file compile into Runner without ActivityKit.
static func fromLiveActivity(_ attrs: LiveActivitiesAppAttributes, defaults: UserDefaults) -> GearSnapshot {
func k(_ s: String) -> String { attrs.prefixedKey(s) }
func optInt(_ key: String) -> Int? { defaults.object(forKey: key) as? Int }
return GearSnapshot(
gear: defaults.integer(forKey: k("gear")),
maxGear: defaults.integer(forKey: k("maxGear")),
mode: defaults.string(forKey: k("mode")) ?? "sim",
powerW: optInt(k("powerW")),
cadenceRpm: optInt(k("cadenceRpm")),
ergTargetW: optInt(k("ergTargetW")),
gearRatio: defaults.double(forKey: k("gearRatio")),
showPower: defaults.bool(forKey: k("showPower")),
showCadence: defaults.bool(forKey: k("showCadence")),
showErgTarget: defaults.bool(forKey: k("showErgTarget")),
showGearRatio: defaults.bool(forKey: k("showGearRatio")),
showControls: defaults.bool(forKey: k("showControls")),
frontShiftEnabled: defaults.bool(forKey: k("frontShiftEnabled")),
frontRingLarge: defaults.bool(forKey: k("frontRingLarge"))
)
}
}