1+ import 'dart:developer' ;
2+ import 'dart:io' ;
3+
4+ import 'package:flutter/foundation.dart' ;
15import 'package:get/get.dart' ;
26import 'package:package_info_plus/package_info_plus.dart' ;
7+ import 'package:resonate/l10n/app_localizations.dart' ;
8+ import 'package:resonate/utils/enums/action_enum.dart' ;
9+ import 'package:resonate/utils/enums/log_type.dart' ;
10+ import 'package:resonate/views/widgets/snackbar.dart' ;
11+ import 'package:upgrader/upgrader.dart' ;
12+ import 'package:url_launcher/url_launcher.dart' ;
13+ import 'package:resonate/utils/enums/update_enums.dart' ;
314
415class AboutAppScreenController extends GetxController {
516 final Rx <String > appVersion = "0.0.0" .obs;
617 final Rx <String > appBuildNumber = "1" .obs;
718 final Rx <bool > updateAvailable = false .obs;
19+ final Rx <bool > isCheckingForUpdate = false .obs;
820
921 final showFullDescription = false .obs;
1022
11- final String fullDescription = """
12- Resonate is a revolutionary voice-based social media platform where every voice matters.
13- Join real-time audio conversations, participate in diverse discussions, and connect with
14- like-minded individuals. Our platform offers:
15- - Live audio rooms with topic-based discussions
16- - Seamless social networking through voice
17- - Community-driven content moderation
18- - Cross-platform compatibility
19- - End-to-end encrypted private conversations
23+ final Upgrader upgrader;
2024
21- Developed by the AOSSIE open source community, we prioritize user privacy and
22- community-driven development. Join us in shaping the future of social audio!""" ;
25+ AboutAppScreenController ({Upgrader ? upgrader})
26+ : upgrader =
27+ upgrader ??
28+ Upgrader (
29+ debugDisplayAlways: kDebugMode,
30+ debugDisplayOnce: false ,
31+ debugLogging: kDebugMode,
32+ durationUntilAlertAgain: kDebugMode
33+ ? const Duration (minutes: 1 )
34+ : const Duration (days: 7 ),
35+ );
2336
2437 @override
2538 void onInit () {
@@ -33,26 +46,85 @@ community-driven development. Join us in shaping the future of social audio!""";
3346 appVersion.value = packageInfo.version;
3447 appBuildNumber.value = packageInfo.buildNumber;
3548 } catch (e) {
36- Get .snackbar ("Error" , "Could not load package info" );
49+ customSnackbar (
50+ AppLocalizations .of (Get .context! )! .updateCheckFailed,
51+ AppLocalizations .of (Get .context! )! .updateCheckFailedMessage,
52+ LogType .error,
53+ );
3754 }
3855 }
3956
4057 void toggleDescription () {
4158 showFullDescription.toggle ();
4259 }
4360
44- Future <void > checkForUpdate () async {
45- // Implement actual update check logic
46- updateAvailable.value = await _fakeUpdateCheck ();
47- if (updateAvailable.value) {
48- Get .snackbar ("Update Available" , "A new version is available!" );
49- } else {
50- Get .snackbar ("Up to Date" , "You're using the latest version" );
61+ Future <UpdateCheckResult > checkForUpdate ({
62+ bool launchUpdateIfAvailable = false ,
63+ bool isManualCheck = false ,
64+ bool clearSettings = true ,
65+ bool showDialog = true ,
66+ }) async {
67+ isCheckingForUpdate.value = true ;
68+ try {
69+ if (clearSettings) {
70+ Upgrader .clearSavedSettings ();
71+ }
72+ await upgrader.initialize ();
73+ final needsUpdate = upgrader.shouldDisplayUpgrade ();
74+ updateAvailable.value = needsUpdate;
75+ if (needsUpdate && showDialog) {
76+ if (launchUpdateIfAvailable) {
77+ await launchStoreForUpdate ();
78+ } else {
79+ Get .dialog (
80+ UpgradeAlert (
81+ upgrader: upgrader,
82+ onIgnore: () {
83+ Get .back ();
84+ return true ;
85+ },
86+ onLater: () {
87+ Get .back ();
88+ return true ;
89+ },
90+ ),
91+ barrierDismissible: true ,
92+ );
93+ }
94+ }
95+ return needsUpdate
96+ ? UpdateCheckResult .updateAvailable
97+ : UpdateCheckResult .noUpdateAvailable;
98+ } catch (e) {
99+ log ('Update check error: $e ' );
100+ return UpdateCheckResult .checkFailed;
101+ } finally {
102+ isCheckingForUpdate.value = false ;
51103 }
52104 }
53105
54- Future <bool > _fakeUpdateCheck () async {
55- await Future .delayed (const Duration (seconds: 1 ));
56- return false ;
106+ Future <UpdateActionResult > launchStoreForUpdate () async {
107+ try {
108+ String storeUrl;
109+ if (Platform .isAndroid) {
110+ storeUrl =
111+ 'https://play.google.com/store/apps/details?id=com.resonate.resonate' ;
112+ } else if (Platform .isIOS) {
113+ // The App Store URL of app
114+ storeUrl = '' ;
115+ } else {
116+ return UpdateActionResult .error;
117+ }
118+ final uri = Uri .parse (storeUrl);
119+ if (await canLaunchUrl (uri)) {
120+ await launchUrl (uri, mode: LaunchMode .externalApplication);
121+ return UpdateActionResult .success;
122+ } else {
123+ return UpdateActionResult .failed;
124+ }
125+ } catch (e) {
126+ log ('Update error: $e ' );
127+ return UpdateActionResult .error;
128+ }
57129 }
58130}
0 commit comments