revanced-manager/lib/ui/views/root_checker/root_checker_viewmodel.dart

41 lines
1.1 KiB
Dart
Raw Normal View History

2022-08-14 16:03:01 +02:00
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/app/app.router.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:stacked/stacked.dart';
import 'package:root/root.dart';
import 'package:stacked_services/stacked_services.dart';
class RootCheckerViewModel extends BaseViewModel {
final _navigationService = locator<NavigationService>();
bool? isRooted = false;
Future<void> initialize() async {
await checkRoot();
notifyListeners();
}
Future<void> checkRoot() async {
isRooted = await Root.isRooted();
2022-08-14 20:40:34 +02:00
if (isRooted == true) {
navigateToHome();
}
2022-08-14 16:03:01 +02:00
notifyListeners();
}
2022-08-14 20:40:34 +02:00
Future<bool> getMagiskPermissions() async {
try {
await Root.exec(cmd: 'cat /proc/version');
} on Exception {
return false;
2022-08-14 16:03:01 +02:00
}
2022-08-14 20:40:34 +02:00
return true;
2022-08-14 16:03:01 +02:00
}
Future<void> navigateToHome() async {
final prefs = await SharedPreferences.getInstance();
2022-08-14 20:40:34 +02:00
prefs.setBool('isRooted', isRooted!);
_navigationService.navigateTo(Routes.navigation);
2022-08-14 16:03:01 +02:00
notifyListeners();
}
}