feat: Add install error dialogs to prevent faulty installations

This commit is contained in:
Alberto Ponces 2022-09-19 01:44:27 +01:00
parent 6c2ceed91f
commit 2f14746124
5 changed files with 65 additions and 23 deletions

View File

@ -89,7 +89,11 @@
"notificationTitle": "ReVanced Manager is patching", "notificationTitle": "ReVanced Manager is patching",
"notificationText": "Tap to return to the installer", "notificationText": "Tap to return to the installer",
"shareApkMenuOption": "Share APK", "shareApkMenuOption": "Share APK",
"shareLogMenuOption": "Share log" "shareLogMenuOption": "Share log",
"installErrorDialogTitle": "Error",
"installErrorDialogText1": "Root install is not possible with the current patches selection.\nRepatch your app or choose non-root install.",
"installErrorDialogText2": "Non-root install is not possible with the current patches selection.\nRepatch your app or choose root install if you have your device rooted.",
"installErrorDialogText3": "Root install is not possible as the original APK was selected from storage.\nSelect an installed app or choose non-root install."
}, },
"settingsView": { "settingsView": {
"widgetTitle": "Settings", "widgetTitle": "Settings",

View File

@ -17,6 +17,7 @@ class PatchedApplication {
Uint8List icon; Uint8List icon;
DateTime patchDate; DateTime patchDate;
bool isRooted; bool isRooted;
bool isFromStorage;
bool hasUpdates; bool hasUpdates;
List<String> appliedPatches; List<String> appliedPatches;
List<String> changelog; List<String> changelog;
@ -29,6 +30,7 @@ class PatchedApplication {
required this.icon, required this.icon,
required this.patchDate, required this.patchDate,
this.isRooted = false, this.isRooted = false,
this.isFromStorage = false,
this.hasUpdates = false, this.hasUpdates = false,
this.appliedPatches = const [], this.appliedPatches = const [],
this.changelog = const [], this.changelog = const [],

View File

@ -54,6 +54,7 @@ class AppSelectorViewModel extends BaseViewModel {
apkFilePath: result.files.single.path!, apkFilePath: result.files.single.path!,
icon: application.icon, icon: application.icon,
patchDate: DateTime.now(), patchDate: DateTime.now(),
isFromStorage: true,
); );
locator<PatcherViewModel>().selectedPatches.clear(); locator<PatcherViewModel>().selectedPatches.clear();
locator<PatcherViewModel>().notifyListeners(); locator<PatcherViewModel>().notifyListeners();

View File

@ -111,7 +111,10 @@ class InstallerView extends StatelessWidget {
label: label:
I18nText('installerView.installRootButton'), I18nText('installerView.installRootButton'),
isExpanded: true, isExpanded: true,
onPressed: () => model.installResult(true), onPressed: () => model.installResult(
context,
true,
),
), ),
), ),
Visibility( Visibility(
@ -125,7 +128,10 @@ class InstallerView extends StatelessWidget {
child: CustomMaterialButton( child: CustomMaterialButton(
label: I18nText('installerView.installButton'), label: I18nText('installerView.installButton'),
isExpanded: true, isExpanded: true,
onPressed: () => model.installResult(false), onPressed: () => model.installResult(
context,
false,
),
), ),
), ),
], ],

View File

@ -10,6 +10,7 @@ import 'package:revanced_manager/models/patched_application.dart';
import 'package:revanced_manager/services/manager_api.dart'; import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/patcher_api.dart'; import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart';
import 'package:stacked/stacked.dart'; import 'package:stacked/stacked.dart';
import 'package:wakelock/wakelock.dart'; import 'package:wakelock/wakelock.dart';
@ -133,28 +134,56 @@ class InstallerViewModel extends BaseViewModel {
isPatching = false; isPatching = false;
} }
void installResult(bool installAsRoot) async { void installResult(BuildContext context, bool installAsRoot) async {
_app.isRooted = installAsRoot; _app.isRooted = installAsRoot;
update( bool hasMicroG = _patches.any((p) => p.name.endsWith('microg-support'));
1.0, bool rootMicroG = installAsRoot && hasMicroG;
'Installing...', bool rootFromStorage = installAsRoot && _app.isFromStorage;
_app.isRooted bool ytWithoutRootMicroG =
? 'Installing patched file using root method' !installAsRoot && !hasMicroG && _app.packageName.contains('youtube');
: 'Installing patched file using nonroot method', if (rootMicroG || rootFromStorage || ytWithoutRootMicroG) {
); return showDialog(
isInstalled = await _patcherAPI.installPatchedFile(_app); context: context,
if (isInstalled) { builder: (context) => AlertDialog(
update(1.0, 'Installed!', 'Installed!'); title: I18nText('installerView.installErrorDialogTitle'),
_app.patchDate = DateTime.now(); backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
_app.appliedPatches = _patches.map((p) => p.name).toList(); content: I18nText(
bool hasMicroG = _patches.any((p) => p.name.endsWith('microg-support')); rootMicroG
if (hasMicroG) { ? 'installerView.installErrorDialogText1'
_app.packageName = _app.packageName.replaceFirst( : rootFromStorage
'com.google.', ? 'installerView.installErrorDialogText3'
'app.revanced.', : 'installerView.installErrorDialogText2',
); ),
actions: <Widget>[
CustomMaterialButton(
label: I18nText('okButton'),
onPressed: () => Navigator.of(context).pop(),
)
],
),
);
} else {
update(
1.0,
'Installing...',
_app.isRooted
? 'Installing patched file using root method'
: 'Installing patched file using nonroot method',
);
isInstalled = await _patcherAPI.installPatchedFile(_app);
if (isInstalled) {
update(1.0, 'Installed!', 'Installed!');
_app.isFromStorage = false;
_app.patchDate = DateTime.now();
_app.appliedPatches = _patches.map((p) => p.name).toList();
if (hasMicroG) {
_app.packageName = _app.packageName.replaceFirst(
'com.google.',
'app.revanced.',
);
}
await _managerAPI.savePatchedApp(_app);
} }
await _managerAPI.savePatchedApp(_app);
} }
} }