feat(trial): block smart-trainer connect after 5-day trial expires

This commit is contained in:
Jonas Bark
2026-04-24 08:29:13 +02:00
parent 942a3264d2
commit c51e8c7d03
4 changed files with 47 additions and 0 deletions

View File

@@ -334,7 +334,39 @@ class ProxyDevice extends BluetoothDevice {
}
}
/// True when the user's 5-day trial has ended and they haven't upgraded.
/// Blocks any smart-trainer connect attempt — BLE upstream, transporter
/// setup, advertising, all of it. Pro and purchased-base-version users
/// bypass this gate (`IAPManager.isTrialExpired` already returns false for
/// them).
bool get _isSubscriptionTrialExpired => IAPManager.instance.isTrialExpired;
void _announceSubscriptionTrialExpired() {
final title = AppLocalizations.current.trialExpiredSmartTrainerBlockedTitle;
final body = AppLocalizations.current.trialExpiredSmartTrainerBlockedBody;
core.connection.signalNotification(
AlertNotification(LogLevel.LOGLEVEL_WARNING, '$title — $body'),
);
core.flutterLocalNotificationsPlugin.show(
1341,
title,
body,
const NotificationDetails(
android: AndroidNotificationDetails('SubscriptionTrial', 'Subscription Trial Status'),
iOS: DarwinNotificationDetails(presentAlert: true, presentSound: true),
),
);
}
Future<void> startProxy() async {
if (_isSubscriptionTrialExpired) {
_announceSubscriptionTrialExpired();
// Clear auto-connect so the next scan cycle doesn't keep re-firing this
// gate. The user re-enables auto-connect implicitly when they tap
// Connect after purchasing.
await core.settings.setAutoConnect(trainerKey, false);
return;
}
isStarting.value = true;
try {
await super.connect();

View File

@@ -521,6 +521,8 @@
},
"trialDaysRemaining": "{trialDaysRemaining} days remaining",
"trialExpired": "Trial expired. Commands limited to {dailyCommandLimit} per day.",
"trialExpiredSmartTrainerBlockedTitle": "5-day trial expired",
"trialExpiredSmartTrainerBlockedBody": "Your 5-day trial is over. Upgrade to Pro or buy the Base version to connect to your smart trainer.",
"trialPeriodActive": "Trial Period Active - {trialDaysRemaining} days remaining",
"trialPeriodDescription": "Enjoy unlimited commands during your trial period. After the trial, commands will be limited to {dailyCommandLimit} per day.",
"troubleshootingGuide": "Questions & Answers",

View File

@@ -4,6 +4,8 @@ import 'package:bike_control/bluetooth/devices/base_device.dart';
import 'package:bike_control/pages/proxy_device_details.dart';
import 'package:bike_control/utils/core.dart';
import 'package:bike_control/utils/i18n_extension.dart';
import 'package:bike_control/utils/iap/iap_manager.dart';
import 'package:bike_control/widgets/go_pro_dialog.dart';
import 'package:dartx/dartx.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
@@ -52,6 +54,10 @@ class _DevicePageState extends State<ProxyPage> {
child: Button.ghost(
onPressed: () async {
if (!device.emulator.isStarted.value && !device.isStarting.value) {
if (IAPManager.instance.isTrialExpired) {
await showGoProDialog(context);
return;
}
final savedMode = core.settings.getRetrofitMode(device.trainerKey);
device.emulator.setRetrofitMode(savedMode);
await core.settings.setAutoConnect(device.trainerKey, true);
@@ -59,6 +65,7 @@ class _DevicePageState extends State<ProxyPage> {
// renders a "Connecting…" state via device.isStarting.
unawaited(device.startProxy().catchError((_) {}));
}
if (!context.mounted) return;
await context.push(ProxyDeviceDetailsPage(device: device));
widget.onUpdate();
},

View File

@@ -3,9 +3,11 @@ import 'dart:io';
import 'package:bike_control/bluetooth/devices/proxy/proxy_device.dart';
import 'package:bike_control/gen/l10n.dart';
import 'package:bike_control/utils/core.dart';
import 'package:bike_control/utils/iap/iap_manager.dart';
import 'package:bike_control/utils/keymap/apps/supported_app.dart';
import 'package:bike_control/utils/requirements/multi.dart';
import 'package:bike_control/utils/requirements/platform.dart';
import 'package:bike_control/widgets/go_pro_dialog.dart';
import 'package:bike_control/widgets/ui/connection_method.dart' show openPermissionSheet;
import 'package:bike_control/widgets/ui/loading_widget.dart';
import 'package:bike_control/widgets/ui/small_progress_indicator.dart';
@@ -209,6 +211,10 @@ class _ConnectionCardState extends State<ConnectionCard> {
),
LoadingWidget(
futureCallback: () async {
if (IAPManager.instance.isTrialExpired) {
await showGoProDialog(context);
return;
}
if (_pendingMode == RetrofitMode.bluetooth) {
final ok = await _ensureBluetoothAdvertisePermissions();
if (!ok) return;