A cross platform Audiobookshelf client for Android and iOS
Dart
Offer a link to the release notes the first time the app opens after an update
Barnabas76e042be4cc8
diff --git a/lib/screens/app_shell.dart b/lib/screens/app_shell.dartindex 7c6f99a3..6a7f52a2 100644--- a/lib/screens/app_shell.dart+++ b/lib/screens/app_shell.dart@@ -55,6 +55,7 @@ import 'settings_screen.dart';import 'app_shell_navigation_policy.dart';import '../widgets/library_picker_sheet.dart';import '../widgets/welcome_sheet.dart';+import '../widgets/whats_new_prompt.dart';import '../services/review_service.dart';import '../services/settings_sync_service.dart';import '../services/update_checker_service.dart';@@ -374,6 +375,7 @@ class _AppShellState extends State<AppShell>context.read<LibraryProvider>().addListener(_onLibraryChanged);_loadPodcastTabPrefs();PlayerSettings.settingsChanged.addListener(_loadPodcastTabPrefs);+ WhatsNewPrompt.showIfUpdated(context);WelcomeSheet.showIfNeeded(context);_checkForUpdate();}diff --git a/lib/widgets/welcome_sheet.dart b/lib/widgets/welcome_sheet.dartindex aa02c33c..d16f7ec3 100644--- a/lib/widgets/welcome_sheet.dart+++ b/lib/widgets/welcome_sheet.dart@@ -7,12 +7,12 @@ import '../l10n/app_localizations.dart';/// couple of essential gestures. Kept short on purpose - the previous version/// was a long modal sheet that users tended to dismiss without reading.class WelcomeSheet {- static const _prefKey = 'has_seen_welcome';+ static const prefKey = 'has_seen_welcome';static Future<void> showIfNeeded(BuildContext context) async {final prefs = await SharedPreferences.getInstance();- if (prefs.getBool(_prefKey) == true) return;- await prefs.setBool(_prefKey, true);+ if (prefs.getBool(prefKey) == true) return;+ await prefs.setBool(prefKey, true);if (!context.mounted) return;// Small delay so the app finishes its initial layout firstawait Future.delayed(const Duration(milliseconds: 800));diff --git a/lib/widgets/whats_new_prompt.dart b/lib/widgets/whats_new_prompt.dartnew file mode 100644index 00000000..5c82574c--- /dev/null+++ b/lib/widgets/whats_new_prompt.dart@@ -0,0 +1,60 @@+import 'package:flutter/foundation.dart';+import 'package:flutter/material.dart';+import 'package:package_info_plus/package_info_plus.dart';+import 'package:shared_preferences/shared_preferences.dart';+import 'package:url_launcher/url_launcher.dart';++import '../build_info.dart';+import '../l10n/app_localizations.dart';+import 'welcome_sheet.dart';++/// After an update, offers the GitHub release notes for the new build.+class WhatsNewPrompt {+ static const _lastBuildKey = 'whats_new_last_build';+ static const _isDevBuild = bool.fromEnvironment('DEV_BUILD');++ /// Call before [WelcomeSheet.showIfNeeded]: a fresh install hasn't seen the+ /// welcome yet, and that's how it's told apart from an update.+ static Future<void> showIfUpdated(BuildContext context) async {+ if (kIsWeb || _isDevBuild) return;+ final prefs = await SharedPreferences.getInstance();+ final freshInstall = prefs.getBool(WelcomeSheet.prefKey) != true;+ final info = await PackageInfo.fromPlatform();+ final build = int.tryParse(info.buildNumber);+ if (build == null) return;+ final lastBuild = prefs.getInt(_lastBuildKey);+ await prefs.setInt(_lastBuildKey, build);+ if (freshInstall || (lastBuild != null && build <= lastBuild)) return;++ final beta = betaNumberFor(info.version);+ final tag = beta == null ? 'v${info.version}' : 'v${info.version}-$build';+ final url = Uri.parse('https://github.com/pounat/absorb/releases/tag/$tag');++ // Let launch settle so this doesn't land on top of the first frames.+ await Future.delayed(const Duration(milliseconds: 1200));+ if (!context.mounted) return;+ final l = AppLocalizations.of(context)!;+ final version =+ beta == null ? info.version : '${info.version} (${l.betaLabel(beta)})';+ final open = await showDialog<bool>(+ context: context,+ builder: (ctx) => AlertDialog(+ title: Text(l.whatsNewTitle),+ content: Text(l.whatsNewContent(version)),+ actions: [+ TextButton(+ onPressed: () => Navigator.pop(ctx, false),+ child: Text(l.later),+ ),+ FilledButton(+ onPressed: () => Navigator.pop(ctx, true),+ child: Text(l.whatsNewButton),+ ),+ ],+ ),+ );+ if (open == true) {+ await launchUrl(url, mode: LaunchMode.externalApplication);+ }+ }+}