The personal finance app for everyone (by everyone)
Ruby
Add Mobile version check for update notifications (#2367)
Tristan the Katanaee89aec85065
diff --git a/mobile/lib/main.dart b/mobile/lib/main.dartindex 0b005f8f21..a806310d6e 100644--- a/mobile/lib/main.dart+++ b/mobile/lib/main.dart@@ -21,6 +21,7 @@ import 'services/log_service.dart';import 'services/preferences_service.dart';import 'services/telemetry_service.dart';import 'theme/sure_theme.dart';+import 'package:upgrader/upgrader.dart';void main() async {WidgetsFlutterBinding.ensureInitialized();@@ -110,6 +111,12 @@ class _AppWrapperState extends State<AppWrapper> with WidgetsBindingObserver {late final AppLinks _appLinks;StreamSubscription<Uri>? _linkSubscription;+ final _upgrader = Upgrader(+ durationUntilAlertAgain: const Duration(days: 7),+ countryCode: 'us',+ messages: _SureUpgraderMessages(),+ );+@overridevoid initState() {super.initState();@@ -267,7 +274,11 @@ class _AppWrapperState extends State<AppWrapper> with WidgetsBindingObserver {if (authProvider.isAuthenticated) {return Stack(children: [- const MainNavigationScreen(),+ UpgradeAlert(+ upgrader: _upgrader,+ showIgnore: false,+ child: const MainNavigationScreen(),+ ),if (_isLocked)BiometricLockScreen(onUnlocked: _onUnlocked,@@ -293,3 +304,23 @@ class _AppWrapperState extends State<AppWrapper> with WidgetsBindingObserver {);}}++class _SureUpgraderMessages extends UpgraderMessages {+ @override+ String get title => 'Update available';++ @override+ String get body =>+ '{{appName}} {{currentAppStoreVersion}} is now available — '+ 'you have {{currentInstalledVersion}}.\n\n'+ "What's new? Check the store for release notes.";++ @override+ String get buttonTitleUpdate => 'Update now';++ @override+ String get buttonTitleLater => 'Later';++ @override+ String get releaseNotes => '';+}diff --git a/mobile/lib/screens/settings_screen.dart b/mobile/lib/screens/settings_screen.dartindex 89ae9f067a..38517eb932 100644--- a/mobile/lib/screens/settings_screen.dart+++ b/mobile/lib/screens/settings_screen.dart@@ -1,6 +1,7 @@import 'package:flutter/material.dart';import 'package:package_info_plus/package_info_plus.dart';import 'package:provider/provider.dart';+import 'package:upgrader/upgrader.dart';import 'package:url_launcher/url_launcher.dart';import '../providers/auth_provider.dart';import '../providers/categories_provider.dart';@@ -34,6 +35,8 @@ class _SettingsScreenState extends State<SettingsScreen> {bool _biometricEnabled = false;bool _isTogglingBiometric = false;List<CustomProxyHeader> _customHeaders = [];+ bool _isCheckingForUpdate = false;+ late final Upgrader _manualUpgrader;String _displayInitial(String? displayName) {final trimmed = displayName?.trim() ?? '';@@ -47,6 +50,82 @@ class _SettingsScreenState extends State<SettingsScreen> {_loadAppVersion();_loadBiometricState();_loadCustomHeaders();+ _manualUpgrader = Upgrader(+ durationUntilAlertAgain: Duration.zero,+ countryCode: 'us',+ );+ }++ Future<void> _checkForUpdate() async {+ if (_isCheckingForUpdate) return;+ setState(() => _isCheckingForUpdate = true);+ try {+ await _manualUpgrader.initialize();+ if (!mounted) {+ _manualUpgrader.dispose();+ return;+ }+ await _manualUpgrader.updateVersionInfo();+ if (!mounted) return;++ final available = _manualUpgrader.isUpdateAvailable();+ final storeVersion = _manualUpgrader.versionInfo?.appStoreVersion?.toString();+ final storeUrl = _manualUpgrader.versionInfo?.appStoreListingURL;++ if (available) {+ await _showUpdateDialog(storeVersion ?? 'a newer version', storeUrl);+ } else {+ ScaffoldMessenger.of(context).showSnackBar(+ const SnackBar(content: Text("You're up to date!")),+ );+ }+ } catch (e) {+ if (mounted) {+ ScaffoldMessenger.of(context).showSnackBar(+ const SnackBar(content: Text('Unable to check for updates')),+ );+ }+ } finally {+ if (mounted) setState(() => _isCheckingForUpdate = false);+ }+ }++ Future<void> _showUpdateDialog(String version, String? storeUrl) async {+ final launch = await showDialog<bool>(+ context: context,+ builder: (ctx) => AlertDialog(+ title: const Text('Update available'),+ content: Text('Version $version is available. Update now?'),+ actions: [+ TextButton(+ onPressed: () => Navigator.pop(ctx, false),+ child: const Text('Later'),+ ),+ TextButton(+ onPressed: storeUrl == null ? null : () => Navigator.pop(ctx, true),+ child: const Text('Update now'),+ ),+ ],+ ),+ );++ if (launch == true && storeUrl != null && mounted) {+ final uri = Uri.tryParse(storeUrl);+ final opened = uri != null+ ? await launchUrl(uri, mode: LaunchMode.externalApplication)+ : false;+ if (!opened && mounted) {+ ScaffoldMessenger.of(context).showSnackBar(+ const SnackBar(content: Text('Unable to open store link')),+ );+ }+ }+ }++ @override+ void dispose() {+ _manualUpgrader.dispose();+ super.dispose();}Future<void> _loadBiometricState() async {@@ -510,6 +589,20 @@ class _SettingsScreenState extends State<SettingsScreen> {),),+ ListTile(+ leading: const Icon(Icons.system_update_outlined),+ title: const Text('Check for updates'),+ subtitle: const Text('See if a newer version is available'),+ trailing: _isCheckingForUpdate+ ? const SizedBox(+ width: 20,+ height: 20,+ child: CircularProgressIndicator(strokeWidth: 2),+ )+ : const Icon(Icons.chevron_right),+ onTap: _isCheckingForUpdate ? null : _checkForUpdate,+ ),+ListTile(leading: const Icon(Icons.chat_bubble_outline),title: const Text('Contact us'),diff --git a/mobile/pubspec.lock b/mobile/pubspec.lockindex cec2032af2..2cd91f8b85 100644--- a/mobile/pubspec.lock+++ b/mobile/pubspec.lock@@ -69,10 +69,10 @@ packages:dependency: transitivedescription:name: characters- sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803+ sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716burl: "https://pub.dev"source: hosted- version: "1.4.0"+ version: "1.4.1"checked_yaml:dependency: transitivedescription:@@ -129,6 +129,14 @@ packages:url: "https://pub.dev"source: hostedversion: "3.0.7"+ csslib:+ dependency: transitive+ description:+ name: csslib+ sha256: "09bad715f418841f976c77db72d5398dc1253c21fb9c0c7f0b0b985860b2d58e"+ url: "https://pub.dev"+ source: hosted+ version: "1.0.2"cupertino_icons:dependency: "direct main"description:@@ -288,6 +296,14 @@ packages:url: "https://pub.dev"source: hostedversion: "2.1.0"+ html:+ dependency: transitive+ description:+ name: html+ sha256: "6d1264f2dffa1b1101c25a91dff0dc2daee4c18e87cd8538729773c073dbf602"+ url: "https://pub.dev"+ source: hosted+ version: "0.15.6"http:dependency: "direct main"description:@@ -332,26 +348,26 @@ packages:dependency: transitivedescription:name: leak_tracker- sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"+ sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"url: "https://pub.dev"source: hosted- version: "10.0.9"+ version: "11.0.2"leak_tracker_flutter_testing:dependency: transitivedescription:name: leak_tracker_flutter_testing- sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573+ sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"url: "https://pub.dev"source: hosted- version: "3.0.9"+ version: "3.0.10"leak_tracker_testing:dependency: transitivedescription:name: leak_tracker_testing- sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"+ sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"url: "https://pub.dev"source: hosted- version: "3.0.1"+ version: "3.0.2"lints:dependency: transitivedescription:@@ -412,26 +428,26 @@ packages:dependency: transitivedescription:name: matcher- sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2+ sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6"url: "https://pub.dev"source: hosted- version: "0.12.17"+ version: "0.12.18"material_color_utilities:dependency: transitivedescription:name: material_color_utilities- sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec+ sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"url: "https://pub.dev"source: hosted- version: "0.11.1"+ version: "0.13.0"meta:dependency: transitivedescription:name: meta- sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c+ sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"url: "https://pub.dev"source: hosted- version: "1.16.0"+ version: "1.17.0"nested:dependency: transitivedescription:@@ -448,6 +464,14 @@ packages:url: "https://pub.dev"source: hostedversion: "0.5.0"+ os_detect:+ dependency: transitive+ description:+ name: os_detect+ sha256: "7d87c0dd98c6faf110d5aa498e9a6df02ffce4bb78cc9cfc8ad02929be9bb71f"+ url: "https://pub.dev"+ source: hosted+ version: "2.0.3"package_info_plus:dependency: "direct main"description:@@ -737,10 +761,10 @@ packages:dependency: transitivedescription:name: test_api- sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd+ sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636"url: "https://pub.dev"source: hosted- version: "0.7.4"+ version: "0.7.9"typed_data:dependency: transitivedescription:@@ -749,6 +773,14 @@ packages:url: "https://pub.dev"source: hostedversion: "1.4.0"+ upgrader:+ dependency: "direct main"+ description:+ name: upgrader+ sha256: "6282524d4b664e48e24736ce343eedd115dcc1ce79198fc0bd46f14692e1f05e"+ url: "https://pub.dev"+ source: hosted+ version: "13.5.0"url_launcher:dependency: "direct main"description:@@ -849,10 +881,18 @@ packages:dependency: transitivedescription:name: vector_math- sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"+ sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5burl: "https://pub.dev"source: hosted- version: "2.1.4"+ version: "2.2.0"+ version:+ dependency: transitive+ description:+ name: version+ sha256: "3d4140128e6ea10d83da32fef2fa4003fccbf6852217bb854845802f04191f94"+ url: "https://pub.dev"+ source: hosted+ version: "3.0.2"vm_service:dependency: transitivedescription:@@ -902,5 +942,5 @@ packages:source: hostedversion: "3.1.3"sdks:- dart: ">=3.8.0 <4.0.0"+ dart: ">=3.9.0-0 <4.0.0"flutter: ">=3.32.0"diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yamlindex aa1679402b..850d4ffac6 100644--- a/mobile/pubspec.yaml+++ b/mobile/pubspec.yaml@@ -27,6 +27,7 @@ dependencies:local_auth: ^2.3.0flutter_markdown: ^0.7.2sentry_flutter: ^8.14.2+ upgrader: ^13.5.0dev_dependencies:flutter_test: