From 6785708661173dd72e799b448acbbb72a2644991 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Tue, 22 Aug 2023 19:57:42 -0400 Subject: [PATCH] BG update toggle has an effect --- lib/main.dart | 6 ++++-- lib/pages/app.dart | 3 ++- lib/pages/apps.dart | 8 ++++---- lib/providers/apps_provider.dart | 22 +++++++++++++--------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index a138880..1cd8d55 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -147,7 +147,8 @@ Future bgUpdateCheck(int taskId, Map? params) async { cancelExisting: true); App? newApp = await appsProvider.checkUpdate(appId); if (newApp != null) { - if (!(await appsProvider.canInstallSilently(app!.app))) { + if (!(await appsProvider.canInstallSilently( + app!.app, settingsProvider))) { notificationsProvider.notify( UpdateNotification([newApp], id: newApp.id.hashCode - 1)); } else { @@ -198,7 +199,8 @@ Future bgUpdateCheck(int taskId, Map? params) async { try { logs.add( 'BG update task $taskId: Attempting to update $appId in the background.'); - await appsProvider.downloadAndInstallLatestApps([appId], null, + await appsProvider.downloadAndInstallLatestApps( + [appId], null, settingsProvider, notificationsProvider: notificationsProvider); } catch (e) { logs.add( diff --git a/lib/pages/app.dart b/lib/pages/app.dart index de64bb3..710c3fb 100644 --- a/lib/pages/app.dart +++ b/lib/pages/app.dart @@ -339,7 +339,8 @@ class _AppPageState extends State { HapticFeedback.heavyImpact(); var res = await appsProvider.downloadAndInstallLatestApps( app?.app.id != null ? [app!.app.id] : [], - globalNavigatorKey.currentContext); + globalNavigatorKey.currentContext, + settingsProvider); if (res.isNotEmpty && mounted) { Navigator.of(context).pop(); } diff --git a/lib/pages/apps.dart b/lib/pages/apps.dart index 516a6a6..41c0f7d 100644 --- a/lib/pages/apps.dart +++ b/lib/pages/apps.dart @@ -381,7 +381,8 @@ class AppsPageState extends State { : () { appsProvider.downloadAndInstallLatestApps( [listedApps[appIndex].app.id], - globalNavigatorKey.currentContext).catchError((e) { + globalNavigatorKey.currentContext, + settingsProvider).catchError((e) { showError(e, context); return []; }); @@ -683,9 +684,8 @@ class AppsPageState extends State { toInstall.addAll(trackOnlyUpdateIdsAllOrSelected); } appsProvider - .downloadAndInstallLatestApps( - toInstall, globalNavigatorKey.currentContext, - settingsProvider: settingsProvider) + .downloadAndInstallLatestApps(toInstall, + globalNavigatorKey.currentContext, settingsProvider) .catchError((e) { showError(e, context); return []; diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index 1da2213..1ea70ce 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -328,7 +328,11 @@ class AppsProvider with ChangeNotifier { .where((element) => element.downloadProgress != null) .isNotEmpty; - Future canInstallSilently(App app) async { + Future canInstallSilently( + App app, SettingsProvider settingsProvider) async { + if (!settingsProvider.enableBackgroundUpdates) { + return false; + } if (app.apkUrls.length > 1) { // Manual API selection means silent install is not possible return false; @@ -509,10 +513,9 @@ class AppsProvider with ChangeNotifier { // If no BuildContext is provided, apps that require user interaction are ignored // 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> downloadAndInstallLatestApps( - List appIds, BuildContext? context, - {SettingsProvider? settingsProvider, - NotificationsProvider? notificationsProvider}) async { + Future> downloadAndInstallLatestApps(List appIds, + BuildContext? context, SettingsProvider settingsProvider, + {NotificationsProvider? notificationsProvider}) async { notificationsProvider = notificationsProvider ?? context?.read(); List appsToInstall = []; @@ -540,7 +543,8 @@ class AppsProvider with ChangeNotifier { apps[id]!.app.preferredApkIndex = urlInd; await saveApps([apps[id]!.app]); } - if (context != null || await canInstallSilently(apps[id]!.app)) { + if (context != null || + await canInstallSilently(apps[id]!.app, settingsProvider)) { appsToInstall.add(id); } } @@ -577,9 +581,9 @@ class AppsProvider with ChangeNotifier { downloadedDir = downloadedArtifact as DownloadedXApkDir; } var appId = downloadedFile?.appId ?? downloadedDir!.appId; - bool willBeSilent = await canInstallSilently(apps[appId]!.app); - if (!(await settingsProvider?.getInstallPermission(enforce: false) ?? - true)) { + bool willBeSilent = + await canInstallSilently(apps[appId]!.app, settingsProvider); + if (!(await settingsProvider.getInstallPermission(enforce: false))) { throw ObtainiumError(tr('cancelled')); } if (!willBeSilent && context != null) {