diff --git a/lib/i10n/intl_de.arb b/lib/i10n/intl_de.arb index cff07457..b5a53345 100644 --- a/lib/i10n/intl_de.arb +++ b/lib/i10n/intl_de.arb @@ -3077,5 +3077,11 @@ "paywallNoSubscriptionQuestion": "Keine Lust auf Abos?", "paywallProForeverAction": "Pro für immer – {price}", "planProForever": "Für immer", - "planProForeverLine": "Einmal gekauft – kein Abo" + "planProForeverLine": "Einmal gekauft – kein Abo", + "whatsNewBannerTitle": "BikeControl {version} ist da", + "whatsNewBannerBody": "Sieh dir an, was neu ist", + "whatsNewBlogLink": "Mehr im BikeControl-Blog", + "whatsNewHelpTitle": "BikeControl braucht deine Hilfe", + "whatsNewHelpBody": "BikeControl wird von einer einzigen Person entwickelt, nicht von einer großen Firma. Eine kurze Bewertung im Store hilft anderen, die App zu finden, und hält sie am Leben.", + "whatsNewRateAction": "BikeControl bewerten" } diff --git a/lib/i10n/intl_en.arb b/lib/i10n/intl_en.arb index 571ee9d7..bf2c8997 100644 --- a/lib/i10n/intl_en.arb +++ b/lib/i10n/intl_en.arb @@ -3523,5 +3523,18 @@ "paywallNoSubscriptionQuestion": "Don't like subscriptions?", "paywallProForeverAction": "Get Pro forever – {price}", "planProForever": "Forever", - "planProForeverLine": "Bought once – no subscription" + "planProForeverLine": "Bought once – no subscription", + "whatsNewBannerTitle": "BikeControl {version} is here", + "@whatsNewBannerTitle": { + "placeholders": { + "version": { + "type": "String" + } + } + }, + "whatsNewBannerBody": "See what's new", + "whatsNewBlogLink": "More on the BikeControl blog", + "whatsNewHelpTitle": "BikeControl needs your help", + "whatsNewHelpBody": "BikeControl is made by one person, not a big company. A short rating in the store helps other riders find it and keeps it going.", + "whatsNewRateAction": "Rate BikeControl" } diff --git a/lib/i10n/intl_es.arb b/lib/i10n/intl_es.arb index fa3f0443..9bb25750 100644 --- a/lib/i10n/intl_es.arb +++ b/lib/i10n/intl_es.arb @@ -3077,5 +3077,11 @@ "paywallNoSubscriptionQuestion": "¿No te gustan las suscripciones?", "paywallProForeverAction": "Pro para siempre – {price}", "planProForever": "Para siempre", - "planProForeverLine": "Pago único – sin suscripción" + "planProForeverLine": "Pago único – sin suscripción", + "whatsNewBannerTitle": "Ya está aquí BikeControl {version}", + "whatsNewBannerBody": "Mira las novedades", + "whatsNewBlogLink": "Más en el blog de BikeControl", + "whatsNewHelpTitle": "BikeControl necesita tu ayuda", + "whatsNewHelpBody": "BikeControl lo hace una sola persona, no una gran empresa. Una valoración rápida en la tienda ayuda a otros ciclistas a encontrarla y la mantiene viva.", + "whatsNewRateAction": "Valorar BikeControl" } diff --git a/lib/i10n/intl_fr.arb b/lib/i10n/intl_fr.arb index 9e2b911e..f578e144 100644 --- a/lib/i10n/intl_fr.arb +++ b/lib/i10n/intl_fr.arb @@ -3077,5 +3077,11 @@ "paywallNoSubscriptionQuestion": "Pas fan des abonnements ?", "paywallProForeverAction": "Pro pour toujours – {price}", "planProForever": "Pour toujours", - "planProForeverLine": "Achat unique – sans abonnement" + "planProForeverLine": "Achat unique – sans abonnement", + "whatsNewBannerTitle": "BikeControl {version} est arrivé", + "whatsNewBannerBody": "Découvrir les nouveautés", + "whatsNewBlogLink": "Plus sur le blog BikeControl", + "whatsNewHelpTitle": "BikeControl a besoin de toi", + "whatsNewHelpBody": "BikeControl est développé par une seule personne, pas par une grande entreprise. Une petite note dans le store aide d'autres cyclistes à le trouver et le fait vivre.", + "whatsNewRateAction": "Noter BikeControl" } diff --git a/lib/i10n/intl_it.arb b/lib/i10n/intl_it.arb index 1901b2d6..f54a81c6 100644 --- a/lib/i10n/intl_it.arb +++ b/lib/i10n/intl_it.arb @@ -3077,5 +3077,11 @@ "paywallNoSubscriptionQuestion": "Non ti piacciono gli abbonamenti?", "paywallProForeverAction": "Pro per sempre – {price}", "planProForever": "Per sempre", - "planProForeverLine": "Acquisto unico – nessun abbonamento" + "planProForeverLine": "Acquisto unico – nessun abbonamento", + "whatsNewBannerTitle": "È arrivato BikeControl {version}", + "whatsNewBannerBody": "Scopri le novità", + "whatsNewBlogLink": "Altro sul blog di BikeControl", + "whatsNewHelpTitle": "BikeControl ha bisogno del tuo aiuto", + "whatsNewHelpBody": "BikeControl è sviluppato da una sola persona, non da una grande azienda. Una breve valutazione nello store aiuta altri ciclisti a trovarlo e lo mantiene vivo.", + "whatsNewRateAction": "Valuta BikeControl" } diff --git a/lib/i10n/intl_pl.arb b/lib/i10n/intl_pl.arb index f1590b47..44082ea8 100644 --- a/lib/i10n/intl_pl.arb +++ b/lib/i10n/intl_pl.arb @@ -3077,5 +3077,11 @@ "paywallNoSubscriptionQuestion": "Nie lubisz subskrypcji?", "paywallProForeverAction": "Pro na zawsze – {price}", "planProForever": "Na zawsze", - "planProForeverLine": "Jednorazowy zakup – bez subskrypcji" + "planProForeverLine": "Jednorazowy zakup – bez subskrypcji", + "whatsNewBannerTitle": "BikeControl {version} już jest", + "whatsNewBannerBody": "Zobacz, co nowego", + "whatsNewBlogLink": "Więcej na blogu BikeControl", + "whatsNewHelpTitle": "BikeControl potrzebuje twojej pomocy", + "whatsNewHelpBody": "BikeControl tworzy jedna osoba, a nie duża firma. Krótka ocena w sklepie pomaga innym kolarzom ją znaleźć i pozwala jej dalej się rozwijać.", + "whatsNewRateAction": "Oceń BikeControl" } diff --git a/lib/i10n/intl_zh.arb b/lib/i10n/intl_zh.arb index 336a973c..f620355c 100644 --- a/lib/i10n/intl_zh.arb +++ b/lib/i10n/intl_zh.arb @@ -4259,5 +4259,11 @@ "paywallNoSubscriptionQuestion": "不喜欢订阅?", "paywallProForeverAction": "永久 Pro – {price}", "planProForever": "永久", - "planProForeverLine": "一次购买,无需订阅" + "planProForeverLine": "一次购买,无需订阅", + "whatsNewBannerTitle": "BikeControl {version} 来了", + "whatsNewBannerBody": "看看有什么新内容", + "whatsNewBlogLink": "在 BikeControl 博客了解更多", + "whatsNewHelpTitle": "BikeControl 需要你的帮助", + "whatsNewHelpBody": "BikeControl 由一个人开发,而不是一家大公司。在应用商店留下简短评分,能帮助其他骑手找到它,也让它持续发展。", + "whatsNewRateAction": "为 BikeControl 评分" } diff --git a/lib/pages/navigation.dart b/lib/pages/navigation.dart index 020fcb58..ee49e28b 100644 --- a/lib/pages/navigation.dart +++ b/lib/pages/navigation.dart @@ -22,7 +22,7 @@ import 'package:version/version.dart'; import '../pages/onboarding/onboarding_page.dart'; import '../pages/onboarding/onboarding_trigger.dart'; import '../utils/settings/settings.dart'; -import '../widgets/changelog_dialog.dart'; +import 'package:bike_control/widgets/changelog/whats_new.dart'; class Navigation extends StatefulWidget { const Navigation({super.key, this.initialSection = AppSection.ride}); @@ -182,9 +182,7 @@ class _NavigationState extends State { recordError(e, s, context: 'onboarding trigger'); } - if (mounted) { - await ChangelogDialog.showIfNeeded(context, currentVersion, lastSeenVersion); - } + await WhatsNew.checkAtLaunch(currentVersion, lastSeenVersion); // Update last seen version await core.settings.setLastSeenVersion(currentVersion); diff --git a/lib/pages/shell/app_shell.dart b/lib/pages/shell/app_shell.dart index 21b3b621..fca7ee61 100644 --- a/lib/pages/shell/app_shell.dart +++ b/lib/pages/shell/app_shell.dart @@ -27,6 +27,7 @@ import 'package:bike_control/widgets/ui/pro_badge.dart'; import 'package:bike_control/widgets/ui/toast.dart'; import 'package:bike_control/widgets/ui/type_scale.dart'; import 'package:flutter/foundation.dart' show ValueListenable, defaultTargetPlatform; +import 'package:bike_control/widgets/changelog/whats_new.dart'; import 'package:bike_control/pages/activity/rides_view.dart' show RidesMenuButton; import 'package:flutter/rendering.dart' show @@ -551,7 +552,6 @@ class ShellTopBar extends StatelessWidget { ], ); final scrolled = this.scrolled; - if (scrolled == null && !compact) return bar; return Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, @@ -560,6 +560,8 @@ class ShellTopBar extends StatelessWidget { // A waiting update on the phone: a strip under the bar, which has no // room for a labelled button beside the title. if (compact) const AppUpdateButton(banner: true), + // An update's notes, unread: until opened or dismissed. + WhatsNewBanner(horizontalMargin: phone ? 16 : 24), if (scrolled != null) ValueListenableBuilder( valueListenable: scrolled, diff --git a/lib/utils/settings/settings.dart b/lib/utils/settings/settings.dart index ec9e2e83..dd2d7d3b 100644 --- a/lib/utils/settings/settings.dart +++ b/lib/utils/settings/settings.dart @@ -550,6 +550,24 @@ class Settings { await prefs.setString('last_seen_version', version); } + /// The update whose "What's new" banner is still up: the version updated + /// to and the one updated from. Null once the rider opened or dismissed it. + (String version, String since)? getWhatsNewPending() { + final version = prefs.getString('whats_new_version'); + final since = prefs.getString('whats_new_since'); + return version == null || since == null ? null : (version, since); + } + + Future setWhatsNewPending((String version, String since)? pending) async { + if (pending == null) { + await prefs.remove('whats_new_version'); + await prefs.remove('whats_new_since'); + } else { + await prefs.setString('whats_new_version', pending.$1); + await prefs.setString('whats_new_since', pending.$2); + } + } + bool getVibrationEnabled() { return prefs.getBool('vibration_enabled') ?? true; } diff --git a/lib/widgets/changelog/whats_new.dart b/lib/widgets/changelog/whats_new.dart new file mode 100644 index 00000000..738ae693 --- /dev/null +++ b/lib/widgets/changelog/whats_new.dart @@ -0,0 +1,364 @@ +import 'dart:io' show Platform; + +import 'package:bike_control/main.dart' show recordError, screenshotMode; +import 'package:bike_control/models/changelog.dart'; +import 'package:bike_control/pages/changelog_page.dart'; +import 'package:bike_control/utils/core.dart'; +import 'package:bike_control/utils/i18n_extension.dart'; +import 'package:bike_control/utils/rate_app.dart'; +import 'package:bike_control/widgets/changelog/changelog_view.dart'; +import 'package:bike_control/widgets/ui/bk_grouped_section.dart' show BkGroupedDivider; +import 'package:bike_control/widgets/ui/bk_page_column.dart'; +import 'package:bike_control/widgets/ui/bk_page_header.dart'; +import 'package:bike_control/widgets/ui/bk_pill_button.dart'; +import 'package:bike_control/widgets/ui/colors.dart'; +import 'package:bike_control/widgets/ui/type_scale.dart'; +import 'package:flutter/foundation.dart' show kIsWeb, visibleForTesting; +import 'package:shadcn_flutter/shadcn_flutter.dart'; +import 'package:url_launcher/url_launcher_string.dart'; + +const whatsNewBlogUrl = 'https://bikecontrol.app/blog'; + +/// "What's new" after an update: a banner at the top of the app instead of a +/// dialog riders click away before reading. It stays until the rider opens it +/// or dismisses it, across launches, and opens [WhatsNewPage]. +abstract final class WhatsNew { + /// The update the banner announces (version, updated from); null hides it. + static final ValueNotifier<(String version, String since)?> pending = ValueNotifier(null); + + /// At launch, before the last-seen version is overwritten. Not on a fresh + /// install (onboarding greets that rider), not when the changelog has + /// nothing newer than [lastSeenVersion], never in store renders. + static Future checkAtLaunch(String currentVersion, String? lastSeenVersion) async { + if (screenshotMode) return; + try { + if (lastSeenVersion != null && lastSeenVersion != currentVersion) { + final since = releasesSince(await ChangelogSource.bundled(), lastSeenVersion); + if (since.isNotEmpty) { + // Two updates in a row without opening it: keep the older "since", + // so the page still shows everything the rider missed. + final previous = core.settings.getWhatsNewPending(); + final from = previous != null && previous.$1 == lastSeenVersion ? previous.$2 : lastSeenVersion; + await core.settings.setWhatsNewPending((currentVersion, from)); + } + } + final stored = core.settings.getWhatsNewPending(); + if (stored != null && stored.$1 == currentVersion) { + pending.value = stored; + } else if (stored != null) { + await core.settings.setWhatsNewPending(null); + } + } catch (e, s) { + recordError(e, s, context: 'WhatsNew.checkAtLaunch'); + } + } + + /// Opened or closed: the banner is done for this update. + static Future dismiss() async { + pending.value = null; + try { + await core.settings.setWhatsNewPending(null); + } catch (e, s) { + recordError(e, s, context: 'WhatsNew.dismiss'); + } + } + + static Future open(BuildContext context) async { + final update = pending.value; + if (update == null) return; + final navigator = Navigator.of(context, rootNavigator: true); + await dismiss(); + await navigator.push( + MaterialPageRoute( + fullscreenDialog: true, + settings: const RouteSettings(name: '/whats-new'), + builder: (_) => WhatsNewPage(currentVersion: update.$1, sinceVersion: update.$2), + ), + ); + } +} + +/// The strip under the top bar while an update's notes are unread. +class WhatsNewBanner extends StatelessWidget { + const WhatsNewBanner({super.key, this.horizontalMargin = 16}); + + final double horizontalMargin; + + @override + Widget build(BuildContext context) { + return ValueListenableBuilder( + valueListenable: WhatsNew.pending, + builder: (context, update, _) { + if (update == null) return const SizedBox.shrink(); + final cs = Theme.of(context).colorScheme; + final l = context.i18n; + final accent = cs.primary; + return Padding( + key: const ValueKey('whats-new-banner'), + padding: EdgeInsets.fromLTRB(horizontalMargin, 4, horizontalMargin, 8), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(14), + color: cs.card, + border: Border.all(color: accent.withValues(alpha: 0.45)), + boxShadow: bkCardShadow(context), + ), + clipBehavior: Clip.antiAlias, + child: Row( + children: [ + Expanded( + child: Button.ghost( + key: const ValueKey('whats-new-banner-open'), + style: const ButtonStyle.ghost().withPadding(padding: const EdgeInsets.fromLTRB(12, 10, 8, 10)), + alignment: AlignmentDirectional.centerStart, + onPressed: () => WhatsNew.open(context), + child: Row( + children: [ + Container( + width: 34, + height: 34, + decoration: BoxDecoration( + color: accent.withValues(alpha: 0.14), + borderRadius: BorderRadius.circular(10), + ), + child: Icon(LucideIcons.sparkles, size: 18, color: bkAccentText(context)), + ), + const Gap(12), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + l.whatsNewBannerTitle(update.$1), + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: context.typography.small.copyWith(fontWeight: FontWeight.w700), + ), + Text( + l.whatsNewBannerBody, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: context.typography.xSmall.copyWith( + color: bkAccentText(context), + fontWeight: FontWeight.w600, + ), + ), + ], + ), + ), + Icon(LucideIcons.chevronRight, size: 18, color: cs.mutedForeground), + ], + ), + ), + ), + IconButton.ghost( + key: const ValueKey('whats-new-banner-dismiss'), + icon: Semantics( + label: l.a11yDismiss, + child: Icon(LucideIcons.x, size: 18, color: cs.mutedForeground), + ), + onPressed: WhatsNew.dismiss, + ), + const Gap(4), + ], + ), + ), + ); + }, + ); + } +} + +/// The update's notes, full screen: the releases since the version the rider +/// came from, the blog for the longer story, and a plea for a store rating. +class WhatsNewPage extends StatefulWidget { + const WhatsNewPage({super.key, required this.currentVersion, required this.sinceVersion, this.releases}); + + final String currentVersion; + final String sinceVersion; + + /// Skips loading the bundled changelog (tests, renders). + final List? releases; + + /// At most this many releases: someone back after a long time gets the + /// latest few here and the rest under "All versions". + static const int maxReleases = 3; + + /// Whether this platform has a store to rate in. + @visibleForTesting + static bool Function() canRate = () => !kIsWeb && !Platform.isLinux; + + @override + State createState() => _WhatsNewPageState(); +} + +class _WhatsNewPageState extends State { + List? _releases; + + @override + void initState() { + super.initState(); + _releases = widget.releases; + if (_releases == null) _load(); + } + + Future _load() async { + try { + final releases = releasesSince(await ChangelogSource.bundled(), widget.sinceVersion); + if (mounted) setState(() => _releases = releases); + } catch (e, s) { + recordError(e, s, context: 'WhatsNewPage.load'); + if (mounted) setState(() => _releases = const []); + } + } + + Future _rate() async { + try { + await requestAppRating(); + } catch (e, s) { + recordError(e, s, context: 'whats new rate'); + } + } + + @override + Widget build(BuildContext context) { + final l = context.i18n; + final releases = _releases?.take(WhatsNewPage.maxReleases).toList(); + return Scaffold( + headers: [BkPageHeader(title: l.whatsNew, columnWidth: changelogMaxWidth)], + child: SingleChildScrollView( + padding: const EdgeInsets.fromLTRB(16, 20, 16, 40), + child: BkPageColumn( + maxWidth: changelogMaxWidth, + child: releases == null + ? const SizedBox(height: 200) + : Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + for (final (i, r) in releases.indexed) ...[ + if (i > 0) + const Padding( + padding: EdgeInsets.symmetric(vertical: 28), + child: BkGroupedDivider(indent: 0), + ), + ChangelogReleaseFull( + key: ValueKey('whats-new-${r.version}'), + release: r, + isCurrent: r.version == widget.currentVersion, + ), + ], + const Gap(28), + _LinkRow( + key: const ValueKey('whats-new-blog'), + icon: LucideIcons.newspaper, + label: l.whatsNewBlogLink, + external: true, + onPressed: () => launchUrlString(whatsNewBlogUrl, mode: LaunchMode.externalApplication), + ), + _LinkRow( + key: const ValueKey('whats-new-all'), + icon: LucideIcons.history, + label: l.changelogAllVersions, + onPressed: () => Navigator.of( + context, + ).pushReplacement(MaterialPageRoute(builder: (_) => const ChangelogPage())), + ), + if (WhatsNewPage.canRate()) ...[ + const Gap(28), + _HelpCard(onRate: _rate), + ], + ], + ), + ), + ), + ); + } +} + +class _LinkRow extends StatelessWidget { + const _LinkRow({ + super.key, + required this.icon, + required this.label, + required this.onPressed, + this.external = false, + }); + + final IconData icon; + final bool external; + final String label; + final VoidCallback onPressed; + + @override + Widget build(BuildContext context) { + final accent = bkAccentText(context); + return Button.ghost( + style: const ButtonStyle.ghost().withPadding(padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 10)), + alignment: AlignmentDirectional.centerStart, + onPressed: onPressed, + leading: Icon(icon, size: 18, color: accent), + trailing: Icon(external ? LucideIcons.arrowUpRight : LucideIcons.chevronRight, size: 16, color: accent), + child: Text( + label, + style: context.typography.base.copyWith(color: accent, fontWeight: FontWeight.w600), + ), + ); + } +} + +/// "BikeControl needs your help": one person builds it, ratings bring riders. +class _HelpCard extends StatelessWidget { + const _HelpCard({required this.onRate}); + + final VoidCallback onRate; + + @override + Widget build(BuildContext context) { + final cs = Theme.of(context).colorScheme; + final l = context.i18n; + return Container( + key: const ValueKey('whats-new-help'), + padding: const EdgeInsets.fromLTRB(20, 20, 20, 20), + decoration: BoxDecoration( + color: cs.card, + borderRadius: BorderRadius.circular(20), + border: Border.all(color: cs.primary.withValues(alpha: 0.45)), + boxShadow: bkCardShadow(context), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Row( + children: [ + for (var i = 0; i < 5; i++) + Padding( + padding: const EdgeInsets.only(right: 4), + child: Icon(RadixIcons.starFilled, size: 20, color: const Color(0xFFF5B301)), + ), + ], + ), + const Gap(14), + Semantics( + header: true, + child: Text( + l.whatsNewHelpTitle, + style: context.typography.large.copyWith(fontWeight: FontWeight.w700, letterSpacing: -0.2), + ), + ), + const Gap(6), + Text( + l.whatsNewHelpBody, + style: context.typography.small.copyWith(color: cs.mutedForeground, height: 1.45), + ), + const Gap(18), + BkPillButton( + key: const ValueKey('whats-new-rate'), + onPressed: onRate, + child: Text(l.whatsNewRateAction), + ), + ], + ), + ); + } +} diff --git a/lib/widgets/changelog_dialog.dart b/lib/widgets/changelog_dialog.dart deleted file mode 100644 index fdbabe9d..00000000 --- a/lib/widgets/changelog_dialog.dart +++ /dev/null @@ -1,161 +0,0 @@ -import 'dart:async'; - -import 'package:bike_control/main.dart'; -import 'package:bike_control/models/changelog.dart'; -import 'package:bike_control/pages/changelog_page.dart'; -import 'package:bike_control/utils/i18n_extension.dart'; -import 'package:bike_control/widgets/changelog/changelog_view.dart'; -import 'package:bike_control/widgets/ui/bk_grouped_section.dart' show BkGroupedDivider; -import 'package:bike_control/widgets/ui/bk_pill_button.dart'; -import 'package:bike_control/widgets/ui/colors.dart' show bkAccentText; -import 'package:bike_control/widgets/ui/type_scale.dart'; -import 'package:shadcn_flutter/shadcn_flutter.dart'; - -/// "What's new" after an update: only the releases since the version the -/// rider last opened, each in full, and one clear way out. "All versions" -/// opens the full changelog. -class ChangelogDialog extends StatelessWidget { - const ChangelogDialog({super.key, required this.releases, this.currentVersion}); - - /// Newest first. - final List releases; - final String? currentVersion; - - /// At most this many releases: someone back after a long time gets the - /// latest few here and the rest one tap away. - static const int maxReleases = 3; - - static final BorderRadius _radius = BorderRadius.circular(20); - - @override - Widget build(BuildContext context) { - final cs = Theme.of(context).colorScheme; - final l = context.i18n; - final size = MediaQuery.sizeOf(context); - final shown = releases.take(maxReleases).toList(); - return Center( - child: Padding( - padding: const EdgeInsets.all(16), - child: ConstrainedBox( - constraints: BoxConstraints(maxWidth: changelogMaxWidth, maxHeight: size.height * 0.86), - // shadcn's dialog route has a transparent barrier; the backdrop dims - // the page, the outline and shadow lift the card off it. - child: ModalBackdrop( - borderRadius: _radius, - child: Container( - key: const ValueKey('whats-new-card'), - decoration: BoxDecoration( - color: cs.card, - borderRadius: _radius, - border: Border.all(color: cs.border), - boxShadow: const [ - BoxShadow(color: Color(0x40000000), offset: Offset(0, 16), blurRadius: 40, spreadRadius: -8), - ], - ), - clipBehavior: Clip.antiAlias, - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Padding( - padding: const EdgeInsets.fromLTRB(24, 24, 24, 4), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - spacing: 4, - children: [ - Semantics( - header: true, - child: Text(l.whatsNew, style: BkDisplay.title(context)), - ), - Text( - l.changelogWhatsNewSince, - style: context.typography.small.copyWith(color: cs.mutedForeground), - ), - ], - ), - ), - Flexible( - child: SingleChildScrollView( - padding: const EdgeInsets.fromLTRB(24, 20, 24, 20), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - for (final (i, r) in shown.indexed) ...[ - if (i > 0) - const Padding( - padding: EdgeInsets.symmetric(vertical: 28), - child: BkGroupedDivider(indent: 0), - ), - ChangelogReleaseFull( - key: ValueKey('whats-new-${r.version}'), - release: r, - isCurrent: currentVersion != null && r.version == currentVersion, - ), - ], - ], - ), - ), - ), - const BkGroupedDivider(indent: 0), - Padding( - padding: const EdgeInsets.fromLTRB(24, 14, 24, 20), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - spacing: 4, - children: [ - BkPillButton( - key: const ValueKey('whats-new-close'), - onPressed: () => Navigator.of(context).pop(), - child: Text(l.gotIt), - ), - Button.ghost( - key: const ValueKey('whats-new-all'), - alignment: Alignment.center, - onPressed: () { - final navigator = Navigator.of(context); - navigator.pop(); - navigator.push(MaterialPageRoute(builder: (_) => const ChangelogPage())); - }, - child: Text( - l.changelogAllVersions, - style: context.typography.small.copyWith( - color: bkAccentText(context), - fontWeight: FontWeight.w600, - ), - ), - ), - ], - ), - ), - ], - ), - ), - ), - ), - ), - ); - } - - /// After an update, the releases since [lastSeenVersion]. Not on a fresh - /// install (nothing was seen before — onboarding greets that rider), not - /// when nothing newer is in the changelog, and never in store renders. - static Future showIfNeeded(BuildContext context, String currentVersion, String? lastSeenVersion) async { - if (lastSeenVersion == null || lastSeenVersion == currentVersion || screenshotMode) return; - try { - final releases = await ChangelogSource.bundled(); - final since = releasesSince(releases, lastSeenVersion); - if (since.isEmpty || !context.mounted) return; - // Not awaited: the version counts as seen once the dialog is up. - unawaited( - showDialog( - context: context, - useRootNavigator: true, - routeSettings: const RouteSettings(name: '/changelog'), - builder: (context) => ChangelogDialog(releases: since, currentVersion: currentVersion), - ), - ); - } catch (e, s) { - recordError(e, s, context: 'ChangelogDialog.showIfNeeded'); - } - } -} diff --git a/scripts/get_latest_changelog.sh b/scripts/get_latest_changelog.sh index cf8d08a1..767d4527 100755 --- a/scripts/get_latest_changelog.sh +++ b/scripts/get_latest_changelog.sh @@ -13,4 +13,4 @@ if [ ! -f "$CHANGELOG_FILE" ]; then fi # Extract the first changelog entry (between first ### and second ###) -awk '/^### / {if (count++) exit} count' "$CHANGELOG_FILE" | tail -n +2 | sed 's/^- /• /' +awk '/^### / {if (count++) exit} count' "$CHANGELOG_FILE" | tail -n +2 | sed -e 's/^- /• /' -e 's/\*\*//g' diff --git a/test/pages/changelog/changelog_page_test.dart b/test/pages/changelog/changelog_page_test.dart index dace3e9b..668dbb60 100644 --- a/test/pages/changelog/changelog_page_test.dart +++ b/test/pages/changelog/changelog_page_test.dart @@ -4,7 +4,8 @@ import 'package:bike_control/gen/l10n.dart'; import 'package:bike_control/main.dart' show OtherLocalizationsDelegate, screenshotMode; import 'package:bike_control/pages/changelog_page.dart'; -import 'package:bike_control/widgets/changelog_dialog.dart'; +import 'package:bike_control/utils/core.dart'; +import 'package:bike_control/widgets/changelog/whats_new.dart'; import 'package:bike_control/widgets/ui/app_theme.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:shadcn_flutter/shadcn_flutter.dart'; @@ -113,56 +114,99 @@ Future main() async { expect(find.textContaining('Remote pairing', findRichText: true), findsNothing); }); - testWidgets('after an update, only the releases since the last one seen, and Got it closes', (tester) async { - screenshotMode = false; - addTearDown(() => screenshotMode = true); - tester.view.physicalSize = const Size(390, 844); - tester.view.devicePixelRatio = 1; - addTearDown(tester.view.reset); - await tester.pumpWidget( - app( - Builder( - builder: (context) => Scaffold( - child: Button.primary( - onPressed: () => ChangelogDialog.showIfNeeded(context, '7.0.0', '4.7.0'), - child: const Text('open'), + group('What\'s new after an update', () { + setUp(() async { + screenshotMode = false; + WhatsNew.pending.value = null; + await core.settings.setWhatsNewPending(null); + }); + tearDown(() { + screenshotMode = true; + WhatsNew.pending.value = null; + WhatsNewPage.canRate = () => true; + }); + + Future pumpBanner(WidgetTester tester) async { + tester.view.physicalSize = const Size(390, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget( + app( + const Scaffold( + child: Column( + children: [ + WhatsNewBanner(), + Expanded(child: SizedBox()), + ], ), ), ), - ), - ); - await tester.tap(find.text('open')); - await tester.pumpAndSettle(); + ); + await tester.pump(); + } - expect(find.text(l.whatsNew), findsOneWidget); - expect(find.byKey(const ValueKey('whats-new-7.0.0')), findsOneWidget); - expect(find.byKey(const ValueKey('whats-new-5.5.0')), findsOneWidget); - expect(find.byKey(const ValueKey('whats-new-4.7.0')), findsNothing); + testWidgets('a banner, not a dialog; it opens the releases since the last one seen full screen', (tester) async { + WhatsNewPage.canRate = () => true; + await WhatsNew.checkAtLaunch('7.0.0', '4.7.0'); + await pumpBanner(tester); - // shadcn's dialog route has a transparent barrier: without a backdrop and - // an outline the card sat flat on the page it covers. - expect(find.descendant(of: find.byType(ChangelogDialog), matching: find.byType(ModalBackdrop)), findsOneWidget); - final card = tester.widget( - find.descendant(of: find.byType(ChangelogDialog), matching: find.byKey(const ValueKey('whats-new-card'))), - ); - final decoration = card.decoration! as BoxDecoration; - expect(decoration.border, isNotNull); - expect(decoration.boxShadow, isNotEmpty); + expect(find.byType(WhatsNewPage), findsNothing); + expect(find.text(l.whatsNewBannerTitle('7.0.0')), findsOneWidget); - await tester.tap(find.byKey(const ValueKey('whats-new-close'))); - await tester.pumpAndSettle(); - expect(find.text(l.whatsNew), findsNothing); - }); + await tester.tap(find.byKey(const ValueKey('whats-new-banner-open'))); + await tester.pumpAndSettle(); - testWidgets('nothing after a fresh install or without a change since', (tester) async { - screenshotMode = false; - addTearDown(() => screenshotMode = true); - late BuildContext ctx; - await tester.pumpWidget(app(Builder(builder: (c) => const SizedBox()))); - ctx = tester.element(find.byType(SizedBox).first); - await ChangelogDialog.showIfNeeded(ctx, '7.0.0', null); - await ChangelogDialog.showIfNeeded(ctx, '7.0.0', '7.0.0'); - await tester.pumpAndSettle(); - expect(find.text(l.whatsNew), findsNothing); + expect(find.byType(WhatsNewPage), findsOneWidget); + expect(find.byKey(const ValueKey('whats-new-7.0.0')), findsOneWidget); + expect(find.byKey(const ValueKey('whats-new-5.5.0')), findsOneWidget); + expect(find.byKey(const ValueKey('whats-new-4.7.0')), findsNothing); + await tester.scrollUntilVisible(find.byKey(const ValueKey('whats-new-rate')), 200); + expect(find.byKey(const ValueKey('whats-new-blog')), findsOneWidget); + expect(find.text(l.whatsNewHelpTitle), findsOneWidget); + + // Opened is seen: the banner is gone, also after a restart. + expect(WhatsNew.pending.value, isNull); + expect(core.settings.getWhatsNewPending(), isNull); + }); + + testWidgets('it stays across launches until dismissed', (tester) async { + await WhatsNew.checkAtLaunch('7.0.0', '5.5.0'); + WhatsNew.pending.value = null; // a restart + await WhatsNew.checkAtLaunch('7.0.0', '7.0.0'); + await pumpBanner(tester); + expect(find.byKey(const ValueKey('whats-new-banner')), findsOneWidget); + + await tester.tap(find.byKey(const ValueKey('whats-new-banner-dismiss'))); + await tester.pump(); + expect(find.byKey(const ValueKey('whats-new-banner')), findsNothing); + await WhatsNew.checkAtLaunch('7.0.0', '7.0.0'); + expect(WhatsNew.pending.value, isNull); + }); + + testWidgets('two updates unread: the page still starts at the first one missed', (tester) async { + await WhatsNew.checkAtLaunch('5.5.0', '4.7.0'); + await WhatsNew.checkAtLaunch('7.0.0', '5.5.0'); + expect(WhatsNew.pending.value, ('7.0.0', '4.7.0')); + }); + + testWidgets('nothing after a fresh install, without a change since, or in store renders', (tester) async { + await WhatsNew.checkAtLaunch('7.0.0', null); + await WhatsNew.checkAtLaunch('7.0.0', '7.0.0'); + expect(WhatsNew.pending.value, isNull); + screenshotMode = true; + await WhatsNew.checkAtLaunch('7.0.0', '4.7.0'); + expect(WhatsNew.pending.value, isNull); + }); + + testWidgets('no rating plea where there is no store', (tester) async { + WhatsNewPage.canRate = () => false; + tester.view.physicalSize = const Size(390, 2400); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget(app(const WhatsNewPage(currentVersion: '7.0.0', sinceVersion: '5.5.0'))); + await tester.pumpAndSettle(); + expect(find.byKey(const ValueKey('whats-new-blog')), findsOneWidget); + expect(find.byKey(const ValueKey('whats-new-help')), findsNothing); + }); }); } diff --git a/test/pages/changelog/whats_new_snapshot_test.dart b/test/pages/changelog/whats_new_snapshot_test.dart new file mode 100644 index 00000000..b720692d --- /dev/null +++ b/test/pages/changelog/whats_new_snapshot_test.dart @@ -0,0 +1,68 @@ +@Tags(['screenshots']) +library; + +import 'dart:io'; + +import 'package:bike_control/models/changelog.dart'; +import 'package:bike_control/pages/navigation.dart'; +import 'package:bike_control/widgets/changelog/whats_new.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:shadcn_flutter/shadcn_flutter.dart'; + +import '../../helpers/shell_harness.dart'; +import '../../widget_snapshot.dart'; + +/// The "What's new" banner in the shell and the page it opens. Run: +/// `flutter test --run-skipped test/pages/changelog/whats_new_snapshot_test.dart` +/// Output: `build/snapshots/whats-new-*.png` +Future main() async { + await ensureSnapshotHarness(); + quietShellEnvironment(); + final releases = releasesSince(parseChangelog(File('CHANGELOG.md').readAsStringSync()), '7.4.0'); + final version = releases.first.version; + + const sizes = [Size(390, 844), Size(1280, 800)]; + for (final size in sizes) { + for (final brightness in Brightness.values) { + final tag = '${size.width.toInt()}x${size.height.toInt()}-${brightness.name}'; + testWidgets('whats-new-banner-$tag', (tester) async { + WhatsNew.pending.value = (version, '7.4.0'); + addTearDown(() => WhatsNew.pending.value = null); + await captureWidget( + tester, + name: 'whats-new-banner-$tag', + width: size.width, + height: size.height, + padding: EdgeInsets.zero, + pixelRatio: 2, + brightness: brightness, + settle: false, + builder: (context) => const Navigation(), + ); + await disposeShell(tester); + }); + + for (final scrolled in [false, true]) { + final name = 'whats-new-page${scrolled ? '-end' : ''}-$tag'; + testWidgets(name, (tester) async { + await captureWidget( + tester, + name: name, + width: size.width, + height: size.height, + padding: EdgeInsets.zero, + pixelRatio: 2, + brightness: brightness, + builder: (context) => WhatsNewPage(currentVersion: version, sinceVersion: '7.4.0', releases: releases), + beforeCapture: scrolled + ? (tester) async { + await tester.ensureVisible(find.byKey(const ValueKey('whats-new-rate'))); + await tester.pumpAndSettle(); + } + : null, + ); + }); + } + } + } +} diff --git a/test/pages/owner_feedback_round2_snapshot_test.dart b/test/pages/owner_feedback_round2_snapshot_test.dart index 7beac399..d45a35d3 100644 --- a/test/pages/owner_feedback_round2_snapshot_test.dart +++ b/test/pages/owner_feedback_round2_snapshot_test.dart @@ -22,7 +22,7 @@ import 'package:bike_control/utils/core.dart'; import 'package:bike_control/utils/host_platform.dart'; import 'package:bike_control/utils/keymap/apps/my_whoosh.dart'; import 'package:bike_control/utils/requirements/multi.dart'; -import 'package:bike_control/widgets/changelog_dialog.dart'; +import 'package:bike_control/widgets/changelog/whats_new.dart'; import 'package:flutter/services.dart' show StandardMessageCodec; import 'package:flutter_test/flutter_test.dart'; import 'package:prop/emulators/definitions/fitness_bike_definition.dart'; @@ -300,10 +300,7 @@ Future main() async { name: 'of2-whats-new-390x844-$b', size: phone, brightness: brightness, - build: (context) => ColoredBox( - color: Theme.of(context).colorScheme.background, - child: ChangelogDialog(releases: releases, currentVersion: '7.0.0'), - ), + build: (_) => WhatsNewPage(currentVersion: '7.0.0', sinceVersion: '6.5.0', releases: releases), ); }); @@ -376,10 +373,7 @@ Future main() async { name: 'of2-whats-new-1280x800-dark', size: desktop, brightness: Brightness.dark, - build: (context) => ColoredBox( - color: Theme.of(context).colorScheme.background, - child: ChangelogDialog(releases: releases, currentVersion: '7.0.0'), - ), + build: (_) => WhatsNewPage(currentVersion: '7.0.0', sinceVersion: '6.5.0', releases: releases), ); }); }