Skip to content

Commit

Permalink
chore: merge dev branch to main branch (#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ushie authored Aug 8, 2023
2 parents 3cf06ef + 722a585 commit 055c521
Show file tree
Hide file tree
Showing 26 changed files with 297 additions and 102 deletions.
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ linter:
- flutter_style_todos
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- collection_methods_unrelated_type
- leading_newlines_in_multiline_strings
- library_names
- library_prefixes
- library_private_types_in_public_api
- list_remove_unrelated_type
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_duplicate_case_values
Expand Down
15 changes: 10 additions & 5 deletions assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"yesButton": "Yes",
"noButton": "No",
"warning": "Warning",
"new": "New",
"navigationView": {
"dashboardTab": "Dashboard",
"patcherTab": "Patcher",
Expand All @@ -33,10 +34,10 @@
"updatePatchesDialogTitle": "Update ReVanced Patches",
"updateChangelogTitle": "Changelog",

"patchesConsentDialogText": "ReVanced Patches need to be downloaded to patch apps.",
"patchesConsentDialogText2": "This will reveal your IP address to {url}.",
"patchesConsentDialogText3": "Auto update",
"patchesConsentDialogText3Sub": "You can still change this in the settings later",
"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.",

"notificationTitle": "Update downloaded",
"notificationText": "Tap to install the update",
Expand Down Expand Up @@ -112,6 +113,7 @@
"patchesSelectorView": {
"viewTitle": "Select patches",
"searchBarHint": "Search patches",
"universalPatches": "Universal patches",

"doneButton": "Done",

Expand All @@ -129,7 +131,10 @@
},
"patchItem": {
"unsupportedDialogText": "Selecting this patch may result in patching errors.\n\nApp version: {packageVersion}\nSupported versions:\n{supportedVersions}",
"unsupportedPatchVersion": "Patch is not supported for this app version. Enable the experimental toggle in settings to proceed."
"unsupportedPatchVersion": "Patch is not supported for this app version. Enable the experimental toggle in settings to proceed.",

"newPatchDialogText": "This is a new patch that has been added since the last time you have patched this app.",
"newPatch": "New patch"
},
"installerView": {
"widgetTitle": "Installer",
Expand Down
5 changes: 2 additions & 3 deletions docs/2_2_managing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ After patching an app, you may want to manage it. This page will guide you throu
## 🪜 Steps to manage patched apps

1. Tap on the **Dashboard** tab in the bottom navigation bar
2. Select the **Installed** chip
3. Tap on the **Info** button for the app you want to manage
4. Choose one of the options from the menu
2. Tap on the **Info** button for the app you want to manage
3. Choose one of the options from the menu

## ⏭️ What's next

Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class MyApp extends StatelessWidget {
},
),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
GlobalWidgetsLocalizations.delegate,
],
);
}
Expand Down
68 changes: 58 additions & 10 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ class ManagerAPI {
String keystoreFile =
'/sdcard/Android/data/app.revanced.manager.flutter/files/revanced-manager.keystore';
String defaultKeystorePassword = 's3cur3p@ssw0rd';
String defaultApiUrl = 'https://releases.revanced.app/';
String defaultApiUrl = 'https://api.revanced.app/';
String defaultRepoUrl = 'https://api.github.com';
String defaultPatcherRepo = 'revanced/revanced-patcher';
String defaultPatchesRepo = 'revanced/revanced-patches';
String defaultIntegrationsRepo = 'revanced/revanced-integrations';
String defaultCliRepo = 'revanced/revanced-cli';
String defaultManagerRepo = 'revanced/revanced-manager';
String? patchesVersion = '';
String? integrationsVersion = '';
bool isDefaultPatchesRepo() {
return getPatchesRepo() == 'revanced/revanced-patches';
}

bool isDefaultIntegrationsRepo() {
return getIntegrationsRepo() == 'revanced/revanced-integrations';
}

Future<void> initialize() async {
_prefs = await SharedPreferences.getInstance();
isRooted = await _rootAPI.isRooted();
Expand Down Expand Up @@ -98,6 +103,21 @@ class ManagerAPI {
await _prefs.setBool('patchesAutoUpdate', value);
}

List<Patch> getSavedPatches(String packageName) {
final List<String> patchesJson = _prefs.getStringList('savedPatches-$packageName') ?? [];
final List<Patch> patches = patchesJson.map((String patchJson) {
return Patch.fromJson(jsonDecode(patchJson));
}).toList();
return patches;
}

Future<void> savePatches(List<Patch> patches, String packageName) async {
final List<String> patchesJson = patches.map((Patch patch) {
return jsonEncode(patch.toJson());
}).toList();
await _prefs.setStringList('savedPatches-$packageName', patchesJson);
}

String getIntegrationsRepo() {
return _prefs.getString('integrationsRepo') ?? defaultIntegrationsRepo;
}
Expand Down Expand Up @@ -252,14 +272,12 @@ class ManagerAPI {
Future<File?> downloadIntegrations() async {
try {
final String repoName = getIntegrationsRepo();
if (repoName == defaultIntegrationsRepo) {
return await _revancedAPI.getLatestReleaseFile(
'.apk',
defaultIntegrationsRepo,
);
} else {
return await _githubAPI.getLatestReleaseFile('.apk', repoName);
}
final String currentVersion = await getCurrentIntegrationsVersion();
return await _githubAPI.getPatchesReleaseFile(
'.apk',
repoName,
currentVersion,
);
} on Exception catch (e) {
if (kDebugMode) {
print(e);
Expand Down Expand Up @@ -308,14 +326,31 @@ class ManagerAPI {
);
}

Future<String?> getLatestIntegrationsVersion() async {
if (isDefaultIntegrationsRepo()) {
return await _revancedAPI.getLatestReleaseVersion(
'.apk',
defaultIntegrationsRepo,
);
} else {
final release = await _githubAPI.getLatestRelease(getIntegrationsRepo());
if (release != null) {
return release['tag_name'];
} else {
return null;
}
}
}

Future<String?> getLatestPatchesVersion() async {
if (isDefaultPatchesRepo()) {
return await _revancedAPI.getLatestReleaseVersion(
'.json',
defaultPatchesRepo,
);
} else {
final release = await _githubAPI.getLatestPatchesRelease(getPatchesRepo());
final release =
await _githubAPI.getLatestPatchesRelease(getPatchesRepo());
if (release != null) {
return release['tag_name'];
} else {
Expand All @@ -342,6 +377,19 @@ class ManagerAPI {
await _prefs.setString('patchesVersion', version);
}

Future<String> getCurrentIntegrationsVersion() async {
integrationsVersion = _prefs.getString('integrationsVersion') ?? '0.0.0';
if (integrationsVersion == '0.0.0' || isPatchesAutoUpdate()) {
integrationsVersion = await getLatestIntegrationsVersion() ?? '0.0.0';
await setCurrentIntegrationsVersion(integrationsVersion!);
}
return integrationsVersion!;
}

Future<void> setCurrentIntegrationsVersion(String version) async {
await _prefs.setString('integrationsVersion', version);
}

Future<List<PatchedApplication>> getAppsToRemove(
List<PatchedApplication> patchedApps,
) async {
Expand Down
22 changes: 13 additions & 9 deletions lib/services/patcher_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,20 @@ class PatcherAPI {
}

List<Patch> getFilteredPatches(String packageName) {
if (!filteredPatches.keys.contains(packageName)) {
final List<Patch> patches = _patches
.where(
(patch) =>
patch.compatiblePackages.isEmpty ||
!patch.name.contains('settings') &&
patch.compatiblePackages
.any((pack) => pack.name == packageName),
)
final List<Patch> patches = _patches
.where(
(patch) =>
patch.compatiblePackages.isEmpty ||
!patch.name.contains('settings') &&
patch.compatiblePackages
.any((pack) => pack.name == packageName),
)
.toList();
if (!_managerAPI.areUniversalPatchesEnabled()) {
filteredPatches[packageName] = patches
.where((patch) => patch.compatiblePackages.isNotEmpty)
.toList();
} else {
filteredPatches[packageName] = patches;
}
return filteredPatches[packageName];
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/views/contributors/contributors_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ContributorsView extends StatelessWidget {
title: 'contributorsView.managerContributors',
contributors: model.managerContributors,
),
SizedBox(height: MediaQuery.of(context).viewPadding.bottom)
SizedBox(height: MediaQuery.of(context).viewPadding.bottom),
],
),
),
Expand Down
25 changes: 17 additions & 8 deletions lib/ui/views/home/home_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class HomeViewModel extends BaseViewModel {

Future<void> initialize(BuildContext context) async {
_latestManagerVersion = await _managerAPI.getLatestManagerVersion();
if(!_managerAPI.getPatchesConsent()){
if (!_managerAPI.getPatchesConsent()) {
await showPatchesConsent(context);
}
await _patcherAPI.initialize();
Expand Down Expand Up @@ -168,13 +168,13 @@ class HomeViewModel extends BaseViewModel {
}
}

Future<void> showPatchesConsent(BuildContext context) async{
Future<void> showPatchesConsent(BuildContext context) async {
final ValueNotifier<bool> autoUpdate = ValueNotifier(true);
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: const Text('ReVanced Patches'),
title: const Text('Download ReVanced Patches?'),
content: ValueListenableBuilder(
valueListenable: autoUpdate,
builder: (context, value, child) {
Expand All @@ -197,7 +197,9 @@ class HomeViewModel extends BaseViewModel {
padding: const EdgeInsets.symmetric(vertical: 10),
child: I18nText(
'homeView.patchesConsentDialogText2',
translationParams: {'url': _managerAPI.defaultApiUrl.split('/')[2]},
translationParams: {
'url': _managerAPI.defaultApiUrl.split('/')[2],
},
child: Text(
'',
style: TextStyle(
Expand All @@ -211,8 +213,12 @@ class HomeViewModel extends BaseViewModel {
CheckboxListTile(
value: value,
contentPadding: EdgeInsets.zero,
title: I18nText('homeView.patchesConsentDialogText3',),
subtitle: I18nText('homeView.patchesConsentDialogText3Sub',),
title: I18nText(
'homeView.patchesConsentDialogText3',
),
subtitle: I18nText(
'homeView.patchesConsentDialogText3Sub',
),
onChanged: (selected) {
autoUpdate.value = selected!;
},
Expand All @@ -237,7 +243,7 @@ class HomeViewModel extends BaseViewModel {
Navigator.of(context).pop();
},
label: I18nText('okButton'),
)
),
],
),
);
Expand All @@ -247,9 +253,12 @@ class HomeViewModel extends BaseViewModel {
_toast.showBottom('homeView.downloadingMessage');
final String patchesVersion =
await _managerAPI.getLatestPatchesVersion() ?? '0.0.0';
if (patchesVersion != '0.0.0') {
final String integrationsVersion =
await _managerAPI.getLatestIntegrationsVersion() ?? '0.0.0';
if (patchesVersion != '0.0.0' && integrationsVersion != '0.0.0') {
_toast.showBottom('homeView.downloadedMessage');
await _managerAPI.setCurrentPatchesVersion(patchesVersion);
await _managerAPI.setCurrentIntegrationsVersion(integrationsVersion);
forceRefresh(context);
} else {
_toast.showBottom('homeView.errorDownloadMessage');
Expand Down
8 changes: 6 additions & 2 deletions lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class InstallerViewModel extends BaseViewModel {
});
}

void update(double value, String header, String log) {
Future<void> update(double value, String header, String log) async {
if (value >= 0.0) {
progress = value;
}
Expand All @@ -97,6 +97,10 @@ class InstallerViewModel extends BaseViewModel {
} else if (value == 1.0) {
isPatching = false;
hasErrors = false;
await _managerAPI.savePatches(
_patcherAPI.getFilteredPatches(_app.packageName),
_app.packageName,
);
} else if (value == -100.0) {
isPatching = false;
hasErrors = true;
Expand Down Expand Up @@ -203,7 +207,7 @@ class InstallerViewModel extends BaseViewModel {
CustomMaterialButton(
label: I18nText('okButton'),
onPressed: () => Navigator.of(context).pop(),
)
),
],
),
);
Expand Down
13 changes: 11 additions & 2 deletions lib/ui/views/patcher/patcher_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:revanced_manager/utils/about_info.dart';
import 'package:revanced_manager/utils/check_for_supported_patch.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';

Expand Down Expand Up @@ -77,7 +78,7 @@ class PatcherViewModel extends BaseViewModel {
Navigator.of(context).pop();
showArmv7WarningDialog(context);
},
)
),
],
),
);
Expand Down Expand Up @@ -110,7 +111,7 @@ class PatcherViewModel extends BaseViewModel {
Navigator.of(context).pop();
navigateToInstaller();
},
)
),
],
),
);
Expand Down Expand Up @@ -156,6 +157,14 @@ class PatcherViewModel extends BaseViewModel {
this
.selectedPatches
.addAll(patches.where((patch) => selectedPatches.contains(patch.name)));
if (!_managerAPI.areExperimentalPatchesEnabled()) {
this.selectedPatches.removeWhere((patch) => !isPatchSupported(patch));
}
if (!_managerAPI.areUniversalPatchesEnabled()) {
this
.selectedPatches
.removeWhere((patch) => patch.compatiblePackages.isEmpty);
}
notifyListeners();
}
}
Loading

0 comments on commit 055c521

Please sign in to comment.