Skip to content

Commit 7dcf1c7

Browse files
authored
Merge pull request #521 from Mayank4352/dev
Added the functionality for checking app update
2 parents e01eaec + 259edfc commit 7dcf1c7

16 files changed

+994
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ migrate_working_dir/
3737
lib/firebase_options.dart
3838
firebase.json
3939

40+
4041
# Symbolication related
4142
app.*.symbols
4243

Lines changed: 94 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1+
import 'dart:developer';
2+
import 'dart:io';
3+
4+
import 'package:flutter/foundation.dart';
15
import 'package:get/get.dart';
26
import '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

415
class 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
}

lib/controllers/auth_state_controller.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:get/get.dart';
1212
import 'package:get_storage/get_storage.dart';
1313
import 'package:resonate/controllers/friend_calling_controller.dart';
1414
import 'package:resonate/controllers/friends_controller.dart';
15+
import 'package:resonate/controllers/about_app_screen_controller.dart';
1516
import 'package:resonate/controllers/upcomming_rooms_controller.dart';
1617
import 'package:resonate/controllers/tabview_controller.dart';
1718
import 'package:resonate/models/follower_user_model.dart';
@@ -233,6 +234,9 @@ class AuthStateController extends GetxController {
233234
Future<void> isUserLoggedIn() async {
234235
try {
235236
await setUserProfileData();
237+
if (Get.isRegistered<AboutAppScreenController>()) {
238+
Get.find<AboutAppScreenController>().checkForUpdate();
239+
}
236240
if (isUserProfileComplete == false) {
237241
Get.offNamed(AppRoutes.onBoarding);
238242
} else {

lib/l10n/app_en.arb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,5 +587,25 @@
587587
"example": "john_doe"
588588
}
589589
}
590-
}
590+
},
591+
"checkForUpdates": "Check Updates",
592+
"updateNow": "Update Now",
593+
"updateLater": "Later",
594+
"updateSuccessful": "Update Successful",
595+
"updateSuccessfulMessage": "Resonate has been updated successfully!",
596+
"updateCancelled": "Update Cancelled",
597+
"updateCancelledMessage": "Update was cancelled by user",
598+
"updateFailed": "Update Failed",
599+
"updateFailedMessage": "Failed to update. Please try updating from Play Store manually.",
600+
"updateError": "Update Error",
601+
"updateErrorMessage": "An error occurred while updating. Please try again.",
602+
"platformNotSupported": "Platform Not Supported",
603+
"platformNotSupportedMessage": "Update checking is only available on Android devices",
604+
"updateCheckFailed": "Update Check Failed",
605+
"updateCheckFailedMessage": "Could not check for updates. Please try again later.",
606+
"upToDateTitle": "You're Up to Date!",
607+
"upToDateMessage": "You're using the latest version of Resonate",
608+
"updateAvailableTitle": "Update Available!",
609+
"updateAvailableMessage": "A new version of Resonate is available on Play Store",
610+
"updateFeaturesImprovement": "Get the latest features and improvements!"
591611
}

lib/l10n/app_hi.arb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,5 +588,25 @@
588588
"example": "john_doe"
589589
}
590590
}
591-
}
591+
},
592+
"checkForUpdates": "अपडेट चेक करें",
593+
"updateNow": "अभी अपडेट करें",
594+
"updateLater": "बाद में",
595+
"updateSuccessful": "अपडेट सफल",
596+
"updateSuccessfulMessage": "रेज़ोनेट सफलतापूर्वक अपडेट हो गया है!",
597+
"updateCancelled": "अपडेट रद्द किया गया",
598+
"updateCancelledMessage": "अपडेट यूज़र द्वारा रद्द किया गया",
599+
"updateFailed": "अपडेट फेल",
600+
"updateFailedMessage": "अपडेट फेल हो गया। कृपया Play Store से मैन्युअली अपडेट करने का प्रयास करें।",
601+
"updateError": "अपडेट एरर",
602+
"updateErrorMessage": "अपडेट करने में कोई समस्या आई। कृपया फिर से प्रयास करें।",
603+
"platformNotSupported": "प्लेटफॉर्म सपोर्टेड नहीं",
604+
"platformNotSupportedMessage": "अपडेट चेक करना केवल Android डिवाइस पर उपलब्ध है",
605+
"updateCheckFailed": "अपडेट चेक फेल",
606+
"updateCheckFailedMessage": "अपडेट चेक नहीं हो सका। कृपया बाद में प्रयास करें।",
607+
"upToDateTitle": "आप अप टू डेट हैं!",
608+
"upToDateMessage": "आप रेज़ोनेट का लेटेस्ट वर्शन इस्तेमाल कर रहे हैं",
609+
"updateAvailableTitle": "अपडेट उपलब्ध है!",
610+
"updateAvailableMessage": "रेज़ोनेट का नया वर्शन Play Store पर उपलब्ध है",
611+
"updateFeaturesImprovement": "नवीनतम सुविधाएं और सुधार प्राप्त करें!"
592612
}

