From 48a739c94ecfb5a5ec93c2e3c634571610552d41 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 23 Dec 2023 20:53:51 +0100 Subject: [PATCH] refactor: Simplify `uninstallApp` code --- .../appInfoView/app_info_viewmodel.dart | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/ui/widgets/appInfoView/app_info_viewmodel.dart b/lib/ui/widgets/appInfoView/app_info_viewmodel.dart index d4274972..89069966 100644 --- a/lib/ui/widgets/appInfoView/app_info_viewmodel.dart +++ b/lib/ui/widgets/appInfoView/app_info_viewmodel.dart @@ -25,20 +25,16 @@ class AppInfoViewModel extends BaseViewModel { PatchedApplication app, bool onlyUnpatch, ) async { - bool isUninstalled = true; - if (app.isRooted) { - final bool hasRootPermissions = await _rootAPI.hasRootPermissions(); - if (hasRootPermissions) { - await _rootAPI.uninstall( - app.packageName, - ); - if (!onlyUnpatch) { - await DeviceApps.uninstallApp(app.packageName); - } - } - } else { + var isUninstalled = onlyUnpatch; + + if (!onlyUnpatch) { isUninstalled = await DeviceApps.uninstallApp(app.packageName); } + + if (isUninstalled && app.isRooted && await _rootAPI.hasRootPermissions()) { + await _rootAPI.uninstall(app.packageName); + } + if (isUninstalled) { await _managerAPI.deletePatchedApp(app); locator().initialize(context);