Bugfix for prev. commit

This commit is contained in:
Imran Remtulla
2023-04-30 00:15:53 -04:00
parent 81f66683d2
commit 04b3c8ad7d
3 changed files with 28 additions and 28 deletions

View File

@@ -615,7 +615,7 @@ class AppsPageState extends State<AppsPage> {
items: formItems.map((e) => [e]).toList(),
initValid: true,
);
}).then((values) {
}).then((values) async {
if (values != null) {
if (values.isEmpty) {
values = getDefaultValuesFromFormItems([formItems]);
@@ -623,29 +623,22 @@ class AppsPageState extends State<AppsPage> {
bool shouldInstallUpdates = values['updates'] == true;
bool shouldInstallNew = values['installs'] == true;
bool shouldMarkTrackOnlies = values['trackonlies'] == true;
(() async {
List<String> toInstall = [];
if (shouldInstallUpdates) {
toInstall.addAll(existingUpdateIdsAllOrSelected);
}
if (shouldInstallNew) {
toInstall.addAll(newInstallIdsAllOrSelected);
}
if (shouldMarkTrackOnlies) {
toInstall.addAll(trackOnlyUpdateIdsAllOrSelected);
}
if (toInstall.length > 1) {
// Permission is requested automatically, but if there are more than 1 installs,
// We want to explicitly request it and wait for the result to avoid multiple requests
await settingsProvider.getInstallPermission(
enforce: false);
}
appsProvider
.downloadAndInstallLatestApps(
toInstall, globalNavigatorKey.currentContext)
.catchError((e) {
showError(e, context);
});
List<String> toInstall = [];
if (shouldInstallUpdates) {
toInstall.addAll(existingUpdateIdsAllOrSelected);
}
if (shouldInstallNew) {
toInstall.addAll(newInstallIdsAllOrSelected);
}
if (shouldMarkTrackOnlies) {
toInstall.addAll(trackOnlyUpdateIdsAllOrSelected);
}
appsProvider
.downloadAndInstallLatestApps(
toInstall, globalNavigatorKey.currentContext,
settingsProvider: settingsProvider)
.catchError((e) {
showError(e, context);
});
}
});

View File

@@ -351,7 +351,8 @@ class AppsProvider with ChangeNotifier {
// If user input is needed and the App is in the background, a notification is sent to get the user's attention
// Returns an array of Ids for Apps that were successfully downloaded, regardless of installation result
Future<List<String>> downloadAndInstallLatestApps(
List<String> appIds, BuildContext? context) async {
List<String> appIds, BuildContext? context,
{SettingsProvider? settingsProvider}) async {
List<String> appsToInstall = [];
List<String> trackOnlyAppsToUpdate = [];
// For all specified Apps, filter out those for which:
@@ -440,6 +441,11 @@ class AppsProvider with ChangeNotifier {
silentUpdates = moveObtainiumToStart(silentUpdates);
regularInstalls = moveObtainiumToStart(regularInstalls);
if (!(await settingsProvider?.getInstallPermission(enforce: false) ??
true)) {
throw ObtainiumError(tr('cancelled'));
}
// // Install silent updates (uncomment when it works - TODO)
// for (var u in silentUpdates) {
// await installApk(u, silent: true); // Would need to add silent option

View File

@@ -120,19 +120,20 @@ class SettingsProvider with ChangeNotifier {
return result;
}
Future<void> getInstallPermission({bool enforce = false}) async {
Future<bool> getInstallPermission({bool enforce = false}) async {
while (!(await Permission.requestInstallPackages.isGranted)) {
// Explicit request as InstallPlugin request sometimes bugged
Fluttertoast.showToast(
msg: tr('pleaseAllowInstallPerm'), toastLength: Toast.LENGTH_LONG);
if ((await Permission.requestInstallPackages.request()) ==
PermissionStatus.granted) {
break;
return true;
}
if (!enforce) {
break;
return false;
}
}
return true;
}
bool get showAppWebpage {