Skip to content

Commit

Permalink
fix: Add Unpatch option on App Info view
Browse files Browse the repository at this point in the history
  • Loading branch information
ponces committed Sep 17, 2022
1 parent e74fce8 commit ef3685c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 25 deletions.
3 changes: 3 additions & 0 deletions assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@
"openButton": "Open",
"uninstallButton": "Uninstall",
"patchButton": "Patch",
"unpatchButton": "Unpatch",
"uninstallDialogTitle": "Uninstall",
"uninstallDialogText": "Are you sure you want to uninstall this app?",
"unpatchDialogTitle": "Unpatch",
"unpatchDialogText": "Are you sure you want to unpatch this app?",
"rootDialogTitle": "Error",
"rootDialogText": "App was installed with root mode enabled but currently root mode is disabled.\nPlease enable root mode first.",
"packageNameLabel": "Package Name",
Expand Down
48 changes: 45 additions & 3 deletions lib/ui/widgets/appInfoView/app_info_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AppInfoView extends StatelessWidget {
CustomCard(
child: IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
InkWell(
onTap: () => model.openApp(app),
Expand Down Expand Up @@ -96,8 +96,11 @@ class AppInfoView extends StatelessWidget {
color: Theme.of(context).canvasColor,
),
InkWell(
onTap: () =>
model.showUninstallAlertDialog(context, app),
onTap: () => model.showUninstallAlertDialog(
context,
app,
false,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expand Down Expand Up @@ -154,6 +157,45 @@ class AppInfoView extends StatelessWidget {
],
),
),
Visibility(
visible: app.isRooted,
child: VerticalDivider(
color: Theme.of(context).canvasColor,
),
),
Visibility(
visible: app.isRooted,
child: InkWell(
onTap: () => model.showUninstallAlertDialog(
context,
app,
true,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.settings_backup_restore_outlined,
color:
Theme.of(context).colorScheme.primary,
),
const SizedBox(height: 10),
I18nText(
'appInfoView.unpatchButton',
child: Text(
'',
style: TextStyle(
color: Theme.of(context)
.colorScheme
.primary,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
),
],
),
),
Expand Down
54 changes: 32 additions & 22 deletions lib/ui/widgets/appInfoView/app_info_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ class AppInfoViewModel extends BaseViewModel {
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
final RootAPI _rootAPI = RootAPI();

Future<void> uninstallApp(PatchedApplication app) async {
Future<void> uninstallApp(PatchedApplication app, bool onlyUnpatch) async {
if (app.isRooted) {
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
_rootAPI.deleteApp(app.packageName, app.apkFilePath);
_managerAPI.deletePatchedApp(app);
if (!onlyUnpatch) {
DeviceApps.uninstallApp(app.packageName);
}
}
} else {
DeviceApps.uninstallApp(app.packageName);
Expand All @@ -43,32 +46,39 @@ class AppInfoViewModel extends BaseViewModel {
Future<void> showUninstallAlertDialog(
BuildContext context,
PatchedApplication app,
bool onlyUnpatch,
) async {
if (app.isRooted) {
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
if (!hasRootPermissions) {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: I18nText('appInfoView.rootDialogTitle'),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
content: I18nText('appInfoView.rootDialogText'),
actions: <Widget>[
CustomMaterialButton(
label: I18nText('okButton'),
onPressed: () => Navigator.of(context).pop(),
)
],
),
);
}
bool hasRootPermissions = await _rootAPI.hasRootPermissions();
if (app.isRooted && !hasRootPermissions) {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: I18nText('appInfoView.rootDialogTitle'),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
content: I18nText('appInfoView.rootDialogText'),
actions: <Widget>[
CustomMaterialButton(
label: I18nText('okButton'),
onPressed: () => Navigator.of(context).pop(),
)
],
),
);
} else {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: I18nText('appInfoView.uninstallDialogTitle'),
title: I18nText(
onlyUnpatch
? 'appInfoView.unpatchDialogTitle'
: 'appInfoView.uninstallDialogTitle',
),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
content: I18nText('appInfoView.uninstallDialogText'),
content: I18nText(
onlyUnpatch
? 'appInfoView.unpatchDialogText'
: 'appInfoView.uninstallDialogText',
),
actions: <Widget>[
CustomMaterialButton(
isFilled: false,
Expand All @@ -78,7 +88,7 @@ class AppInfoViewModel extends BaseViewModel {
CustomMaterialButton(
label: I18nText('okButton'),
onPressed: () {
uninstallApp(app);
uninstallApp(app, onlyUnpatch);
locator<HomeViewModel>().initialize(context);
Navigator.of(context).pop();
Navigator.of(context).pop();
Expand Down

0 comments on commit ef3685c

Please sign in to comment.