From c51e8c7d03ffd8f7934c8e514b04131af8b92aa9 Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Fri, 24 Apr 2026 08:29:13 +0200 Subject: [PATCH] feat(trial): block smart-trainer connect after 5-day trial expires --- lib/bluetooth/devices/proxy/proxy_device.dart | 32 +++++++++++++++++++ lib/i10n/intl_en.arb | 2 ++ lib/pages/proxy.dart | 7 ++++ .../proxy_device_details/connection_card.dart | 6 ++++ 4 files changed, 47 insertions(+) diff --git a/lib/bluetooth/devices/proxy/proxy_device.dart b/lib/bluetooth/devices/proxy/proxy_device.dart index 3daa6b09..5002d600 100644 --- a/lib/bluetooth/devices/proxy/proxy_device.dart +++ b/lib/bluetooth/devices/proxy/proxy_device.dart @@ -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 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(); diff --git a/lib/i10n/intl_en.arb b/lib/i10n/intl_en.arb index 3f10b13b..2f5a9d8d 100644 --- a/lib/i10n/intl_en.arb +++ b/lib/i10n/intl_en.arb @@ -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", diff --git a/lib/pages/proxy.dart b/lib/pages/proxy.dart index c1ff4cb1..e1560e65 100644 --- a/lib/pages/proxy.dart +++ b/lib/pages/proxy.dart @@ -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 { 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 { // renders a "Connecting…" state via device.isStarting. unawaited(device.startProxy().catchError((_) {})); } + if (!context.mounted) return; await context.push(ProxyDeviceDetailsPage(device: device)); widget.onUpdate(); }, diff --git a/lib/pages/proxy_device_details/connection_card.dart b/lib/pages/proxy_device_details/connection_card.dart index 3a3aa283..906699b4 100644 --- a/lib/pages/proxy_device_details/connection_card.dart +++ b/lib/pages/proxy_device_details/connection_card.dart @@ -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 { ), LoadingWidget( futureCallback: () async { + if (IAPManager.instance.isTrialExpired) { + await showGoProDialog(context); + return; + } if (_pendingMode == RetrofitMode.bluetooth) { final ok = await _ensureBluetoothAdvertisePermissions(); if (!ok) return;