Skip to content

Commit

Permalink
feat: Hide "Install as Root" button if user does not have root access…
Browse files Browse the repository at this point in the history
… at all
  • Loading branch information
ponces committed Sep 23, 2022
1 parent c8c35ca commit 9561153
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/services/root_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ class RootAPI {
final String _postFsDataDirPath = '/data/adb/post-fs-data.d';
final String _serviceDDirPath = '/data/adb/service.d';

Future<bool> isRooted() async {
try {
bool? isRooted = await Root.isRootAvailable();
return isRooted != null && isRooted;
} on Exception {
return false;
}
}

Future<bool> hasRootPermissions() async {
try {
bool? isRooted = await Root.isRootAvailable();
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/views/installer/installer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class InstallerView extends StatelessWidget {
),
),
Visibility(
visible: !model.isInstalled,
visible: !model.isInstalled && model.isRooted,
child: CustomMaterialButton(
isFilled: false,
label:
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: use_build_context_synchronously
import 'package:device_apps/device_apps.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -9,6 +10,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/root_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';
Expand All @@ -18,6 +20,7 @@ import 'package:wakelock/wakelock.dart';
class InstallerViewModel extends BaseViewModel {
final ManagerAPI _managerAPI = locator<ManagerAPI>();
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
final RootAPI _rootAPI = RootAPI();
final Toast _toast = locator<Toast>();
final PatchedApplication _app = locator<PatcherViewModel>().selectedApp!;
final List<Patch> _patches = locator<PatcherViewModel>().selectedPatches;
Expand All @@ -28,11 +31,13 @@ class InstallerViewModel extends BaseViewModel {
double? progress = 0.0;
String logs = '';
String headerLogs = '';
bool isRooted = false;
bool isPatching = true;
bool isInstalled = false;
bool hasErrors = false;

Future<void> initialize(BuildContext context) async {
isRooted = await _rootAPI.isRooted();
if (await Permission.ignoreBatteryOptimizations.isGranted) {
try {
FlutterBackground.initialize(
Expand Down

0 comments on commit 9561153

Please sign in to comment.