Skip to content

Commit

Permalink
feat: select install type before patching
Browse files Browse the repository at this point in the history
  • Loading branch information
Aunali321 committed Apr 14, 2023
1 parent aa2fc03 commit 74e0c09
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 4 deletions.
8 changes: 6 additions & 2 deletions assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"disabledLabel": "Disabled",
"yesButton": "Yes",
"noButton": "No",
"rootLabel": "Root",
"nonRootLabel": "Non-root",
"selectInstallMethod": "Select install method",
"selectInstallMethodHint": "Selected patches are compatible with {installMethod} install only. {option} MicroG patch for {otherInstallMethod} install.",
"warning": "Warning",
"navigationView": {
"dashboardTab": "Dashboard",
Expand Down Expand Up @@ -104,8 +108,8 @@
"exportApkMenuOption": "Export APK",
"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.",
"installErrorDialogText1": "Root install is not possible with the current patches selection.\nUnselect MicroG patch to continue.",
"installErrorDialogText2": "Non-root install is not possible with the current patches selection.\nSelect MicroG patch to continue.",
"installErrorDialogText3": "Root install is not possible as the original APK was selected from storage.\nSelect an installed app or choose non-root install.",
"noExit": "Installer is still running, cannot exit..."
},
Expand Down
112 changes: 110 additions & 2 deletions lib/ui/views/patcher/patcher_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: use_build_context_synchronously

import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:injectable/injectable.dart';
Expand All @@ -7,6 +9,7 @@ import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/models/patched_application.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/services/toast.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
Expand All @@ -16,8 +19,12 @@ class PatcherViewModel extends BaseViewModel {
final NavigationService _navigationService = locator<NavigationService>();
final ManagerAPI _managerAPI = locator<ManagerAPI>();
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
final Toast _toast = locator<Toast>();
PatchedApplication? selectedApp;
List<Patch> selectedPatches = [];
late bool hasMicroGPatch = selectedPatches.any(
(patch) => patch.name.endsWith('microg-support'),
);

void navigateToAppSelector() {
_navigationService.navigateTo(Routes.appSelectorView);
Expand Down Expand Up @@ -52,9 +59,14 @@ class PatcherViewModel extends BaseViewModel {

Future<void> showPatchConfirmationDialog(BuildContext context) async {
final bool isValid = await isValidPatchConfig();

hasMicroGPatch = selectedPatches.any(
(patch) => patch.name.endsWith('microg-support'),
);

if (context.mounted) {
if (isValid) {
navigateToInstaller();
askForInstallationMethod(context);
} else {
return showDialog(
context: context,
Expand All @@ -72,7 +84,7 @@ class PatcherViewModel extends BaseViewModel {
label: I18nText('yesButton'),
onPressed: () {
Navigator.of(context).pop();
navigateToInstaller();
askForInstallationMethod(context);
},
)
],
Expand All @@ -82,6 +94,102 @@ class PatcherViewModel extends BaseViewModel {
}
}

Future<dynamic> askForInstallationMethod(BuildContext context) {
if (selectedApp!.packageName.contains('youtube')) {
final width = MediaQuery.of(context).size.width;
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: I18nText('selectInstallMethod'),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
content: I18nText(
!hasMicroGPatch
? FlutterI18n.translate(
context,
'selectInstallMethodHint',
translationParams: {
'installMethod': 'root',
'option': 'Select',
'otherInstallMethod': 'non-root',
},
)
: FlutterI18n.translate(
context,
'selectInstallMethodHint',
translationParams: {
'installMethod': 'non-root',
'option': 'Unselect',
'otherInstallMethod': 'root',
},
),
),
actions: <Widget>[
TextButton(
onPressed: () {
if (hasMicroGPatch) {
_toast.show(
'installerView.installErrorDialogText1',
);
hasMicroGPatch = true;
} else {
Navigator.of(context).pop();
navigateToInstaller();
}
},
style: ButtonStyle(
minimumSize: MaterialStateProperty.all<Size>(Size(width, 48)),
foregroundColor: MaterialStateProperty.all<Color>(
Theme.of(context).colorScheme.primary,
),
backgroundColor: MaterialStateProperty.all<Color>(
Theme.of(context).colorScheme.primary.withOpacity(0.1),
),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
),
),
child: I18nText('rootLabel'),
),
const SizedBox(height: 8),
TextButton(
style: ButtonStyle(
minimumSize: MaterialStateProperty.all<Size>(Size(width, 48)),
foregroundColor: MaterialStateProperty.all<Color>(
Theme.of(context).colorScheme.primary,
),
backgroundColor: MaterialStateProperty.all<Color>(
Theme.of(context).colorScheme.primary.withOpacity(0.1),
),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
),
),
child: I18nText('nonRootLabel'),
onPressed: () {
if (!hasMicroGPatch) {
_toast.show(
'installerView.installErrorDialogText2',
);
hasMicroGPatch = false;
} else {
Navigator.of(context).pop();
navigateToInstaller();
}
},
)
],
),
);
} else {
navigateToInstaller();
return Future.value();
}
}

String getAppSelectionString() {
String text = '${selectedApp!.name} (${selectedApp!.packageName})';
if (text.length > 32) {
Expand Down

0 comments on commit 74e0c09

Please sign in to comment.