Skip to content

Commit

Permalink
feat: Show a dialog when an update is available (#1654)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAabedKhan committed Jan 26, 2024
1 parent 7104d6d commit 34905a1
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 203 deletions.
26 changes: 18 additions & 8 deletions assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",

Expand All @@ -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...",

Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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)",

Expand Down
2 changes: 1 addition & 1 deletion lib/services/github_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
26 changes: 19 additions & 7 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions lib/services/revanced_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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');
Expand Down
14 changes: 1 addition & 13 deletions lib/services/root_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import 'package:flutter/foundation.dart';
import 'package:root/root.dart';

class RootAPI {
// TODO(aAbed): remove in the future, keep it for now during migration.
final String _postFsDataDirPath = '/data/adb/post-fs-data.d';

final String _revancedDirPath = '/data/adb/revanced';
final String _serviceDDirPath = '/data/adb/service.d';

Expand Down Expand Up @@ -99,18 +96,9 @@ class RootAPI {
);
}

// TODO(aAbed): remove in the future, keep it for now during migration.
Future<void> removeOrphanedFiles() async {
await Root.exec(
cmd: '''
find $_revancedDirPath -type f -name original.apk -delete
for file in "$_serviceDDirPath"/*; do
filename=\$(basename "\$file")
if [ -f "$_postFsDataDirPath/\$filename" ]; then
rm "$_postFsDataDirPath/\$filename"
fi
done
''',
cmd: 'find $_revancedDirPath -type f -name original.apk -delete',
);
}

Expand Down
Loading

0 comments on commit 34905a1

Please sign in to comment.