Files
swiftcontrol/lib/utils/help_article.dart
Jonas Bark 6a8f75b100 feat(onboarding): controller contour, skip-VS tears down bridges, correct help articles
Step 3's connected state renders the controller's contour via the same
ControllerCanvas the home screen uses, with human-readable button chips, so
riders see the buttons they just gained. 'Let {app} handle Virtual
Shifting' (footer and header Skip) now disconnects every smart-trainer
bridge — started, connected or still connecting — with auto-connect
cleared and keepInList so going back re-offers them. helpArticleFor covers
ZwiftPlayFw2 (a fw-2.x Play spoke the Ride protocol and got the Zwift Ride
article) and ZwiftClickV2RightSide; a test locks the slugs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 09:49:34 +02:00

71 lines
4.0 KiB
Dart

import 'package:bike_control/bluetooth/devices/base_device.dart';
import 'package:bike_control/bluetooth/devices/cycplus/cycplus_bc2.dart';
import 'package:bike_control/bluetooth/devices/elite/elite_square.dart';
import 'package:bike_control/bluetooth/devices/elite/elite_sterzo.dart';
import 'package:bike_control/bluetooth/devices/gamepad/gamepad_device.dart';
import 'package:bike_control/bluetooth/devices/hid/hid_device.dart';
import 'package:bike_control/bluetooth/devices/shimano/shimano_di2.dart';
import 'package:bike_control/bluetooth/devices/sram/sram_axs.dart';
import 'package:bike_control/bluetooth/devices/thinkrider/thinkrider_vs200.dart';
import 'package:bike_control/bluetooth/devices/wahoo/wahoo_kickr_bike_shift.dart';
import 'package:bike_control/bluetooth/devices/zwift/zwift_click.dart';
import 'package:bike_control/bluetooth/devices/zwift/zwift_clickv2.dart';
import 'package:bike_control/bluetooth/devices/zwift/zwift_clickv2_right_side.dart';
import 'package:bike_control/bluetooth/devices/zwift/zwift_play.dart';
import 'package:bike_control/bluetooth/devices/zwift/zwift_play_fw2.dart';
import 'package:bike_control/bluetooth/devices/zwift/zwift_ride.dart';
import 'package:bike_control/gen/l10n.dart';
import 'package:bike_control/utils/keymap/apps/supported_app.dart';
import 'package:flutter/widgets.dart';
/// A link to a bikecontrol.app how-to article for a controller + trainer app.
class HelpArticle {
const HelpArticle({required this.url, required this.label});
final String url;
final String label;
}
/// The how-to-connect article for [controller] + the active trainer [app], or
/// null when [controller] is null or has no dedicated page (so callers can hide
/// the entry). The trainer app falls back to the generic "other-training-app"
/// page when [app] is null or has no page of its own.
HelpArticle? helpArticleFor(
BuildContext context, {
required BaseDevice? controller,
required SupportedApp? app,
}) {
if (controller == null) return null;
final ctrl = _controllerArticle(controller);
if (ctrl == null) return null;
final appSlug = app?.helpSlug ?? 'other-training-app';
final appName = app?.name ?? 'your trainer app';
return HelpArticle(
url: 'https://bikecontrol.app/use-${ctrl.slug}-with-$appSlug/',
label: AppLocalizations.of(context).useControllerWithApp(ctrl.name, appName),
);
}
/// Maps a controller device to its bikecontrol.app slug + display name, or null
/// for device types without a dedicated page (e.g. gyroscope steering, a smart
/// trainer proxy). `ZwiftClickV2 extends ZwiftRide` — keep the V2 check first.
({String slug, String name})? _controllerArticle(BaseDevice device) {
if (device is ZwiftClickV2) return (slug: 'zwift-click-v2', name: 'Zwift Click V2');
if (device is ZwiftClickV2RightSide) return (slug: 'zwift-click-v2', name: 'Zwift Click V2');
if (device is ZwiftClick) return (slug: 'zwift-click', name: 'Zwift Click');
// A Play on firmware 2.x speaks the Ride protocol but is still a Play to
// the rider — must come before the ZwiftRide check it extends.
if (device is ZwiftPlayFw2) return (slug: 'zwift-play', name: 'Zwift Play');
if (device is ZwiftPlay) return (slug: 'zwift-play', name: 'Zwift Play');
if (device is ZwiftRide) return (slug: 'zwift-ride', name: 'Zwift Ride');
if (device is ShimanoDi2) return (slug: 'shimano-di2', name: 'Shimano Di2');
if (device is SramAxs) return (slug: 'sram-axs-etap', name: 'SRAM AXS');
if (device is WahooKickrBikeShift) return (slug: 'wahoo-kickr-bike-shift', name: 'Wahoo KICKR Bike Shift');
if (device is CycplusBc2) return (slug: 'cycplus-bc2-virtual-shifter', name: 'CYCPLUS BC2');
if (device is EliteSquare) return (slug: 'elite-square-smart-frame', name: 'Elite Square');
if (device is EliteSterzo) return (slug: 'elite-sterzo-smart', name: 'Elite Sterzo');
if (device is ThinkRiderVs200) return (slug: 'thinkrider-vs200', name: 'ThinkRider VS200');
if (device is GamepadDevice) return (slug: 'gamepads', name: 'Gamepad');
if (device is HidDevice) return (slug: 'keyboard-input', name: 'Keyboard');
return null;
}