fix: Readd permission_handler with a proper fix

This commit is contained in:
Alberto Ponces 2022-09-18 22:13:29 +01:00
parent c5ad337daa
commit 9c5b0b9c14
3 changed files with 13 additions and 11 deletions

View File

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_background/flutter_background.dart'; import 'package:flutter_background/flutter_background.dart';
import 'package:flutter_i18n/flutter_i18n.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/app/app.locator.dart';
import 'package:revanced_manager/models/patch.dart'; import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/models/patched_application.dart'; import 'package:revanced_manager/models/patched_application.dart';
@ -30,7 +30,7 @@ class InstallerViewModel extends BaseViewModel {
bool hasErrors = false; bool hasErrors = false;
Future<void> initialize(BuildContext context) async { Future<void> initialize(BuildContext context) async {
if (true /*await Permission.ignoreBatteryOptimizations.isGranted*/) { if (await Permission.ignoreBatteryOptimizations.isGranted) {
try { try {
await FlutterBackground.initialize( await FlutterBackground.initialize(
androidConfig: FlutterBackgroundAndroidConfig( androidConfig: FlutterBackgroundAndroidConfig(
@ -122,7 +122,7 @@ class InstallerViewModel extends BaseViewModel {
hasErrors = true; hasErrors = true;
update(-1.0, 'Aborting...', 'No app or patches selected! Aborting'); update(-1.0, 'Aborting...', 'No app or patches selected! Aborting');
} }
if (true /*await Permission.ignoreBatteryOptimizations.isGranted*/) { if (await Permission.ignoreBatteryOptimizations.isGranted) {
try { try {
await FlutterBackground.disableBackgroundExecution(); await FlutterBackground.disableBackgroundExecution();
} on Exception { } on Exception {

View File

@ -3,7 +3,7 @@ import 'package:dynamic_themes/dynamic_themes.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:injectable/injectable.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/services/root_api.dart';
import 'package:revanced_manager/ui/views/home/home_view.dart'; import 'package:revanced_manager/ui/views/home/home_view.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_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 { class NavigationViewModel extends IndexTrackingViewModel {
void initialize(BuildContext context) async { void initialize(BuildContext context) async {
SharedPreferences prefs = await SharedPreferences.getInstance(); 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) { if (prefs.getBool('useDarkTheme') == null) {
bool isDark = bool isDark =
MediaQuery.of(context).platformBrightness != Brightness.light; MediaQuery.of(context).platformBrightness != Brightness.light;
@ -31,12 +39,6 @@ class NavigationViewModel extends IndexTrackingViewModel {
: Brightness.light, : Brightness.light,
), ),
); );
//if (prefs.getBool('permissionsRequested') == null) {
//await prefs.setBool('permissionsRequested', true);
RootAPI().hasRootPermissions();
//Permission.requestInstallPackages.request();
//Permission.ignoreBatteryOptimizations.request();
//}
} }
Widget getViewForIndex(int index) { Widget getViewForIndex(int index) {

View File

@ -52,7 +52,7 @@ dependencies:
ref: feature/nullSafe ref: feature/nullSafe
package_info_plus: ^1.4.3+1 package_info_plus: ^1.4.3+1
path_provider: ^2.0.11 path_provider: ^2.0.11
#permission_handler: ^10.0.0 permission_handler: ^10.0.0
pull_to_refresh: ^2.0.0 pull_to_refresh: ^2.0.0
root: ^2.0.2 root: ^2.0.2
share_extend: ^2.0.0 share_extend: ^2.0.0