feat: Improve experience of rooted patched app installations (#59)

This commit is contained in:
Alberto Ponces
2022-09-06 14:40:49 +01:00
committed by GitHub
parent 9e178ba584
commit 27ef74b561
22 changed files with 203 additions and 299 deletions

View File

@ -6,23 +6,19 @@ import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/models/patched_application.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
import 'package:stacked/stacked.dart';
class AppSelectorViewModel extends BaseViewModel {
final ManagerAPI _managerAPI = locator<ManagerAPI>();
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
final List<ApplicationWithIcon> apps = [];
bool noApps = false;
bool _isRooted = false;
Future<void> initialize() async {
apps.addAll(await _patcherAPI.getFilteredInstalledApps());
apps.sort((a, b) => a.appName.compareTo(b.appName));
noApps = apps.isEmpty;
_isRooted = _managerAPI.isRooted() ?? false;
notifyListeners();
}
@ -34,7 +30,7 @@ class AppSelectorViewModel extends BaseViewModel {
apkFilePath: application.apkFilePath,
icon: application.icon,
patchDate: DateTime.now(),
isRooted: _isRooted,
isRooted: false,
);
locator<PatcherViewModel>().selectedPatches.clear();
locator<PatcherViewModel>().notifyListeners();

View File

@ -4,6 +4,7 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/ui/views/installer/installer_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_popup_menu.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_sliver_app_bar.dart';
import 'package:stacked/stacked.dart';
@ -27,6 +28,34 @@ class InstallerView extends StatelessWidget {
color: Theme.of(context).textTheme.headline6!.color,
),
),
actions: <Widget>[
Visibility(
visible: !model.isPatching,
child: CustomPopupMenu(
onSelected: (value) => model.onMenuSelection(value),
children: {
0: I18nText(
'installerView.shareApkMenuOption',
child: const Text(
'',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
1: I18nText(
'installerView.shareLogMenuOption',
child: const Text(
'',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
},
),
),
],
bottom: PreferredSize(
preferredSize: const Size(double.infinity, 1.0),
child: LinearProgressIndicator(
@ -60,26 +89,42 @@ class InstallerView extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
CustomMaterialButton(
label: I18nText('installerView.shareButton'),
isFilled: false,
onPressed: () => model.shareResult(),
),
const SizedBox(width: 16),
CustomMaterialButton(
label: model.isInstalled
? I18nText('installerView.openButton')
: I18nText('installerView.installButton'),
isExpanded: true,
onPressed: () {
if (model.isInstalled) {
Visibility(
visible: model.isInstalled,
child: CustomMaterialButton(
label: I18nText('installerView.openButton'),
isExpanded: true,
onPressed: () {
model.openApp();
model.cleanPatcher();
Navigator.of(context).pop();
} else {
model.installResult();
}
},
},
),
),
Visibility(
visible: !model.isInstalled,
child: CustomMaterialButton(
isFilled: false,
label:
I18nText('installerView.installButton'),
isExpanded: true,
onPressed: () => model.installResult(false),
),
),
Visibility(
visible: !model.isInstalled,
child: const SizedBox(
width: 16,
),
),
Visibility(
visible: !model.isInstalled,
child: CustomMaterialButton(
label: I18nText(
'installerView.installRootButton'),
isExpanded: true,
onPressed: () => model.installResult(true),
),
),
],
),

View File

@ -14,7 +14,7 @@ import 'package:stacked/stacked.dart';
class InstallerViewModel extends BaseViewModel {
final ManagerAPI _managerAPI = locator<ManagerAPI>();
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
final PatchedApplication? _app = locator<PatcherViewModel>().selectedApp;
final PatchedApplication _app = locator<PatcherViewModel>().selectedApp!;
final List<Patch> _patches = locator<PatcherViewModel>().selectedPatches;
static const _installerChannel = MethodChannel(
'app.revanced.manager/installer',
@ -98,19 +98,19 @@ class InstallerViewModel extends BaseViewModel {
Future<void> runPatcher() async {
update(0.0, 'Initializing...', 'Initializing installer');
if (_app != null && _patches.isNotEmpty) {
String apkFilePath = _app!.apkFilePath;
if (_patches.isNotEmpty) {
String apkFilePath = _app.apkFilePath;
try {
if (_app!.isRooted) {
if (_app.isRooted) {
update(0.0, '', 'Checking if an old patched version exists');
bool oldExists = await _patcherAPI.checkOldPatch(_app!);
bool oldExists = await _patcherAPI.checkOldPatch(_app);
if (oldExists) {
update(0.0, '', 'Deleting old patched version');
await _patcherAPI.deleteOldPatch(_app!);
await _patcherAPI.deleteOldPatch(_app);
}
}
update(0.0, '', 'Creating working directory');
await _patcherAPI.runPatcher(_app!.packageName, apkFilePath, _patches);
await _patcherAPI.runPatcher(_app.packageName, apkFilePath, _patches);
} on Exception {
update(1.0, 'Aborting...', 'An error occurred! Aborting');
}
@ -124,31 +124,32 @@ class InstallerViewModel extends BaseViewModel {
}
}
void installResult() async {
if (_app != null) {
update(
1.0,
'Installing...',
_app!.isRooted
? 'Installing patched file using root method'
: 'Installing patched file using nonroot method',
);
isInstalled = await _patcherAPI.installPatchedFile(_app!);
if (isInstalled) {
update(1.0, 'Installed!', 'Installed!');
_app!.patchDate = DateTime.now();
_app!.appliedPatches = _patches.map((p) => p.name).toList();
await _managerAPI.savePatchedApp(_app!);
} else {
update(1.0, 'Aborting...', 'An error occurred! Aborting');
}
void installResult(bool installAsRoot) async {
_app.isRooted = installAsRoot;
update(
1.0,
'Installing...',
_app.isRooted
? 'Installing patched file using root method'
: 'Installing patched file using nonroot method',
);
isInstalled = await _patcherAPI.installPatchedFile(_app);
if (isInstalled) {
update(1.0, 'Installed!', 'Installed!');
_app.patchDate = DateTime.now();
_app.appliedPatches = _patches.map((p) => p.name).toList();
await _managerAPI.savePatchedApp(_app);
} else {
update(1.0, 'Aborting...', 'An error occurred! Aborting');
}
}
void shareResult() {
if (_app != null) {
_patcherAPI.sharePatchedFile(_app!.name, _app!.version);
}
_patcherAPI.sharePatchedFile(_app.name, _app.version);
}
void shareLog() {
_patcherAPI.shareLog(logs);
}
Future<void> cleanPatcher() async {
@ -159,8 +160,17 @@ class InstallerViewModel extends BaseViewModel {
}
void openApp() {
if (_app != null) {
DeviceApps.openApp(_app!.packageName);
DeviceApps.openApp(_app.packageName);
}
void onMenuSelection(int value) {
switch (value) {
case 0:
shareResult();
break;
case 1:
shareLog();
break;
}
}
}

View File

@ -1,71 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.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/rootCheckerView/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: FloatingActionButton.extended(
label: I18nText('rootCheckerView.nonRootButton'),
icon: const Icon(Icons.keyboard_arrow_right),
onPressed: () => model.navigateAsNonRoot(),
),
body: Container(
height: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 28.0),
child: Column(
children: <Widget>[
const SizedBox(height: 120),
I18nText(
'rootCheckerView.widgetTitle',
child: Text(
'',
style: GoogleFonts.jetBrainsMono(
fontSize: 24,
),
),
),
const SizedBox(height: 24),
I18nText(
'rootCheckerView.widgetDescription',
child: const Text(
'',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 17,
letterSpacing: 1.1,
),
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
MagiskButton(
onPressed: () => model.navigateAsRoot(),
),
I18nText(
'rootCheckerView.grantedPermission',
translationParams: {
'isRooted': model.isRooted.toString(),
},
),
],
),
),
],
),
),
),
);
}
}

View File

@ -1,36 +0,0 @@
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/app/app.router.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:stacked/stacked.dart';
import 'package:root/root.dart';
import 'package:stacked_services/stacked_services.dart';
class RootCheckerViewModel extends BaseViewModel {
final NavigationService _navigationService = locator<NavigationService>();
final ManagerAPI _managerAPI = locator<ManagerAPI>();
bool isRooted = false;
void initialize() {
isRooted = _managerAPI.isRooted() ?? false;
}
Future<void> navigateAsRoot() async {
bool? res = await Root.isRooted();
isRooted = res != null && res == true;
if (isRooted) {
await navigateToHome();
} else {
notifyListeners();
}
}
Future<void> navigateAsNonRoot() async {
isRooted = false;
await navigateToHome();
}
Future<void> navigateToHome() async {
_managerAPI.setIsRooted(isRooted);
_navigationService.navigateTo(Routes.navigationView);
}
}

View File

@ -113,21 +113,6 @@ class SettingsView extends StatelessWidget {
SettingsSection(
title: 'settingsView.patcherSectionTitle',
children: <Widget>[
ListTile(
contentPadding: EdgeInsets.zero,
title: I18nText(
'settingsView.rootModeLabel',
child: const Text(
'',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
),
subtitle: I18nText('settingsView.rootModeHint'),
onTap: () => model.navigateToRootChecker(),
),
SourcesWidget(
title: 'settingsView.sourcesLabel',
organizationController: organizationController,

View File

@ -18,10 +18,6 @@ class SettingsViewModel extends BaseViewModel {
notifyListeners();
}
void navigateToRootChecker() {
_navigationService.navigateTo(Routes.rootCheckerView);
}
void navigateToContributors() {
_navigationService.navigateTo(Routes.contributorsView);
}