mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-11-29 09:11:17 +01:00
Three things the chain got wrong once a real trainer was in the room.
The trainer card offered "Edit" for a trainer that had never been
connected — an offer to edit nothing. It now offers Connect until the
trainer is actually bridged, and that opens the onboarding trainer picker
itself: connectTrainerFromPicker is extracted so onboarding and the home
card share one path, and "connect my trainer" behaves identically wherever
a rider reaches it. Extracting it also removed an empty `if
(device.isSmartTrainer) {}` that the consent removal had left behind.
The checklist is withheld until the rider has committed to bridging. A
trainer merely in range and one deliberately left on "let the app handle
shifting" are the same state underneath — not connected — and in both
cases a column of unticked boxes reads as work outstanding when there is
none. That surfaced a related bug: picking "No connection" sets
autoConnect false, but a trainer that had connected earlier in the session
was still classified as lost, so deliberately disconnecting it turned the
card red. An explicit "no connection" is now a resting state regardless of
what happened earlier.
Status changes animate. The checklist grows and shrinks through
AnimatedSize, so when the last step ticks the card folds to its one-line
summary as a movement the eye can follow rather than a jump; the card
border and the banner — colour, wash, and the badge resizing between its
calm and alarmed sizes — move on the same curve, so the screen resolves as
one gesture instead of several. The test asserts the collapse is genuinely
taller mid-flight than at rest, because "it animates" is otherwise not
something a test can hold onto.
Finally, the trainer-app instructions sheet was a thinner retelling of the
setup steps rather than the steps themselves. The onboarding guide block
is extracted as OnboardingAppGuideCard and both use it, so a rider who
loses the connection gets the same numbered steps, the same screenshots
and the same full-guide link that got them connected in the first place.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
43 lines
2.0 KiB
Dart
43 lines
2.0 KiB
Dart
import 'package:bike_control/bluetooth/devices/proxy/proxy_device.dart';
|
|
import 'package:bike_control/main.dart' show recordError;
|
|
import 'package:bike_control/utils/core.dart';
|
|
import 'package:bike_control/utils/iap/iap_manager.dart';
|
|
import 'package:bike_control/widgets/go_pro_dialog.dart';
|
|
import 'package:bike_control/widgets/ui/toast.dart';
|
|
import 'package:prop/prop.dart' show LogLevel, RetrofitMode;
|
|
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
|
|
|
/// Connects a smart trainer the way the onboarding wizard does: pick it from a
|
|
/// list, and it bridges over WiFi.
|
|
///
|
|
/// Shared by the onboarding trainer step and the home screen's trainer card, so
|
|
/// "connect my trainer" behaves identically wherever a rider reaches it — same
|
|
/// transport, same trial gate, same routing through the connection manager.
|
|
///
|
|
/// Returns true when a connect was actually started.
|
|
Future<bool> connectTrainerFromPicker(BuildContext context, ProxyDevice device) async {
|
|
try {
|
|
if (device.isStartedListenable.value || device.isStarting.value || device.isConnectedListenable.value) {
|
|
return false;
|
|
}
|
|
if (IAPManager.instance.isTrialExpired) {
|
|
await showGoProDialog(context);
|
|
return false;
|
|
}
|
|
// WiFi transport: the trainer app finds "<trainer> - BikeControl" over the
|
|
// network, and no BLE-advertise permission prompt interrupts the flow.
|
|
device.setRetrofitMode(RetrofitMode.wifi);
|
|
await core.settings.setRetrofitMode(device.trainerKey, RetrofitMode.wifi);
|
|
await core.settings.setAutoConnect(device.trainerKey, true);
|
|
// Route through the connection manager (not device.startProxy directly) so
|
|
// the action / connection-state listeners are attached — same rationale as
|
|
// ConnectionCard._onSelect.
|
|
await core.connection.connectDevice(device);
|
|
return true;
|
|
} catch (e, s) {
|
|
recordError(e, s, context: 'connect trainer from picker');
|
|
buildToast(level: LogLevel.LOGLEVEL_ERROR, title: e.toString());
|
|
return false;
|
|
}
|
|
}
|