feat: Root checker screen.

This commit is contained in:
Aunali321 2022-08-14 19:33:01 +05:30
parent f3383393ef
commit 6061d900ed
10 changed files with 236 additions and 3 deletions

View File

@ -66,5 +66,10 @@
"versionLabel": "Version", "versionLabel": "Version",
"aboutLabel": "About", "aboutLabel": "About",
"contributorsLabel": "Contributors" "contributorsLabel": "Contributors"
},
"rootCheckerView": {
"widgetTitle": "Is your device rooted?",
"widgetDescription": "Don't know what's this or prefer to use non-root version? Just click button below!",
"grantPermission": "Grant Root Permission"
} }
} }

1
assets/images/magisk.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" viewBox="0 0 24 24"><path d="M5.974,13.795c0.859,0.36,0.403-0.902,1.934-2.048c0.862-0.646,3.412-2.486,2.871-2.105V9.641c-2.766,1.951-5.64,1.714-6.959-2.528C3.586,6.361,3.08,12.582,5.974,13.795z"/><path d="M2.565 12.358c-.39-.546.967 3.514 4.365 3.563 2.49.036 2.78-2.408 4.44-2.482.501-.022.608-.808.63-1.067-.004-.045-.005-.077-.005-.077s.009-.009.012-.012c-.001-.001-.715-.774-1.617-.517l-.001.001c-1.522.434-2.113 2.523-3.649 2.781-.318.053-.675.148-1.092.128C4.867 14.639 3.881 14.204 2.565 12.358zM18.016 13.795c2.893-1.212 2.387-7.434 2.154-6.682-1.319 4.242-4.193 4.48-6.959 2.528-.54-.381 2.009 1.459 2.871 2.105v.001C17.613 12.893 17.156 14.155 18.016 13.795z"/><path d="M12 12.372c.02.248.123 1.056.631 1.079 1.66.074 1.95 2.518 4.44 2.482 3.399-.049 4.755-4.109 4.365-3.563-1.317 1.846-2.302 2.281-3.082 2.318-.417.02-.774-.075-1.092-.128-1.536-.258-2.127-2.347-3.649-2.781l-.001-.001c-.861-.245-1.543.44-1.605.505h0C12.006 12.283 12.004 12.321 12 12.372zM20.065 5.341c-1.179 2.963-5.641 1.848-6.067 3.718-.084.367.756 1.233 2.373 1.167C19.711 10.089 20.327 4.68 20.065 5.341zM7.838.604c-.694.068-2.451 1.104-2.13 1.533 1.701 2.276 2.746 4.356 4.713 5.949.264.214-1.179-2.193-1.239-3.547L9.181 4.539C9.115 3.056 8.532.536 7.838.604zM7.618 10.225c1.618.066 2.457-.8 2.373-1.167-.426-1.87-4.889-.755-6.067-3.718C3.662 4.68 4.278 10.089 7.618 10.225z"/><path d="M4.167 4.47c.122 1.021 1.21 1.987 2.663 2.38 1.554.421 3.37 1.384 3.37 1.384-2.188-1.361-1.725-1.19-2.941-2.46C6.141 4.607 5.29 2.273 5.29 2.273S4.077 3.709 4.167 4.47zM11.862 3.168c.14-1.681-.899-2.714-1.281-3.023C10.2-.164 9.469.073 8.59.363c.995.674 1.494 1.476 1.632 2.574-.209 2.539 1.17 3.775 1.332 8.077v.001C11.854 11.13 11.723 4.849 11.862 3.168zM13.199 14.527c-1.279 1.746-2.356-.069-2.356-.069S11 15.379 10.809 17.41C10.57 19.956 11.791 24 11.791 24s1.665-4.052 1.374-6.67C12.926 15.178 13.273 14.426 13.199 14.527zM17.992 16.162c.208-.343-1.194 1.337-2.582.137-.962-.832-1.127-1.085-1.875-1.808-.252-.244.28 1.014.428 2.151l-.001.001c.208 1.591-.023 2.462-.324 4.164C13.487 21.668 16.743 18.218 17.992 16.162zM16.73 5.774c-1.215 1.27-.754 1.099-2.941 2.46 0 0 1.816-.964 3.37-1.384 1.452-.393 2.542-1.359 2.663-2.38.09-.76-1.123-2.197-1.123-2.197S17.848 4.607 16.73 5.774zM10.409 14.619l-.001-.001c-.748.723-.914.976-1.875 1.808-1.387 1.2-2.79-.48-2.582-.137 1.249 2.057 4.506 5.506 4.354 4.645-.301-1.703-.532-2.574-.324-4.164C10.13 15.633 10.662 14.375 10.409 14.619zM13.407.147c-.382.309-1.42 1.342-1.281 3.023.139 1.681.007 7.962.309 7.846.162-4.302 1.54-5.538 1.332-8.077V2.937c.139-1.098.639-1.9 1.632-2.574C14.52.074 13.788-.162 13.407.147zM16.151.605c-.694-.068-1.277 2.453-1.343 3.936-.06 1.354-1.504 3.761-1.239 3.547l-.001-.001c1.966-1.594 3.012-3.673 4.713-5.949C18.603 1.709 16.846.673 16.151.605z"/></svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -2,11 +2,13 @@ import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/ui/views/app_selector/app_selector_view.dart'; import 'package:revanced_manager/ui/views/app_selector/app_selector_view.dart';
import 'package:revanced_manager/ui/views/app_selector/app_selector_viewmodel.dart'; import 'package:revanced_manager/ui/views/app_selector/app_selector_viewmodel.dart';
import 'package:revanced_manager/ui/views/contributors/contributors_view.dart'; import 'package:revanced_manager/ui/views/contributors/contributors_view.dart';
import 'package:revanced_manager/ui/views/home/home_view.dart';
import 'package:revanced_manager/ui/views/installer/installer_view.dart'; import 'package:revanced_manager/ui/views/installer/installer_view.dart';
import 'package:revanced_manager/ui/views/installer/installer_viewmodel.dart'; import 'package:revanced_manager/ui/views/installer/installer_viewmodel.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_view.dart'; import 'package:revanced_manager/ui/views/patches_selector/patches_selector_view.dart';
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart'; import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
import 'package:revanced_manager/ui/views/root_checker/root_checker_view.dart';
import 'package:revanced_manager/ui/views/settings/settings_view.dart'; import 'package:revanced_manager/ui/views/settings/settings_view.dart';
import 'package:stacked/stacked_annotations.dart'; import 'package:stacked/stacked_annotations.dart';
import 'package:stacked_services/stacked_services.dart'; import 'package:stacked_services/stacked_services.dart';
@ -14,11 +16,13 @@ import 'package:stacked_themes/stacked_themes.dart';
@StackedApp( @StackedApp(
routes: [ routes: [
MaterialRoute(page: HomeView),
MaterialRoute(page: AppSelectorView), MaterialRoute(page: AppSelectorView),
MaterialRoute(page: PatchesSelectorView), MaterialRoute(page: PatchesSelectorView),
MaterialRoute(page: InstallerView), MaterialRoute(page: InstallerView),
MaterialRoute(page: SettingsView), MaterialRoute(page: SettingsView),
MaterialRoute(page: ContributorsView) MaterialRoute(page: ContributorsView),
MaterialRoute(page: RootCheckerView),
], ],
dependencies: [ dependencies: [
LazySingleton(classType: NavigationService), LazySingleton(classType: NavigationService),

View File

@ -4,7 +4,7 @@
// StackedLocatorGenerator // StackedLocatorGenerator
// ************************************************************************** // **************************************************************************
// ignore_for_file: public_member_api_docs, depend_on_referenced_packages // ignore_for_file: public_member_api_docs
import 'package:stacked_core/stacked_core.dart'; import 'package:stacked_core/stacked_core.dart';
import 'package:stacked_services/stacked_services.dart'; import 'package:stacked_services/stacked_services.dart';

View File

@ -12,22 +12,28 @@ import 'package:stacked_services/stacked_services.dart';
import '../ui/views/app_selector/app_selector_view.dart'; import '../ui/views/app_selector/app_selector_view.dart';
import '../ui/views/contributors/contributors_view.dart'; import '../ui/views/contributors/contributors_view.dart';
import '../ui/views/home/home_view.dart';
import '../ui/views/installer/installer_view.dart'; import '../ui/views/installer/installer_view.dart';
import '../ui/views/patches_selector/patches_selector_view.dart'; import '../ui/views/patches_selector/patches_selector_view.dart';
import '../ui/views/root_checker/root_checker_view.dart';
import '../ui/views/settings/settings_view.dart'; import '../ui/views/settings/settings_view.dart';
class Routes { class Routes {
static const String homeView = '/home-view';
static const String appSelectorView = '/app-selector-view'; static const String appSelectorView = '/app-selector-view';
static const String patchesSelectorView = '/patches-selector-view'; static const String patchesSelectorView = '/patches-selector-view';
static const String installerView = '/installer-view'; static const String installerView = '/installer-view';
static const String settingsView = '/settings-view'; static const String settingsView = '/settings-view';
static const String contributorsView = '/contributors-view'; static const String contributorsView = '/contributors-view';
static const String rootCheckerView = '/root-checker-view';
static const all = <String>{ static const all = <String>{
homeView,
appSelectorView, appSelectorView,
patchesSelectorView, patchesSelectorView,
installerView, installerView,
settingsView, settingsView,
contributorsView, contributorsView,
rootCheckerView,
}; };
} }
@ -35,15 +41,23 @@ class StackedRouter extends RouterBase {
@override @override
List<RouteDef> get routes => _routes; List<RouteDef> get routes => _routes;
final _routes = <RouteDef>[ final _routes = <RouteDef>[
RouteDef(Routes.homeView, page: HomeView),
RouteDef(Routes.appSelectorView, page: AppSelectorView), RouteDef(Routes.appSelectorView, page: AppSelectorView),
RouteDef(Routes.patchesSelectorView, page: PatchesSelectorView), RouteDef(Routes.patchesSelectorView, page: PatchesSelectorView),
RouteDef(Routes.installerView, page: InstallerView), RouteDef(Routes.installerView, page: InstallerView),
RouteDef(Routes.settingsView, page: SettingsView), RouteDef(Routes.settingsView, page: SettingsView),
RouteDef(Routes.contributorsView, page: ContributorsView), RouteDef(Routes.contributorsView, page: ContributorsView),
RouteDef(Routes.rootCheckerView, page: RootCheckerView),
]; ];
@override @override
Map<Type, StackedRouteFactory> get pagesMap => _pagesMap; Map<Type, StackedRouteFactory> get pagesMap => _pagesMap;
final _pagesMap = <Type, StackedRouteFactory>{ final _pagesMap = <Type, StackedRouteFactory>{
HomeView: (data) {
return MaterialPageRoute<dynamic>(
builder: (context) => const HomeView(),
settings: data,
);
},
AppSelectorView: (data) { AppSelectorView: (data) {
return MaterialPageRoute<dynamic>( return MaterialPageRoute<dynamic>(
builder: (context) => const AppSelectorView(), builder: (context) => const AppSelectorView(),
@ -77,6 +91,12 @@ class StackedRouter extends RouterBase {
settings: data, settings: data,
); );
}, },
RootCheckerView: (data) {
return MaterialPageRoute<dynamic>(
builder: (context) => const RootCheckerView(),
settings: data,
);
},
}; };
} }
@ -95,6 +115,22 @@ class InstallerViewArguments {
/// ************************************************************************* /// *************************************************************************
extension NavigatorStateExtension on NavigationService { extension NavigatorStateExtension on NavigationService {
Future<dynamic> navigateToHomeView({
int? routerId,
bool preventDuplicates = true,
Map<String, String>? parameters,
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
transition,
}) async {
return navigateTo(
Routes.homeView,
id: routerId,
preventDuplicates: preventDuplicates,
parameters: parameters,
transition: transition,
);
}
Future<dynamic> navigateToAppSelectorView({ Future<dynamic> navigateToAppSelectorView({
int? routerId, int? routerId,
bool preventDuplicates = true, bool preventDuplicates = true,
@ -176,4 +212,20 @@ extension NavigatorStateExtension on NavigationService {
transition: transition, transition: transition,
); );
} }
Future<dynamic> navigateToRootCheckerView({
int? routerId,
bool preventDuplicates = true,
Map<String, String>? parameters,
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
transition,
}) async {
return navigateTo(
Routes.rootCheckerView,
id: routerId,
preventDuplicates: preventDuplicates,
parameters: parameters,
transition: transition,
);
}
} }

View File

@ -54,7 +54,9 @@ class MyApp extends StatelessWidget {
} }
class Navigation extends StatelessWidget { class Navigation extends StatelessWidget {
const Navigation({Key? key}) : super(key: key); const Navigation({
Key? key,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -0,0 +1,83 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/widgets/I18nText.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/ui/views/root_checker/root_checker_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/magisk_button.dart';
import 'package:stacked/stacked.dart';
class RootCheckerView extends StatelessWidget {
const RootCheckerView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ViewModelBuilder<RootCheckerViewModel>.reactive(
onModelReady: (model) => model.initialize,
viewModelBuilder: () => RootCheckerViewModel(),
builder: (context, model, child) => Scaffold(
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
const Text('nonroot'),
const SizedBox(height: 8),
FloatingActionButton(
onPressed: model.navigateToHome,
backgroundColor: Theme.of(context).colorScheme.secondary,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(48),
),
child: const Icon(
Icons.keyboard_arrow_right,
size: 32,
),
),
],
),
body: Container(
height: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 28.0),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
const SizedBox(height: 120),
I18nText(
'rootCheckerView.widgetTitle',
child: Text(
'',
style: GoogleFonts.jetBrainsMono(
fontSize: 24,
),
),
),
const SizedBox(height: 24),
I18nText(
'rootCheckerView.widgetDescription',
child: Text(
'',
textAlign: TextAlign.center,
style: GoogleFonts.roboto(
fontSize: 17,
letterSpacing: 1.1,
),
),
),
const SizedBox(height: 170),
MagiskButton(
onPressed: () {
model.getMagiskPermissions();
Future.delayed(const Duration(seconds: 5), () {
model.checkRoot();
});
},
),
Text(
"Magisk permission granted: ${model.isRooted.toString()}",
style: GoogleFonts.poppins(),
),
],
),
),
),
);
}
}

View File

@ -0,0 +1,38 @@
import 'package:fluttertoast/fluttertoast.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/app/app.router.dart';
import 'package:revanced_manager/ui/views/home/home_view.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();
notifyListeners();
}
Future<void> getMagiskPermissions() async {
if (isRooted == true) {
Fluttertoast.showToast(msg: 'Magisk permission already granted!');
}
await Root.exec(cmd: "adb shell su -c exit");
notifyListeners();
}
Future<void> navigateToHome() async {
final prefs = await SharedPreferences.getInstance();
prefs.setBool('showHome', true);
_navigationService.navigateTo(Routes.homeView);
notifyListeners();
}
}

View File

@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/widgets/I18nText.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/theme.dart';
class MagiskButton extends StatelessWidget {
final Function()? onPressed;
const MagiskButton({
Key? key,
this.onPressed,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
GestureDetector(
onTap: onPressed,
child: CircleAvatar(
radius: 32,
backgroundColor: isDark
? Theme.of(context).colorScheme.secondary
: const Color(0xffCBDFFC),
child: SvgPicture.asset(
'assets/images/magisk.svg',
color: isDark ? Colors.white70 : Colors.grey[900],
height: 50,
width: 50,
),
),
),
const SizedBox(height: 8),
I18nText(
'rootCheckerView.grantPermission',
child: Text(
'',
style: GoogleFonts.poppins(
fontSize: 15,
),
),
),
],
);
}
}

View File

@ -32,6 +32,7 @@ dependencies:
path_provider: ^2.0.11 path_provider: ^2.0.11
root: ^2.0.2 root: ^2.0.2
share_extend: ^2.0.0 share_extend: ^2.0.0
shared_preferences: ^2.0.15
stacked: ^2.3.15 stacked: ^2.3.15
stacked_generator: ^0.7.14 stacked_generator: ^0.7.14
stacked_services: ^0.9.3 stacked_services: ^0.9.3