Skip to content

Commit

Permalink
feat: Add a warning for split APK patching for now
Browse files Browse the repository at this point in the history
  • Loading branch information
ponces committed Sep 15, 2022
1 parent a82b0cd commit ec31667
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 12 deletions.
4 changes: 3 additions & 1 deletion assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
},
"patcherView": {
"widgetTitle": "Patcher",
"patchButton": "Patch"
"patchButton": "Patch",
"patchDialogTitle": "Warning",
"patchDialogText": "You have selected a resource patch and a split APK installation was detected so patching errors can occur.\nAre you sure you want to proceed with patching a split base APK?"
},
"appSelectorCard": {
"widgetTitle": "Select application",
Expand Down
30 changes: 21 additions & 9 deletions lib/services/patcher_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ class PatcherAPI {
.toList();
}

Future<bool> needsIntegrations(List<Patch> selectedPatches) async {
return selectedPatches.any(
(patch) => patch.dependencies.contains('integrations'),
);
}

Future<bool> needsResourcePatching(List<Patch> selectedPatches) async {
return selectedPatches.any(
(patch) => patch.dependencies.any((dep) => dep.contains('resource-')),
);
}

Future<bool> needsSettingsPatch(List<Patch> selectedPatches) async {
return selectedPatches.any(
(patch) => patch.dependencies.contains('settings'),
);
}

Future<String> getOriginalFilePath(
String packageName,
String originalFilePath,
Expand All @@ -101,15 +119,9 @@ class PatcherAPI {
String originalFilePath,
List<Patch> selectedPatches,
) async {
bool mergeIntegrations = selectedPatches.any(
(patch) => patch.dependencies.contains('integrations'),
);
bool resourcePatching = selectedPatches.any(
(patch) => patch.dependencies.any((dep) => dep.contains('resource-')),
);
bool includeSettings = selectedPatches.any(
(patch) => patch.dependencies.contains('settings'),
);
bool mergeIntegrations = await needsIntegrations(selectedPatches);
bool resourcePatching = await needsResourcePatching(selectedPatches);
bool includeSettings = await needsSettingsPatch(selectedPatches);
if (includeSettings) {
try {
Patch? settingsPatch = _patches.firstWhereOrNull(
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/views/patcher/patcher_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PatcherView extends StatelessWidget {
child: FloatingActionButton.extended(
label: I18nText('patcherView.patchButton'),
icon: const Icon(Icons.build),
onPressed: () => model.navigateToInstaller(),
onPressed: () => model.showPatchConfirmationDialog(context),
),
),
body: CustomScrollView(
Expand Down
48 changes: 48 additions & 0 deletions lib/ui/views/patcher/patcher_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import 'package:device_apps/device_apps.dart';
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:injectable/injectable.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/app/app.router.dart';
import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/models/patched_application.dart';
import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';

@lazySingleton
class PatcherViewModel extends BaseViewModel {
final NavigationService _navigationService = locator<NavigationService>();
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
PatchedApplication? selectedApp;
List<Patch> selectedPatches = [];

Expand All @@ -31,4 +37,46 @@ class PatcherViewModel extends BaseViewModel {
bool dimPatchesCard() {
return selectedApp == null;
}

Future<bool> isValidPatchConfig() async {
bool needsResourcePatching =
await _patcherAPI.needsResourcePatching(selectedPatches);
if (needsResourcePatching && selectedApp != null) {
Application? app = await DeviceApps.getApp(selectedApp!.packageName);
if (app != null && app.isSplit) {
return false;
}
}
return true;
}

Future<void> showPatchConfirmationDialog(BuildContext context) async {
bool isValid = await isValidPatchConfig();
if (isValid) {
navigateToInstaller();
} else {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: I18nText('patcherView.patchDialogTitle'),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
content: I18nText('patcherView.patchDialogText'),
actions: <Widget>[
CustomMaterialButton(
isFilled: false,
label: I18nText('cancelButton'),
onPressed: () => Navigator.of(context).pop(),
),
CustomMaterialButton(
label: I18nText('okButton'),
onPressed: () {
Navigator.of(context).pop();
navigateToInstaller();
},
)
],
),
);
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
device_apps:
git:
url: https://github.com/ponces/flutter_plugin_device_apps
ref: appinfo-from-storage
ref: revanced-manager
device_info_plus: ^4.1.2
dio: ^4.0.6
dio_http_cache_lts: ^0.4.1
Expand Down

0 comments on commit ec31667

Please sign in to comment.