feat: abort patching process at any time (#1072)

This commit is contained in:
aAbed
2023-08-04 03:25:08 +05:45
committed by GitHub
parent fe75b75ddc
commit 374eb3d06d
4 changed files with 112 additions and 6 deletions

View File

@ -36,6 +36,8 @@ class InstallerViewModel extends BaseViewModel {
bool isPatching = true;
bool isInstalled = false;
bool hasErrors = false;
bool isCanceled = false;
bool cancel = false;
Future<void> initialize(BuildContext context) async {
isRooted = await _rootAPI.isRooted();
@ -162,6 +164,19 @@ class InstallerViewModel extends BaseViewModel {
}
}
Future<void> stopPatcher() async {
try {
isCanceled = true;
update(0.5, 'Aborting...', 'Canceling patching process');
await _patcherAPI.stopPatcher();
update(-100.0, 'Aborted...', 'Press back to exit');
} on Exception catch (e) {
if (kDebugMode) {
print(e);
}
}
}
Future<void> installResult(BuildContext context, bool installAsRoot) async {
try {
_app.isRooted = installAsRoot;
@ -280,10 +295,21 @@ class InstallerViewModel extends BaseViewModel {
Future<bool> onWillPop(BuildContext context) async {
if (isPatching) {
_toast.showBottom('installerView.noExit');
if (!cancel) {
cancel = true;
_toast.showBottom('installerView.pressBackAgain');
} else if (!isCanceled) {
await stopPatcher();
} else {
_toast.showBottom('installerView.noExit');
}
return false;
}
cleanPatcher();
if (!cancel) {
cleanPatcher();
} else {
_patcherAPI.cleanPatcher();
}
Navigator.of(context).pop();
return true;
}