lib/l10n/app_localizations.dart

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,126 @@ abstract class AppLocalizations {
20872087
/// In en, this message translates to:
20882088
/// **'User \${username} declined the call.'**
20892089
String callDeclinedTo(String username);
2090+
2091+
/// No description provided for @checkForUpdates.
2092+
///
2093+
/// In en, this message translates to:
2094+
/// **'Check Updates'**
2095+
String get checkForUpdates;
2096+
2097+
/// No description provided for @updateNow.
2098+
///
2099+
/// In en, this message translates to:
2100+
/// **'Update Now'**
2101+
String get updateNow;
2102+
2103+
/// No description provided for @updateLater.
2104+
///
2105+
/// In en, this message translates to:
2106+
/// **'Later'**
2107+
String get updateLater;
2108+
2109+
/// No description provided for @updateSuccessful.
2110+
///
2111+
/// In en, this message translates to:
2112+
/// **'Update Successful'**
2113+
String get updateSuccessful;
2114+
2115+
/// No description provided for @updateSuccessfulMessage.
2116+
///
2117+
/// In en, this message translates to:
2118+
/// **'Resonate has been updated successfully!'**
2119+
String get updateSuccessfulMessage;
2120+
2121+
/// No description provided for @updateCancelled.
2122+
///
2123+
/// In en, this message translates to:
2124+
/// **'Update Cancelled'**
2125+
String get updateCancelled;
2126+
2127+
/// No description provided for @updateCancelledMessage.
2128+
///
2129+
/// In en, this message translates to:
2130+
/// **'Update was cancelled by user'**
2131+
String get updateCancelledMessage;
2132+
2133+
/// No description provided for @updateFailed.
2134+
///
2135+
/// In en, this message translates to:
2136+
/// **'Update Failed'**
2137+
String get updateFailed;
2138+
2139+
/// No description provided for @updateFailedMessage.
2140+
///
2141+
/// In en, this message translates to:
2142+
/// **'Failed to update. Please try updating from Play Store manually.'**
2143+
String get updateFailedMessage;
2144+
2145+
/// No description provided for @updateError.
2146+
///
2147+
/// In en, this message translates to:
2148+
/// **'Update Error'**
2149+
String get updateError;
2150+
2151+
/// No description provided for @updateErrorMessage.
2152+
///
2153+
/// In en, this message translates to:
2154+
/// **'An error occurred while updating. Please try again.'**
2155+
String get updateErrorMessage;
2156+
2157+
/// No description provided for @platformNotSupported.
2158+
///
2159+
/// In en, this message translates to:
2160+
/// **'Platform Not Supported'**
2161+
String get platformNotSupported;
2162+
2163+
/// No description provided for @platformNotSupportedMessage.
2164+
///
2165+
/// In en, this message translates to:
2166+
/// **'Update checking is only available on Android devices'**
2167+
String get platformNotSupportedMessage;
2168+
2169+
/// No description provided for @updateCheckFailed.
2170+
///
2171+
/// In en, this message translates to:
2172+
/// **'Update Check Failed'**
2173+
String get updateCheckFailed;
2174+
2175+
/// No description provided for @updateCheckFailedMessage.
2176+
///
2177+
/// In en, this message translates to:
2178+
/// **'Could not check for updates. Please try again later.'**
2179+
String get updateCheckFailedMessage;
2180+
2181+
/// No description provided for @upToDateTitle.
2182+
///
2183+
/// In en, this message translates to:
2184+
/// **'You\'re Up to Date!'**
2185+
String get upToDateTitle;
2186+
2187+
/// No description provided for @upToDateMessage.
2188+
///
2189+
/// In en, this message translates to:
2190+
/// **'You\'re using the latest version of Resonate'**
2191+
String get upToDateMessage;
2192+
2193+
/// No description provided for @updateAvailableTitle.
2194+
///
2195+
/// In en, this message translates to:
2196+
/// **'Update Available!'**
2197+
String get updateAvailableTitle;
2198+
2199+
/// No description provided for @updateAvailableMessage.
2200+
///
2201+
/// In en, this message translates to:
2202+
/// **'A new version of Resonate is available on Play Store'**
2203+
String get updateAvailableMessage;
2204+
2205+
/// No description provided for @updateFeaturesImprovement.
2206+
///
2207+
/// In en, this message translates to:
2208+
/// **'Get the latest features and improvements!'**
2209+
String get updateFeaturesImprovement;
20902210
}
20912211

20922212
class _AppLocalizationsDelegate

0 commit comments

Comments
 (0)