feat: Show a dialog when an update is available (#1654)

This commit is contained in:
aAbed 2024-01-25 23:05:34 +05:45 committed by aAbed
parent 7104d6d6dd
commit c7d975e612
No known key found for this signature in database
GPG Key ID: F26611AB3F996827
10 changed files with 302 additions and 190 deletions

View File

@ -16,6 +16,8 @@
"noShowAgain": "Don't show this again",
"add": "Add",
"remove": "Remove",
"showChangelogButton": "Show changelog",
"showUpdateButton": "Show update",
"navigationView": {
"dashboardTab": "Dashboard",
"patcherTab": "Patcher",
@ -27,6 +29,7 @@
"updatesSubtitle": "Updates",
"patchedSubtitle": "Patched apps",
"changeLaterSubtitle": "You can change this in the settings at a later time.",
"noUpdates": "No updates available",
@ -35,20 +38,25 @@
"noInstallations": "No patched apps installed",
"installUpdate": "Continue to install the update?",
"updateDialogTitle": "Update Manager",
"updatePatchesDialogTitle": "Update ReVanced Patches",
"updateSheetTitle": "Update ReVanced Manager",
"updateDialogTitle": "New update available",
"updatePatchesSheetTitle": "Update ReVanced Patches",
"updateChangelogTitle": "Changelog",
"patchesConsentDialogText": "ReVanced Patches needs to be downloaded.",
"patchesConsentDialogText2": "This will connect you to {url}.",
"patchesConsentDialogText3": "Auto update?",
"patchesConsentDialogText3Sub": "You can change this in settings at a later time.",
"updateDialogText": "A new update is available for {file}.\n\nThe currently installed version is {version}.",
"downloadConsentDialogTitle": "Download necessary files?",
"downloadConsentDialogText": "ReVanced Manager needs to download necessary files to work properly.",
"downloadConsentDialogText2": "This will connect you to {url}.",
"checkUpdateDialogTitle": "Check for updates?",
"checkUpdateDialogText": "Do you want ReVanced Manager to check for updates automatically?",
"notificationTitle": "Update downloaded",
"notificationText": "Tap to install the update",
"downloadingMessage": "Downloading update...",
"downloadedMessage": "Update downloaded!",
"downloadedMessage": "Update downloaded",
"installingMessage": "Installing update...",
@ -157,7 +165,7 @@
"unsupportedPatchVersion": "Patch is not supported for this app version.",
"unsupportedRequiredOption": "This patch contains a required option that is not supported by this app",
"patchesChangeWarningDialogText": "It is recommended to use the default patch selection and options. Changing them may result in unexpected issues.\n\nYou'll need to turn on \"Allow changing patch selection\" in settings before changing any patch selection.",
"patchesChangeWarningDialogText": "It is recommended to use the default patch selection and options. Changing them may result in unexpected issues.\n\nYou'll need to turn on \"Allow changing patch selection\" in the settings before changing any patch selection.",
"patchesChangeWarningDialogButton": "Use default selection"
},
"installerView": {
@ -235,6 +243,8 @@
"autoUpdatePatchesLabel": "Auto update patches",
"autoUpdatePatchesHint": "Automatically update patches to the latest version",
"showUpdateDialogLabel": "Show update dialog",
"showUpdateDialogHint": "Show a dialog when a new update is available",
"universalPatchesLabel": "Show universal patches",
"universalPatchesHint": "Display all apps and universal patches (may slow down the app list)",

View File

@ -81,7 +81,7 @@ class GithubAPI {
int updates = 0;
final String currentVersion =
await _managerAPI.getCurrentManagerVersion();
while (response.data[updates]['tag_name'] != 'v$currentVersion') {
while (response.data[updates]['tag_name'] != currentVersion) {
updates++;
}
for (int i = 1; i < updates; i++) {

View File

@ -128,12 +128,12 @@ class ManagerAPI {
await _prefs.setString('patchesRepo', value);
}
bool getPatchesConsent() {
return _prefs.getBool('patchesConsent') ?? false;
bool getDownloadConsent() {
return _prefs.getBool('downloadConsent') ?? false;
}
Future<void> setPatchesConsent(bool consent) async {
await _prefs.setBool('patchesConsent', consent);
void setDownloadConsent(bool consent) {
_prefs.setBool('downloadConsent', consent);
}
bool isPatchesAutoUpdate() {
@ -156,6 +156,14 @@ class ManagerAPI {
_prefs.setBool('showPatchesChangeWarning', !value);
}
bool showUpdateDialog() {
return _prefs.getBool('showUpdateDialog') ?? true;
}
void setShowUpdateDialog(bool value) {
_prefs.setBool('showUpdateDialog', value);
}
bool isChangingToggleModified() {
return _prefs.getBool('isChangingToggleModified') ?? false;
}
@ -164,8 +172,8 @@ class ManagerAPI {
_prefs.setBool('isChangingToggleModified', value);
}
Future<void> setPatchesAutoUpdate(bool value) async {
await _prefs.setBool('patchesAutoUpdate', value);
void setPatchesAutoUpdate(bool value) {
_prefs.setBool('patchesAutoUpdate', value);
}
List<Patch> getSavedPatches(String packageName) {
@ -508,7 +516,11 @@ class ManagerAPI {
Future<String> getCurrentManagerVersion() async {
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
return packageInfo.version;
String version = packageInfo.version;
if (!version.startsWith('v')) {
version = 'v$version';
}
return version;
}
Future<String> getCurrentPatchesVersion() async {

View File

@ -8,6 +8,7 @@ import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:injectable/injectable.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/services/download_manager.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:synchronized/synchronized.dart';
import 'package:timeago/timeago.dart';
@ -48,6 +49,9 @@ class RevancedAPI {
String extension,
String repoName,
) {
if (!locator<ManagerAPI>().getDownloadConsent()) {
return Future(() => null);
}
return getToolsLock.synchronized(() async {
try {
final response = await _dio.get('/tools');

View File

@ -19,7 +19,7 @@ import 'package:revanced_manager/services/revanced_api.dart';
import 'package:revanced_manager/services/toast.dart';
import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/homeView/update_confirmation_dialog.dart';
import 'package:revanced_manager/ui/widgets/homeView/update_confirmation_sheet.dart';
import 'package:revanced_manager/ui/widgets/shared/haptics/haptic_checkbox_list_tile.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
@ -35,15 +35,28 @@ class HomeViewModel extends BaseViewModel {
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
bool showUpdatableApps = false;
List<PatchedApplication> patchedInstalledApps = [];
String _currentManagerVersion = '';
String _currentPatchesVersion = '';
String? _latestManagerVersion = '';
File? downloadedApk;
Future<void> initialize(BuildContext context) async {
_managerAPI.rePatchedSavedApps().then((_) => _getPatchedApps());
_currentManagerVersion = await _managerAPI.getCurrentManagerVersion();
if (!_managerAPI.getDownloadConsent()) {
await showDownloadConsent(context);
await forceRefresh(context);
return;
}
_latestManagerVersion = await _managerAPI.getLatestManagerVersion();
if (!_managerAPI.getPatchesConsent()) {
await showPatchesConsent(context);
_currentPatchesVersion = await _managerAPI.getCurrentPatchesVersion();
if (_managerAPI.showUpdateDialog() && await hasManagerUpdates()) {
showUpdateDialog(context, false);
}
if (!_managerAPI.isPatchesAutoUpdate() &&
_managerAPI.showUpdateDialog() &&
await hasPatchesUpdates()) {
showUpdateDialog(context, true);
}
await _patcherAPI.initialize();
@ -114,17 +127,10 @@ class HomeViewModel extends BaseViewModel {
}
Future<bool> hasManagerUpdates() async {
String currentVersion = await _managerAPI.getCurrentManagerVersion();
// add v to current version
if (!currentVersion.startsWith('v')) {
currentVersion = 'v$currentVersion';
}
_latestManagerVersion =
await _managerAPI.getLatestManagerVersion() ?? currentVersion;
await _managerAPI.getLatestManagerVersion() ?? _currentManagerVersion;
if (_latestManagerVersion != currentVersion) {
if (_latestManagerVersion != _currentManagerVersion) {
return true;
}
return false;
@ -132,13 +138,12 @@ class HomeViewModel extends BaseViewModel {
Future<bool> hasPatchesUpdates() async {
final String? latestVersion = await _managerAPI.getLatestPatchesVersion();
final String currentVersion = await _managerAPI.getCurrentPatchesVersion();
if (latestVersion != null) {
try {
final int latestVersionInt =
int.parse(latestVersion.replaceAll(RegExp('[^0-9]'), ''));
final int currentVersionInt =
int.parse(currentVersion.replaceAll(RegExp('[^0-9]'), ''));
int.parse(_currentPatchesVersion.replaceAll(RegExp('[^0-9]'), ''));
return latestVersionInt > currentVersionInt;
} on Exception catch (e) {
if (kDebugMode) {
@ -166,13 +171,15 @@ class HomeViewModel extends BaseViewModel {
}
}
Future<void> showPatchesConsent(BuildContext context) async {
Future<void> showDownloadConsent(BuildContext context) async {
final ValueNotifier<bool> autoUpdate = ValueNotifier(true);
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: const Text('Download ReVanced Patches?'),
builder: (context) => PopScope(
canPop: false,
child: AlertDialog(
title: I18nText('homeView.downloadConsentDialogTitle'),
content: ValueListenableBuilder(
valueListenable: autoUpdate,
builder: (context, value, child) {
@ -181,7 +188,7 @@ class HomeViewModel extends BaseViewModel {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
I18nText(
'homeView.patchesConsentDialogText',
'homeView.downloadConsentDialogText',
child: Text(
'',
style: TextStyle(
@ -194,7 +201,7 @@ class HomeViewModel extends BaseViewModel {
Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: I18nText(
'homeView.patchesConsentDialogText2',
'homeView.downloadConsentDialogText2',
translationParams: {
'url': _managerAPI.defaultApiUrl.split('/')[2],
},
@ -208,17 +215,75 @@ class HomeViewModel extends BaseViewModel {
),
),
),
],
);
},
),
actions: [
TextButton(
onPressed: () async {
_managerAPI.setDownloadConsent(false);
SystemNavigator.pop();
},
child: I18nText('quitButton'),
),
FilledButton(
onPressed: () async {
_managerAPI.setDownloadConsent(true);
_managerAPI.setPatchesAutoUpdate(autoUpdate.value);
Navigator.of(context).pop();
},
child: I18nText('okButton'),
),
],
),
),
);
}
void showUpdateDialog(BuildContext context, bool isPatches) {
final ValueNotifier<bool> noShow =
ValueNotifier(!_managerAPI.showUpdateDialog());
showDialog(
context: context,
builder: (innerContext) => AlertDialog(
title: I18nText('homeView.updateDialogTitle'),
content: ValueListenableBuilder(
valueListenable: noShow,
builder: (context, value, child) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
I18nText(
'homeView.updateDialogText',
translationParams: {
'file': isPatches ? 'ReVanced Patches' : 'ReVanced Manager',
'version': isPatches
? _currentPatchesVersion
: _currentManagerVersion,
},
child: Text(
'',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.secondary,
),
),
),
const SizedBox(height: 10),
HapticCheckboxListTile(
value: value,
contentPadding: EdgeInsets.zero,
title: I18nText(
'homeView.patchesConsentDialogText3',
'noShowAgain',
),
subtitle: I18nText(
'homeView.patchesConsentDialogText3Sub',
'homeView.changeLaterSubtitle',
),
onChanged: (selected) {
autoUpdate.value = selected!;
noShow.value = selected!;
},
),
],
@ -228,18 +293,18 @@ class HomeViewModel extends BaseViewModel {
actions: [
TextButton(
onPressed: () async {
await _managerAPI.setPatchesConsent(false);
SystemNavigator.pop();
_managerAPI.setShowUpdateDialog(!noShow.value);
Navigator.pop(innerContext);
},
child: I18nText('quitButton'),
child: I18nText('dismissButton'), // Decide later
),
FilledButton(
onPressed: () async {
await _managerAPI.setPatchesConsent(true);
await _managerAPI.setPatchesAutoUpdate(autoUpdate.value);
Navigator.of(context).pop();
_managerAPI.setShowUpdateDialog(!noShow.value);
Navigator.pop(innerContext);
await showUpdateConfirmationDialog(context, isPatches);
},
child: I18nText('okButton'),
child: I18nText('showUpdateButton'),
),
],
),
@ -271,43 +336,15 @@ class HomeViewModel extends BaseViewModel {
builder: (context) => ValueListenableBuilder(
valueListenable: downloaded,
builder: (context, value, child) {
return SimpleDialog(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
contentPadding: const EdgeInsets.all(16.0),
return AlertDialog(
title: I18nText(
!value
? 'homeView.downloadingMessage'
: 'homeView.downloadedMessage',
child: Text(
'',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.secondary,
),
),
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Column(
children: [
Row(
children: [
Icon(
Icons.new_releases_outlined,
color: Theme.of(context).colorScheme.secondary,
),
const SizedBox(width: 8.0),
Text(
'$_latestManagerVersion',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.secondary,
),
),
],
),
const SizedBox(height: 16.0),
if (!value)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
@ -346,7 +383,7 @@ class HomeViewModel extends BaseViewModel {
child: Text(
'',
style: TextStyle(
fontSize: 20,
fontSize: 16,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.secondary,
),
@ -384,7 +421,6 @@ class HomeViewModel extends BaseViewModel {
),
],
),
],
);
},
),
@ -436,16 +472,18 @@ class HomeViewModel extends BaseViewModel {
Future<void> showUpdateConfirmationDialog(
BuildContext parentContext,
bool isPatches,
) {
bool isPatches, [
bool changelog = false,
]) {
return showModalBottomSheet(
context: parentContext,
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(24.0)),
),
builder: (context) => UpdateConfirmationDialog(
builder: (context) => UpdateConfirmationSheet(
isPatches: isPatches,
changelog: changelog,
),
);
}

View File

@ -39,6 +39,15 @@ class SettingsViewModel extends BaseViewModel {
notifyListeners();
}
bool showUpdateDialog() {
return _managerAPI.showUpdateDialog();
}
void setShowUpdateDialog(bool value) {
_managerAPI.setShowUpdateDialog(value);
notifyListeners();
}
bool isPatchesChangeEnabled() {
return _managerAPI.isPatchesChangeEnabled();
}

View File

@ -55,17 +55,15 @@ class _LatestCommitCardState extends State<LatestCommitCard> {
FutureBuilder<bool>(
future: model.hasManagerUpdates(),
initialData: false,
builder: (context, snapshot) => Opacity(
opacity: snapshot.hasData && snapshot.data! ? 1.0 : 0.25,
child: FilledButton(
onPressed: snapshot.hasData && snapshot.data!
? () => widget.model.showUpdateConfirmationDialog(
builder: (context, snapshot) => FilledButton(
onPressed: () => widget.model.showUpdateConfirmationDialog(
widget.parentContext,
false,
)
: () => {},
child: I18nText('updateButton'),
!snapshot.data!,
),
child: (snapshot.hasData && !snapshot.data!)
? I18nText('showChangelogButton')
: I18nText('showUpdateButton'),
),
),
],
@ -83,7 +81,7 @@ class _LatestCommitCardState extends State<LatestCommitCard> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text('Patches'),
const Text('ReVanced Patches'),
const SizedBox(height: 4),
Row(
children: <Widget>[
@ -108,19 +106,17 @@ class _LatestCommitCardState extends State<LatestCommitCard> {
),
),
FutureBuilder<bool>(
future: locator<HomeViewModel>().hasPatchesUpdates(),
future: model.hasPatchesUpdates(),
initialData: false,
builder: (context, snapshot) => Opacity(
opacity: snapshot.hasData && snapshot.data! ? 1.0 : 0.25,
child: FilledButton(
onPressed: snapshot.hasData && snapshot.data!
? () => widget.model.showUpdateConfirmationDialog(
builder: (context, snapshot) => FilledButton(
onPressed: () => widget.model.showUpdateConfirmationDialog(
widget.parentContext,
true,
)
: () => {},
child: I18nText('updateButton'),
!snapshot.data!,
),
child: (snapshot.hasData && !snapshot.data!)
? I18nText('showChangelogButton')
: I18nText('showUpdateButton'),
),
),
],

View File

@ -4,10 +4,11 @@ import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
class UpdateConfirmationDialog extends StatelessWidget {
const UpdateConfirmationDialog({super.key, required this.isPatches});
class UpdateConfirmationSheet extends StatelessWidget {
const UpdateConfirmationSheet({super.key, required this.isPatches, this.changelog = false});
final bool isPatches;
final bool changelog;
@override
Widget build(BuildContext context) {
final HomeViewModel model = locator<HomeViewModel>();
@ -36,6 +37,7 @@ class UpdateConfirmationDialog extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!changelog)
Padding(
padding: const EdgeInsets.only(
top: 40.0,
@ -51,8 +53,8 @@ class UpdateConfirmationDialog extends StatelessWidget {
children: [
I18nText(
isPatches
? 'homeView.updatePatchesDialogTitle'
: 'homeView.updateDialogTitle',
? 'homeView.updatePatchesSheetTitle'
: 'homeView.updateSheetTitle',
child: const Text(
'',
style: TextStyle(

View File

@ -7,6 +7,7 @@ import 'package:revanced_manager/ui/widgets/settingsView/settings_auto_update_pa
import 'package:revanced_manager/ui/widgets/settingsView/settings_enable_patches_selection.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_require_suggested_app_version.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_section.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_show_update_dialog.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_universal_patches.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_version_compatibility_check.dart';
@ -19,6 +20,7 @@ class SAdvancedSection extends StatelessWidget {
title: 'settingsView.advancedSectionTitle',
children: const <Widget>[
SAutoUpdatePatches(),
SShowUpdateDialog(),
SEnablePatchesSelection(),
SRequireSuggestedAppVersion(),
SVersionCompatibilityCheck(),

View File

@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/widgets/I18nText.dart';
import 'package:revanced_manager/ui/views/settings/settings_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/shared/haptics/haptic_switch_list_tile.dart';
class SShowUpdateDialog extends StatefulWidget {
const SShowUpdateDialog({super.key});
@override
State<SShowUpdateDialog> createState() => _SShowUpdateDialogState();
}
final _settingsViewModel = SettingsViewModel();
class _SShowUpdateDialogState extends State<SShowUpdateDialog> {
@override
Widget build(BuildContext context) {
return HapticSwitchListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20.0),
title: I18nText(
'settingsView.showUpdateDialogLabel',
child: const Text(
'',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
),
subtitle: I18nText('settingsView.showUpdateDialogHint'),
value: _settingsViewModel.showUpdateDialog(),
onChanged: (value) {
setState(() {
_settingsViewModel.setShowUpdateDialog(value);
});
},
);
}
}