2022-08-14 19:33:01 +05:30
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
|
|
|
import 'package:revanced_manager/app/app.router.dart';
|
2022-09-05 03:32:36 +01:00
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
2022-08-14 19:33:01 +05:30
|
|
|
import 'package:stacked/stacked.dart';
|
|
|
|
import 'package:root/root.dart';
|
|
|
|
import 'package:stacked_services/stacked_services.dart';
|
|
|
|
|
|
|
|
class RootCheckerViewModel extends BaseViewModel {
|
2022-08-18 15:33:33 +01:00
|
|
|
final NavigationService _navigationService = locator<NavigationService>();
|
2022-09-05 03:32:36 +01:00
|
|
|
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
2022-08-18 15:33:33 +01:00
|
|
|
bool isRooted = false;
|
2022-08-14 19:33:01 +05:30
|
|
|
|
2022-09-05 09:14:56 +01:00
|
|
|
void initialize() {
|
|
|
|
isRooted = _managerAPI.isRooted() ?? false;
|
|
|
|
}
|
|
|
|
|
2022-09-01 01:25:19 +01:00
|
|
|
Future<void> navigateAsRoot() async {
|
2022-08-18 15:33:33 +01:00
|
|
|
bool? res = await Root.isRooted();
|
|
|
|
isRooted = res != null && res == true;
|
|
|
|
if (isRooted) {
|
2022-09-01 01:25:19 +01:00
|
|
|
await navigateToHome();
|
|
|
|
} else {
|
|
|
|
notifyListeners();
|
2022-08-14 19:40:34 +01:00
|
|
|
}
|
2022-09-01 01:25:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> navigateAsNonRoot() async {
|
|
|
|
isRooted = false;
|
|
|
|
await navigateToHome();
|
2022-08-14 19:33:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> navigateToHome() async {
|
2022-09-05 03:32:36 +01:00
|
|
|
_managerAPI.setIsRooted(isRooted);
|
2022-09-05 09:07:38 +01:00
|
|
|
_navigationService.navigateTo(Routes.navigationView);
|
2022-08-14 19:33:01 +05:30
|
|
|
}
|
|
|
|
}
|