mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-19 05:00:21 +02:00
BG update toggle has an effect
This commit is contained in:
@@ -147,7 +147,8 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? 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<void> bgUpdateCheck(int taskId, Map<String, dynamic>? 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(
|
||||
|
@@ -339,7 +339,8 @@ class _AppPageState extends State<AppPage> {
|
||||
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();
|
||||
}
|
||||
|
@@ -381,7 +381,8 @@ class AppsPageState extends State<AppsPage> {
|
||||
: () {
|
||||
appsProvider.downloadAndInstallLatestApps(
|
||||
[listedApps[appIndex].app.id],
|
||||
globalNavigatorKey.currentContext).catchError((e) {
|
||||
globalNavigatorKey.currentContext,
|
||||
settingsProvider).catchError((e) {
|
||||
showError(e, context);
|
||||
return <String>[];
|
||||
});
|
||||
@@ -683,9 +684,8 @@ class AppsPageState extends State<AppsPage> {
|
||||
toInstall.addAll(trackOnlyUpdateIdsAllOrSelected);
|
||||
}
|
||||
appsProvider
|
||||
.downloadAndInstallLatestApps(
|
||||
toInstall, globalNavigatorKey.currentContext,
|
||||
settingsProvider: settingsProvider)
|
||||
.downloadAndInstallLatestApps(toInstall,
|
||||
globalNavigatorKey.currentContext, settingsProvider)
|
||||
.catchError((e) {
|
||||
showError(e, context);
|
||||
return <String>[];
|
||||
|
@@ -328,7 +328,11 @@ class AppsProvider with ChangeNotifier {
|
||||
.where((element) => element.downloadProgress != null)
|
||||
.isNotEmpty;
|
||||
|
||||
Future<bool> canInstallSilently(App app) async {
|
||||
Future<bool> 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<List<String>> downloadAndInstallLatestApps(
|
||||
List<String> appIds, BuildContext? context,
|
||||
{SettingsProvider? settingsProvider,
|
||||
NotificationsProvider? notificationsProvider}) async {
|
||||
Future<List<String>> downloadAndInstallLatestApps(List<String> appIds,
|
||||
BuildContext? context, SettingsProvider settingsProvider,
|
||||
{NotificationsProvider? notificationsProvider}) async {
|
||||
notificationsProvider =
|
||||
notificationsProvider ?? context?.read<NotificationsProvider>();
|
||||
List<String> 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) {
|
||||
|
Reference in New Issue
Block a user