mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 04:37:37 +02:00
feat: Improve installation robustness (#1528)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de> Co-authored-by: Ushie <ushiekane@gmail.com> Co-authored-by: Dhruvan Bhalara <53393418+dhruvanbhalara@users.noreply.github.com> Co-authored-by: Pun Butrach <pun.butrach@gmail.com>
This commit is contained in:
@ -8,7 +8,6 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:install_plugin/install_plugin.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/app/app.router.dart';
|
||||
@ -53,7 +52,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
_toast.showBottom('homeView.installingMessage');
|
||||
final File? managerApk = await _managerAPI.downloadManager();
|
||||
if (managerApk != null) {
|
||||
await InstallPlugin.installApk(managerApk.path);
|
||||
await _patcherAPI.installApk(context, managerApk.path);
|
||||
} else {
|
||||
_toast.showBottom('homeView.errorDownloadMessage');
|
||||
}
|
||||
@ -75,7 +74,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
_toast.showBottom('homeView.installingMessage');
|
||||
final File? managerApk = await _managerAPI.downloadManager();
|
||||
if (managerApk != null) {
|
||||
await InstallPlugin.installApk(managerApk.path);
|
||||
await _patcherAPI.installApk(context, managerApk.path);
|
||||
} else {
|
||||
_toast.showBottom('homeView.errorDownloadMessage');
|
||||
}
|
||||
@ -84,6 +83,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
_managerAPI.reAssessSavedApps().then((_) => _getPatchedApps());
|
||||
}
|
||||
|
||||
|
||||
void navigateToAppInfo(PatchedApplication app) {
|
||||
_navigationService.navigateTo(
|
||||
Routes.appInfoView,
|
||||
@ -268,6 +268,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
valueListenable: downloaded,
|
||||
builder: (context, value, child) {
|
||||
return SimpleDialog(
|
||||
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||
contentPadding: const EdgeInsets.all(16.0),
|
||||
title: I18nText(
|
||||
!value
|
||||
@ -365,9 +366,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
alignment: Alignment.centerRight,
|
||||
child: FilledButton(
|
||||
onPressed: () async {
|
||||
await InstallPlugin.installApk(
|
||||
downloadedApk!.path,
|
||||
);
|
||||
await _patcherAPI.installApk(context, downloadedApk!.path);
|
||||
},
|
||||
child: I18nText('updateButton'),
|
||||
),
|
||||
@ -412,7 +411,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
// UILocalNotificationDateInterpretation.absoluteTime,
|
||||
// );
|
||||
_toast.showBottom('homeView.installingMessage');
|
||||
await InstallPlugin.installApk(managerApk.path);
|
||||
await _patcherAPI.installApk(context, managerApk.path);
|
||||
} else {
|
||||
_toast.showBottom('homeView.errorDownloadMessage');
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ class InstallerViewModel extends BaseViewModel {
|
||||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
builder: (innerContext) => AlertDialog(
|
||||
title: I18nText(
|
||||
'installerView.installType',
|
||||
),
|
||||
@ -367,6 +367,19 @@ class InstallerViewModel extends BaseViewModel {
|
||||
installType.value = selected!;
|
||||
},
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: I18nText(
|
||||
'installerView.warning',
|
||||
child: Text(
|
||||
'',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
@ -375,13 +388,13 @@ class InstallerViewModel extends BaseViewModel {
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(innerContext).pop();
|
||||
},
|
||||
child: I18nText('cancelButton'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(innerContext).pop();
|
||||
installResult(context, installType.value == 1);
|
||||
},
|
||||
child: I18nText('installerView.installButton'),
|
||||
@ -390,7 +403,32 @@ class InstallerViewModel extends BaseViewModel {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
installResult(context, false);
|
||||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (innerContext) => AlertDialog(
|
||||
title: I18nText(
|
||||
'warning',
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(16),
|
||||
content: I18nText('installerView.warning'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(innerContext).pop();
|
||||
},
|
||||
child: I18nText('cancelButton'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(innerContext).pop();
|
||||
installResult(context, false);
|
||||
},
|
||||
child: I18nText('installerView.installButton'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -411,15 +449,18 @@ class InstallerViewModel extends BaseViewModel {
|
||||
Future<void> installResult(BuildContext context, bool installAsRoot) async {
|
||||
try {
|
||||
_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) {
|
||||
if (headerLogs != 'Installing...') {
|
||||
update(
|
||||
1.0,
|
||||
'Installing...',
|
||||
_app.isRooted
|
||||
? 'Mounting patched app'
|
||||
: 'Installing patched app',
|
||||
);
|
||||
}
|
||||
final int response = await _patcherAPI.installPatchedFile(context, _app);
|
||||
if (response == 0) {
|
||||
isInstalled = true;
|
||||
_app.isFromStorage = false;
|
||||
_app.patchDate = DateTime.now();
|
||||
_app.appliedPatches = _patches.map((p) => p.name).toList();
|
||||
@ -435,9 +476,26 @@ class InstallerViewModel extends BaseViewModel {
|
||||
|
||||
await _managerAPI.savePatchedApp(_app);
|
||||
|
||||
update(1.0, 'Installed!', 'Installed!');
|
||||
update(1.0, 'Installed', 'Installed');
|
||||
} else if (response == 3) {
|
||||
update(
|
||||
1.0,
|
||||
'Installation canceled',
|
||||
'Installation canceled',
|
||||
);
|
||||
} else if (response == 10) {
|
||||
installResult(context, installAsRoot);
|
||||
update(
|
||||
1.0,
|
||||
'',
|
||||
'Starting installer',
|
||||
);
|
||||
} else {
|
||||
// TODO(aabed): Show error message.
|
||||
update(
|
||||
1.0,
|
||||
'Installation failed',
|
||||
'Installation failed',
|
||||
);
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
if (kDebugMode) {
|
||||
|
@ -184,10 +184,6 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
||||
void selectPatches() {
|
||||
locator<PatcherViewModel>().selectedPatches = selectedPatches;
|
||||
saveSelectedPatches();
|
||||
if (_managerAPI.ctx != null) {
|
||||
Navigator.pop(_managerAPI.ctx!);
|
||||
_managerAPI.ctx = null;
|
||||
}
|
||||
locator<PatcherViewModel>().notifyListeners();
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,9 @@ class AppInfoViewModel extends BaseViewModel {
|
||||
if (app.isRooted) {
|
||||
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
||||
if (hasRootPermissions) {
|
||||
await _rootAPI.deleteApp(app.packageName, app.apkFilePath);
|
||||
await _rootAPI.unmount(
|
||||
app.packageName,
|
||||
);
|
||||
if (!onlyUnpatch) {
|
||||
await DeviceApps.uninstallApp(app.packageName);
|
||||
}
|
||||
|
Reference in New Issue
Block a user