mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-19 21:19:28 +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);
|
cancelExisting: true);
|
||||||
App? newApp = await appsProvider.checkUpdate(appId);
|
App? newApp = await appsProvider.checkUpdate(appId);
|
||||||
if (newApp != null) {
|
if (newApp != null) {
|
||||||
if (!(await appsProvider.canInstallSilently(app!.app))) {
|
if (!(await appsProvider.canInstallSilently(
|
||||||
|
app!.app, settingsProvider))) {
|
||||||
notificationsProvider.notify(
|
notificationsProvider.notify(
|
||||||
UpdateNotification([newApp], id: newApp.id.hashCode - 1));
|
UpdateNotification([newApp], id: newApp.id.hashCode - 1));
|
||||||
} else {
|
} else {
|
||||||
@@ -198,7 +199,8 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
|
|||||||
try {
|
try {
|
||||||
logs.add(
|
logs.add(
|
||||||
'BG update task $taskId: Attempting to update $appId in the background.');
|
'BG update task $taskId: Attempting to update $appId in the background.');
|
||||||
await appsProvider.downloadAndInstallLatestApps([appId], null,
|
await appsProvider.downloadAndInstallLatestApps(
|
||||||
|
[appId], null, settingsProvider,
|
||||||
notificationsProvider: notificationsProvider);
|
notificationsProvider: notificationsProvider);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logs.add(
|
logs.add(
|
||||||
|
@@ -339,7 +339,8 @@ class _AppPageState extends State<AppPage> {
|
|||||||
HapticFeedback.heavyImpact();
|
HapticFeedback.heavyImpact();
|
||||||
var res = await appsProvider.downloadAndInstallLatestApps(
|
var res = await appsProvider.downloadAndInstallLatestApps(
|
||||||
app?.app.id != null ? [app!.app.id] : [],
|
app?.app.id != null ? [app!.app.id] : [],
|
||||||
globalNavigatorKey.currentContext);
|
globalNavigatorKey.currentContext,
|
||||||
|
settingsProvider);
|
||||||
if (res.isNotEmpty && mounted) {
|
if (res.isNotEmpty && mounted) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
|
@@ -381,7 +381,8 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
: () {
|
: () {
|
||||||
appsProvider.downloadAndInstallLatestApps(
|
appsProvider.downloadAndInstallLatestApps(
|
||||||
[listedApps[appIndex].app.id],
|
[listedApps[appIndex].app.id],
|
||||||
globalNavigatorKey.currentContext).catchError((e) {
|
globalNavigatorKey.currentContext,
|
||||||
|
settingsProvider).catchError((e) {
|
||||||
showError(e, context);
|
showError(e, context);
|
||||||
return <String>[];
|
return <String>[];
|
||||||
});
|
});
|
||||||
@@ -683,9 +684,8 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
toInstall.addAll(trackOnlyUpdateIdsAllOrSelected);
|
toInstall.addAll(trackOnlyUpdateIdsAllOrSelected);
|
||||||
}
|
}
|
||||||
appsProvider
|
appsProvider
|
||||||
.downloadAndInstallLatestApps(
|
.downloadAndInstallLatestApps(toInstall,
|
||||||
toInstall, globalNavigatorKey.currentContext,
|
globalNavigatorKey.currentContext, settingsProvider)
|
||||||
settingsProvider: settingsProvider)
|
|
||||||
.catchError((e) {
|
.catchError((e) {
|
||||||
showError(e, context);
|
showError(e, context);
|
||||||
return <String>[];
|
return <String>[];
|
||||||
|
@@ -328,7 +328,11 @@ class AppsProvider with ChangeNotifier {
|
|||||||
.where((element) => element.downloadProgress != null)
|
.where((element) => element.downloadProgress != null)
|
||||||
.isNotEmpty;
|
.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) {
|
if (app.apkUrls.length > 1) {
|
||||||
// Manual API selection means silent install is not possible
|
// Manual API selection means silent install is not possible
|
||||||
return false;
|
return false;
|
||||||
@@ -509,10 +513,9 @@ class AppsProvider with ChangeNotifier {
|
|||||||
// If no BuildContext is provided, apps that require user interaction are ignored
|
// 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
|
// 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
|
// Returns an array of Ids for Apps that were successfully downloaded, regardless of installation result
|
||||||
Future<List<String>> downloadAndInstallLatestApps(
|
Future<List<String>> downloadAndInstallLatestApps(List<String> appIds,
|
||||||
List<String> appIds, BuildContext? context,
|
BuildContext? context, SettingsProvider settingsProvider,
|
||||||
{SettingsProvider? settingsProvider,
|
{NotificationsProvider? notificationsProvider}) async {
|
||||||
NotificationsProvider? notificationsProvider}) async {
|
|
||||||
notificationsProvider =
|
notificationsProvider =
|
||||||
notificationsProvider ?? context?.read<NotificationsProvider>();
|
notificationsProvider ?? context?.read<NotificationsProvider>();
|
||||||
List<String> appsToInstall = [];
|
List<String> appsToInstall = [];
|
||||||
@@ -540,7 +543,8 @@ class AppsProvider with ChangeNotifier {
|
|||||||
apps[id]!.app.preferredApkIndex = urlInd;
|
apps[id]!.app.preferredApkIndex = urlInd;
|
||||||
await saveApps([apps[id]!.app]);
|
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);
|
appsToInstall.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -577,9 +581,9 @@ class AppsProvider with ChangeNotifier {
|
|||||||
downloadedDir = downloadedArtifact as DownloadedXApkDir;
|
downloadedDir = downloadedArtifact as DownloadedXApkDir;
|
||||||
}
|
}
|
||||||
var appId = downloadedFile?.appId ?? downloadedDir!.appId;
|
var appId = downloadedFile?.appId ?? downloadedDir!.appId;
|
||||||
bool willBeSilent = await canInstallSilently(apps[appId]!.app);
|
bool willBeSilent =
|
||||||
if (!(await settingsProvider?.getInstallPermission(enforce: false) ??
|
await canInstallSilently(apps[appId]!.app, settingsProvider);
|
||||||
true)) {
|
if (!(await settingsProvider.getInstallPermission(enforce: false))) {
|
||||||
throw ObtainiumError(tr('cancelled'));
|
throw ObtainiumError(tr('cancelled'));
|
||||||
}
|
}
|
||||||
if (!willBeSilent && context != null) {
|
if (!willBeSilent && context != null) {
|
||||||
|
Reference in New Issue
Block a user