From bb681e31c9c4e8a5b7b0c883edd1bc5c28505627 Mon Sep 17 00:00:00 2001 From: Aunali321 Date: Thu, 20 Apr 2023 22:25:29 +0530 Subject: [PATCH] feat: disable selecting installed apps for nonroot --- lib/services/manager_api.dart | 2 + .../views/app_selector/app_selector_view.dart | 10 +++- .../app_selector/app_selector_viewmodel.dart | 57 +++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index 85900b55..615f37b0 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -22,6 +22,7 @@ class ManagerAPI { final String patcherRepo = 'revanced-patcher'; final String cliRepo = 'revanced-cli'; late SharedPreferences _prefs; + bool isRooted = false; String storedPatchesFile = '/selected-patches.json'; String keystoreFile = '/sdcard/Android/data/app.revanced.manager.flutter/files/revanced-manager.keystore'; @@ -40,6 +41,7 @@ class ManagerAPI { Future initialize() async { _prefs = await SharedPreferences.getInstance(); + isRooted = await _rootAPI.isRooted(); storedPatchesFile = (await getApplicationDocumentsDirectory()).path + storedPatchesFile; } diff --git a/lib/ui/views/app_selector/app_selector_view.dart b/lib/ui/views/app_selector/app_selector_view.dart index 26d3218f..2509eb9a 100644 --- a/lib/ui/views/app_selector/app_selector_view.dart +++ b/lib/ui/views/app_selector/app_selector_view.dart @@ -109,8 +109,14 @@ class _AppSelectorViewState extends State { app.packageName, ), onTap: () { - model.selectApp(app); - Navigator.of(context).pop(); + model.isRooted + ? model.selectApp(app).then( + (_) => Navigator.of(context) + .pop(), + ) + : model.showSelectFromStorageDialog( + context, + ); }, ), ) diff --git a/lib/ui/views/app_selector/app_selector_viewmodel.dart b/lib/ui/views/app_selector/app_selector_viewmodel.dart index bcc58099..b0dbbb01 100644 --- a/lib/ui/views/app_selector/app_selector_viewmodel.dart +++ b/lib/ui/views/app_selector/app_selector_viewmodel.dart @@ -4,6 +4,7 @@ import 'package:device_apps/device_apps.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:revanced_manager/app/app.locator.dart'; import 'package:revanced_manager/models/patch.dart'; import 'package:revanced_manager/models/patched_application.dart'; @@ -12,6 +13,7 @@ import 'package:revanced_manager/services/patcher_api.dart'; import 'package:revanced_manager/services/revanced_api.dart'; import 'package:revanced_manager/services/toast.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:stacked/stacked.dart'; class AppSelectorViewModel extends BaseViewModel { @@ -22,6 +24,7 @@ class AppSelectorViewModel extends BaseViewModel { final List apps = []; List allApps = []; bool noApps = false; + bool isRooted = false; int patchesCount(String packageName) { return _patcherAPI.getFilteredPatches(packageName).length; } @@ -30,6 +33,7 @@ class AppSelectorViewModel extends BaseViewModel { Future initialize() async { patches = await _revancedAPI.getPatches(); + isRooted = _managerAPI.isRooted; apps.addAll( await _patcherAPI @@ -74,6 +78,59 @@ class AppSelectorViewModel extends BaseViewModel { locator().loadLastSelectedPatches(); } + Future showSelectFromStorageDialog(BuildContext context) async { + return showDialog( + context: context, + builder: (context) => SimpleDialog( + alignment: Alignment.center, + contentPadding: + const EdgeInsets.symmetric(horizontal: 20, vertical: 20), + children: [ + const SizedBox(height: 10), + Icon( + Icons.block, + size: 28, + color: Theme.of(context).colorScheme.primary, + ), + const SizedBox(height: 20), + const Text( + 'Feature not yet implented', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w600, + wordSpacing: 1.5, + ), + ), + const SizedBox(height: 20), + const Text( + "This feature has not been added yet for non-root. You'll need to select APK files from storage for now.", + style: TextStyle( + fontSize: 14, + ), + ), + const SizedBox(height: 30), + CustomMaterialButton( + onPressed: () => selectAppFromStorage(context).then( + (_) { + Navigator.pop(context); + Navigator.pop(context); + }, + ), + label: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.sd_card), + const SizedBox(width: 10), + I18nText('Select from storage'), + ], + ), + ), + ], + ), + ); + } + Future selectAppFromStorage(BuildContext context) async { try { final FilePickerResult? result = await FilePicker.platform.pickFiles(