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:
aAbed
2023-12-23 09:01:28 +05:45
committed by GitHub
parent 8b28a33b73
commit c23275f2fe
14 changed files with 610 additions and 252 deletions

View File

@ -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) {