mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-11-29 09:11:17 +01:00
The trainer-app picker now shows an external-link button next to every app that has an official site, opening it in the browser. Adds an officialUrl to SupportedApp with per-app overrides (Strappo, MyWhoosh, Rouvy, Zwift, TrainingPeaks Virtual, Biketerra, BikeControl, OpenBikeControl). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
124 lines
4.1 KiB
Dart
124 lines
4.1 KiB
Dart
import 'package:bike_control/utils/core.dart';
|
|
import 'package:bike_control/utils/keymap/apps/bike_control.dart';
|
|
import 'package:bike_control/utils/keymap/apps/biketerra.dart';
|
|
import 'package:bike_control/utils/keymap/apps/openbikecontrol.dart';
|
|
import 'package:bike_control/utils/keymap/apps/rouvy.dart';
|
|
import 'package:bike_control/utils/keymap/apps/strappo.dart';
|
|
import 'package:bike_control/utils/keymap/apps/training_peaks.dart';
|
|
import 'package:bike_control/utils/keymap/apps/wahoo_element.dart';
|
|
import 'package:bike_control/utils/keymap/apps/zwift.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import '../buttons.dart';
|
|
import '../keymap.dart';
|
|
import 'custom_app.dart';
|
|
import 'my_whoosh.dart';
|
|
|
|
enum AppConnectionMethod {
|
|
zwiftBle,
|
|
zwiftMdns,
|
|
rouvyMdns,
|
|
obpBle,
|
|
obpMdns,
|
|
obpDirCon,
|
|
myWhooshLink,
|
|
local,
|
|
remoteMouse,
|
|
remoteKeyboard,
|
|
di2Ble,
|
|
}
|
|
|
|
enum ConnectionSupport {
|
|
supported,
|
|
beta,
|
|
experimental,
|
|
}
|
|
|
|
/// Which Bridge (virtual shifting) connection transports a trainer app can
|
|
/// actually consume. Used by the connection-mode picker on the proxy device
|
|
/// details page to disable unsupported modes with a contextual hint.
|
|
enum TrainerConnectionType { bluetooth, wifi }
|
|
|
|
abstract class SupportedApp {
|
|
final String packageName;
|
|
final String name;
|
|
final Keymap keymap;
|
|
final List<KeyPair> additionalKeyPairs;
|
|
final bool star;
|
|
final bool officialIntegration;
|
|
|
|
const SupportedApp({
|
|
required this.name,
|
|
required this.packageName,
|
|
required this.keymap,
|
|
required this.officialIntegration,
|
|
this.additionalKeyPairs = const [],
|
|
this.star = false,
|
|
});
|
|
|
|
List<(AppConnectionMethod, ConnectionSupport)> get connections => [];
|
|
|
|
/// Optional asset path for the trainer app logo (only for officially supported apps).
|
|
String? get logoAsset => null;
|
|
|
|
/// Official website for this trainer app, surfaced as an external-link button
|
|
/// next to the app in the trainer-app chooser. Null for apps without a site
|
|
/// of their own (e.g. the generic custom app).
|
|
String? get officialUrl => null;
|
|
|
|
/// Slug for the bikecontrol.app `use-<controller>-with-<app>` how-to article.
|
|
/// Apps without a dedicated page fall back to the generic guide.
|
|
String get helpSlug => 'other-training-app';
|
|
|
|
/// Maps Zwift Click V2 actions to this app's corresponding actions.
|
|
/// E.g. for Rouvy: {InGameAction.usePowerUp: InGameAction.pause, InGameAction.select: InGameAction.kudos}
|
|
Map<InGameAction, InGameAction> get inGameActionsMapping => const {};
|
|
|
|
/// How many virtual gears this trainer app exposes in its shifter. Drives
|
|
/// [FitnessBikeDefinition.maxGear] when this app is active. Default 24
|
|
/// (Zwift's virtual shifting). Override on apps that use a different count
|
|
/// (e.g. MyWhoosh → 30).
|
|
int get virtualGearAmount => 24;
|
|
|
|
/// Default OpenBikeControl supported buttons used by the ButtonEditor
|
|
/// before (or without) a live OBP connection. Overridden by trainer-app
|
|
/// subclasses that ship a known-good list.
|
|
List<ControllerButton> get defaultObpSupportedButtons => const [];
|
|
|
|
/// Whether this app supports the given connection method.
|
|
/// Experimental methods are excluded unless the experimental setting is enabled.
|
|
bool supports(AppConnectionMethod method) {
|
|
final level = supportLevel(method);
|
|
if (level == null) return false;
|
|
if (level == ConnectionSupport.experimental && !core.settings.getShowExperimental()) return false;
|
|
return true;
|
|
}
|
|
|
|
ConnectionSupport? supportLevel(AppConnectionMethod method) {
|
|
final match = connections.where((c) => c.$1 == method);
|
|
return match.isEmpty ? null : match.first.$2;
|
|
}
|
|
|
|
bool isBeta(AppConnectionMethod method) => supportLevel(method) == ConnectionSupport.beta;
|
|
|
|
bool isExperimental(AppConnectionMethod method) => supportLevel(method) == ConnectionSupport.experimental;
|
|
|
|
static final List<SupportedApp> supportedApps = [
|
|
MyWhoosh(),
|
|
Zwift(),
|
|
TrainingPeaks(),
|
|
Biketerra(),
|
|
Rouvy(),
|
|
Strappo(),
|
|
BikeControl(),
|
|
OpenBikeControl(),
|
|
if (kDebugMode) WahooElement(),
|
|
CustomApp(),
|
|
];
|
|
|
|
@override
|
|
String toString() {
|
|
return runtimeType.toString();
|
|
}
|
|
}
|