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 {
|
2022-08-18 16:33:33 +02:00
|
|
|
final NavigationService _navigationService = locator<NavigationService>();
|
|
|
|
bool isRooted = false;
|
2022-08-14 16:03:01 +02:00
|
|
|
|
2022-09-01 02:25:19 +02:00
|
|
|
Future<void> navigateAsRoot() async {
|
2022-08-18 16:33:33 +02:00
|
|
|
bool? res = await Root.isRooted();
|
|
|
|
isRooted = res != null && res == true;
|
|
|
|
if (isRooted) {
|
2022-09-01 02:25:19 +02:00
|
|
|
await navigateToHome();
|
|
|
|
} else {
|
|
|
|
notifyListeners();
|
2022-08-14 20:40:34 +02:00
|
|
|
}
|
2022-09-01 02:25:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> navigateAsNonRoot() async {
|
|
|
|
isRooted = false;
|
|
|
|
await navigateToHome();
|
2022-08-14 16:03:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> navigateToHome() async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
2022-08-30 03:07:28 +02:00
|
|
|
await prefs.setBool('isRooted', isRooted);
|
2022-08-14 20:40:34 +02:00
|
|
|
_navigationService.navigateTo(Routes.navigation);
|
2022-08-14 16:03:01 +02:00
|
|
|
}
|
|
|
|
}
|