diff --git a/CHANGELOG.md b/CHANGELOG.md index e1b1f824..ed6c17b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ### 6.2.0 (26-06-2026) **Features**: -- Virtual front derailleur: adds a second chainring (2× drivetrain) for more realism. The new assignable "Front Shift (Chainring)" action — or pressing both shifters together, SRAM-AXS style — toggles between your small and large rings, changing resistance by the exact chainring ratio while staying on the same rear cog. While it's active your current gear reads as head-unit-style position notation (e.g. 2×14) in the app, the gear overlay, and the iOS Live Activity. Set your chainring sizes per trainer in the gear settings. +- Virtual front derailleur: adds a second chainring (2× drivetrain) for more realism. The new assignable "Front Shift (Chainring)" action toggles between your small and large rings, changing resistance by the exact chainring ratio while staying on the same rear cog. - SRAM style shifting: when you click shift up & down at the same time, the front chainring switches - iOS / iPadOS: Floating gear overlay (Picture-in-Picture): your current gear can now show in a floating window over your trainer app during a ride. - Screen recording: a new assignable "Record Screen" action starts a screen recording from a controller button. diff --git a/lib/pages/proxy_device_details/gear_ratios_editor_page.dart b/lib/pages/proxy_device_details/gear_ratios_editor_page.dart index ca0b5368..ead845c2 100644 --- a/lib/pages/proxy_device_details/gear_ratios_editor_page.dart +++ b/lib/pages/proxy_device_details/gear_ratios_editor_page.dart @@ -139,49 +139,7 @@ class _GearRatiosEditorPageState extends State { Widget _heroCurve(BuildContext context) => GearRatioCurve(definition: def); - Widget _vsModeCard() { - return AnimatedBuilder( - animation: Listenable.merge([def.virtualShiftingMode, def.trainerFeature]), - builder: (context, _) { - final mode = def.virtualShiftingMode.value; - return SettingTile( - title: AppLocalizations.of(context).virtualShiftingMode, - subtitle: AppLocalizations.of(context).virtualShiftingModeDesc, - child: RadioGroup( - value: mode, - onChanged: (v) async { - def.setVirtualShiftingMode(v); - await _updateActive((c) => c.copyWith(mode: v)); - }, - child: Row( - spacing: 6, - children: [ - _vsRadioCard(AppLocalizations.of(context).targetPowerMode, VirtualShiftingMode.targetPower), - _vsRadioCard(AppLocalizations.of(context).trackResistanceMode, VirtualShiftingMode.trackResistance), - _vsRadioCard(AppLocalizations.of(context).basicMode, VirtualShiftingMode.basicResistance), - ], - ), - ), - ); - }, - ); - } - - Widget _vsRadioCard(String label, VirtualShiftingMode value) { - final supported = def.supportsVirtualShiftingMode(value); - return Expanded( - child: RadioCard( - value: value, - enabled: supported, - child: Center( - child: Text( - label, - style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600), - ), - ), - ), - ); - } + Widget _vsModeCard() => VirtualShiftingModeCard(definition: def, device: widget.device); Widget _gearCountCard(BuildContext context) { final cs = Theme.of(context).colorScheme; @@ -556,3 +514,67 @@ class _Preset { final List values; _Preset({required this.label, required this.range, required this.values}); } + +/// The Virtual Shifting mode selector (Target Power / Track Resistance / Basic), +/// extracted from [GearRatiosEditorPage] so it can be rendered standalone (e.g. +/// for a widget snapshot). It reads/writes the same [core.shiftingConfigs] and +/// the passed [definition], so behaviour inside the page is unchanged. +class VirtualShiftingModeCard extends StatelessWidget { + final FitnessBikeDefinition definition; + final ProxyDevice device; + const VirtualShiftingModeCard({ + super.key, + required this.definition, + required this.device, + }); + + Future _updateActive(ShiftingConfig Function(ShiftingConfig) mutate) async { + final current = core.shiftingConfigs.activeFor(device.trainerKey); + await core.shiftingConfigs.upsert(mutate(current)); + } + + Widget _vsRadioCard(String label, VirtualShiftingMode value) { + final supported = definition.supportsVirtualShiftingMode(value); + return Expanded( + child: RadioCard( + value: value, + enabled: supported, + child: Center( + child: Text( + label, + style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600), + ), + ), + ), + ); + } + + @override + Widget build(BuildContext context) { + return AnimatedBuilder( + animation: Listenable.merge([definition.virtualShiftingMode, definition.trainerFeature]), + builder: (context, _) { + final mode = definition.virtualShiftingMode.value; + return SettingTile( + title: AppLocalizations.of(context).virtualShiftingMode, + subtitle: AppLocalizations.of(context).virtualShiftingModeDesc, + child: RadioGroup( + value: mode, + onChanged: (v) async { + definition.setVirtualShiftingMode(v); + await _updateActive((c) => c.copyWith(mode: v)); + }, + child: Row( + spacing: 6, + children: [ + _vsRadioCard(AppLocalizations.of(context).targetPowerMode, VirtualShiftingMode.targetPower), + _vsRadioCard(AppLocalizations.of(context).trackResistanceMode, VirtualShiftingMode.trackResistance), + _vsRadioCard(AppLocalizations.of(context).basicMode, VirtualShiftingMode.basicResistance), + ], + ), + ), + ); + }, + ); + } +} diff --git a/screenshots/en/overlay-settings.png b/screenshots/en/overlay-settings.png new file mode 100644 index 00000000..71362e3e Binary files /dev/null and b/screenshots/en/overlay-settings.png differ diff --git a/screenshots/en/ride-feel.png b/screenshots/en/ride-feel.png new file mode 100644 index 00000000..c1eed467 Binary files /dev/null and b/screenshots/en/ride-feel.png differ diff --git a/screenshots/en/shifting-config-picker.png b/screenshots/en/shifting-config-picker.png new file mode 100644 index 00000000..a4984670 Binary files /dev/null and b/screenshots/en/shifting-config-picker.png differ diff --git a/screenshots/en/vs-mode.png b/screenshots/en/vs-mode.png new file mode 100644 index 00000000..ea20e248 Binary files /dev/null and b/screenshots/en/vs-mode.png differ diff --git a/test/screenshot_test.dart b/test/screenshot_test.dart index 8fded0c4..e5171f98 100644 --- a/test/screenshot_test.dart +++ b/test/screenshot_test.dart @@ -22,6 +22,11 @@ import 'package:bike_control/pages/overview.dart'; import 'package:bike_control/pages/proxy_device_details.dart'; import 'package:bike_control/pages/proxy_device_details/front_shift_card.dart'; import 'package:bike_control/pages/proxy_device_details/gear_ratios_editor_page.dart'; +import 'package:bike_control/pages/proxy_device_details/overlay_settings_section.dart'; +import 'package:bike_control/pages/proxy_device_details/shifting_config_picker.dart'; +import 'package:bike_control/pages/proxy_device_details/trainer_settings_section.dart'; +import 'package:bike_control/models/shifting_config.dart'; +import 'package:bike_control/services/overlay/trainer_overlay_service.dart'; import 'package:bike_control/pages/trainer_connection_settings.dart'; import 'package:bike_control/utils/core.dart' show core; import 'package:bike_control/utils/iap/iap_manager.dart'; @@ -47,6 +52,7 @@ import 'package:bike_control/widgets/controller/controller_canvas.dart'; import 'package:bike_control/widgets/overlay/trainer_overlay_view.dart'; import 'package:bike_control/widgets/ui/animated_button_widget.dart'; import 'package:flutter/material.dart' as ma; +import 'package:flutter/services.dart' show MethodChannel; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:golden_screenshot/golden_screenshot.dart' hide testGoldens; @@ -354,8 +360,13 @@ Future main() async { Finder Function()? capture, Future Function(WidgetTester tester)? afterPump, TargetPlatform platform = TargetPlatform.android, + // Override the (frameless) render resolution. Defaults to the noFrame size + // (~367 logical px wide); pass a wider Size for widgets that need more room + // (e.g. a Row whose Select would collapse at phone-narrow widths). + Size? size, }) async { final nf = sizes.firstWhere((s) => s.type == DeviceType.noFrame); + final res = size ?? nf.size; await AppLocalizations.load(const Locale('en')); screenshotLocale = const Locale('en'); await tester.pumpWidget( @@ -366,7 +377,7 @@ Future main() async { // queries the Windows accent colour via advapi32.dll, which can't load // on a macOS test host. platform: platform, - resolution: nf.size, + resolution: res, pixelRatio: 3, goldenSubFolder: 'iphoneScreenshots/', frameBuilder: @@ -1091,4 +1102,141 @@ Future main() async { testGoldens('overview-thinkrider-vs200', (WidgetTester tester) async { await shootOverview(tester, 'overview-thinkrider-vs200', thinkriderVs200); }); + + // --- Virtual-shifting settings widget snapshots (settings video) ------------- + // Tight single-widget captures of the virtual-shifting settings controls, each + // rendered standalone inside a keyed RepaintBoundary (English, light) so the + // golden captures ONLY that widget (no page chrome). + + // Seed a few NAMED shifting configs for the proxy trainer, with "Climb day" + // active, so the picker and the settings sections show genuine content. + Future seedShiftingConfigs() async { + final key = proxy.trainerKey; + await core.shiftingConfigs.upsert( + ShiftingConfig.defaults(trainerKey: key, name: 'Default', isActive: false), + ); + await core.shiftingConfigs.upsert( + ShiftingConfig.defaults(trainerKey: key, name: 'Sprint', isActive: false) + .copyWith(riderWeightKg: 72, bikeWeightKg: 7.5), + ); + await core.shiftingConfigs.upsert( + ShiftingConfig.defaults(trainerKey: key, name: 'Climb day', isActive: true) + .copyWith(riderWeightKg: 78, bikeWeightKg: 8.5), + ); + } + + // 1) The named-config picker (active "Climb day" + New / Manage buttons). + testGoldens('shifting-config-picker', (WidgetTester tester) async { + await seedShiftingConfigs(); + const k = ValueKey('shot'); + await shootOne( + tester, + 'shifting-config-picker', + () => BikeControlApp( + customChild: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(20), + child: RepaintBoundary( + key: k, + child: ShiftingConfigPicker(trainerKey: proxy.trainerKey), + ), + ), + ), + ), + capture: () => find.byKey(k), + size: const Size(1980, 2390), + ); + }); + + // 2) Ride-feel / trainer settings: the config picker + gear settings card + + // bike-weight + rider-weight steppers. + testGoldens('ride-feel', (WidgetTester tester) async { + await seedShiftingConfigs(); + proxy.debugAttachFitnessBike(fbd); + const k = ValueKey('shot'); + await shootOne( + tester, + 'ride-feel', + () => BikeControlApp( + customChild: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(20), + child: RepaintBoundary( + key: k, + child: TrainerSettingsSection(definition: fbd, device: proxy), + ), + ), + ), + ), + capture: () => find.byKey(k), + // Wide enough that the embedded config picker's Select shows the active + // config name on one line (it sizes to its Expanded slot, which collapses + // at phone-narrow widths). + size: const Size(1980, 2390), + ); + }); + + // 3) Overlay settings: the enable tile + the display-field toggles (Power / + // Cadence / ERG / Gear / Controls). The field list only renders while the + // overlay is "showing", so flip the platform controller (the same singleton + // the section reads in initState) on up front. + testGoldens('overlay-settings', (WidgetTester tester) async { + proxy.debugAttachFitnessBike(fbd); + // The desktop overlay controller opens a native window via this method + // channel; stub it so show() (used below to expand the field list) doesn't + // throw MissingPluginException in the host test VM. + tester.binding.defaultBinaryMessenger.setMockMethodCallHandler( + const MethodChannel('com.coditas.multi_window_native/pluginChannel'), + (call) async => null, + ); + await core.settings.setOverlayFields({ + OverlayField.power, + OverlayField.cadence, + OverlayField.gearRatio, + }); + await TrainerOverlayService.forCurrentPlatform() + .show(fbd, core.settings.getOverlayFields()); + const k = ValueKey('shot'); + await shootOne( + tester, + 'overlay-settings', + () => BikeControlApp( + customChild: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(20), + child: RepaintBoundary( + key: k, + child: OverlaySettingsSection(definition: fbd, device: proxy), + ), + ), + ), + ), + capture: () => find.byKey(k), + ); + }); + + // 4) The Virtual Shifting mode selector (Target Power / Track Resistance / + // Basic radio group), extracted from GearRatiosEditorPage as a public widget. + testGoldens('vs-mode', (WidgetTester tester) async { + await seedShiftingConfigs(); + proxy.debugAttachFitnessBike(fbd); + fbd.setVirtualShiftingMode(VirtualShiftingMode.targetPower); + const k = ValueKey('shot'); + await shootOne( + tester, + 'vs-mode', + () => BikeControlApp( + customChild: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(20), + child: RepaintBoundary( + key: k, + child: VirtualShiftingModeCard(definition: fbd, device: proxy), + ), + ), + ), + ), + capture: () => find.byKey(k), + ); + }); }