From 9c5b0b9c14f382274909c776a2fa88028ab3c25b Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Sun, 18 Sep 2022 22:13:29 +0100 Subject: [PATCH] fix: Readd `permission_handler` with a proper fix --- lib/ui/views/installer/installer_viewmodel.dart | 6 +++--- .../views/navigation/navigation_viewmodel.dart | 16 +++++++++------- pubspec.yaml | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 4a79d9a7..877784d0 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_background/flutter_background.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; -//import 'package:permission_handler/permission_handler.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:revanced_manager/app/app.locator.dart'; import 'package:revanced_manager/models/patch.dart'; import 'package:revanced_manager/models/patched_application.dart'; @@ -30,7 +30,7 @@ class InstallerViewModel extends BaseViewModel { bool hasErrors = false; Future initialize(BuildContext context) async { - if (true /*await Permission.ignoreBatteryOptimizations.isGranted*/) { + if (await Permission.ignoreBatteryOptimizations.isGranted) { try { await FlutterBackground.initialize( androidConfig: FlutterBackgroundAndroidConfig( @@ -122,7 +122,7 @@ class InstallerViewModel extends BaseViewModel { hasErrors = true; update(-1.0, 'Aborting...', 'No app or patches selected! Aborting'); } - if (true /*await Permission.ignoreBatteryOptimizations.isGranted*/) { + if (await Permission.ignoreBatteryOptimizations.isGranted) { try { await FlutterBackground.disableBackgroundExecution(); } on Exception { diff --git a/lib/ui/views/navigation/navigation_viewmodel.dart b/lib/ui/views/navigation/navigation_viewmodel.dart index 2791fbf3..434380d4 100644 --- a/lib/ui/views/navigation/navigation_viewmodel.dart +++ b/lib/ui/views/navigation/navigation_viewmodel.dart @@ -3,7 +3,7 @@ import 'package:dynamic_themes/dynamic_themes.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:injectable/injectable.dart'; -//import 'package:permission_handler/permission_handler.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:revanced_manager/services/root_api.dart'; import 'package:revanced_manager/ui/views/home/home_view.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_view.dart'; @@ -15,6 +15,14 @@ import 'package:stacked/stacked.dart'; class NavigationViewModel extends IndexTrackingViewModel { void initialize(BuildContext context) async { SharedPreferences prefs = await SharedPreferences.getInstance(); + if (prefs.getBool('permissionsRequested') == null) { + await prefs.setBool('permissionsRequested', true); + RootAPI().hasRootPermissions().then( + (value) => Permission.requestInstallPackages.request().then( + (value) => Permission.ignoreBatteryOptimizations.request(), + ), + ); + } if (prefs.getBool('useDarkTheme') == null) { bool isDark = MediaQuery.of(context).platformBrightness != Brightness.light; @@ -31,12 +39,6 @@ class NavigationViewModel extends IndexTrackingViewModel { : Brightness.light, ), ); - //if (prefs.getBool('permissionsRequested') == null) { - //await prefs.setBool('permissionsRequested', true); - RootAPI().hasRootPermissions(); - //Permission.requestInstallPackages.request(); - //Permission.ignoreBatteryOptimizations.request(); - //} } Widget getViewForIndex(int index) { diff --git a/pubspec.yaml b/pubspec.yaml index 13bdd65d..edb015ef 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -52,7 +52,7 @@ dependencies: ref: feature/nullSafe package_info_plus: ^1.4.3+1 path_provider: ^2.0.11 - #permission_handler: ^10.0.0 + permission_handler: ^10.0.0 pull_to_refresh: ^2.0.0 root: ^2.0.2 share_extend: ^2.0.0