diff --git a/lib/main.dart b/lib/main.dart index 38668c2..297b664 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -133,7 +133,7 @@ Future bgUpdateCheck(int taskId, Map? params) async { bool installMode = toCheck.isEmpty && toInstall.isNotEmpty; logs.add( - 'BG update task $taskId: Started in ${installMode ? 'install' : 'update'} mode${attemptCount > 1 ? '. ${attemptCount - 1} consecutive fail(s)' : ''}.'); + 'BG ${installMode ? 'install' : 'update'} task $taskId: Started${attemptCount > 1 ? '. ${attemptCount - 1} consecutive fail(s)' : ''}.'); if (!installMode) { var didCompleteChecking = false; @@ -188,6 +188,8 @@ Future bgUpdateCheck(int taskId, Map? params) async { } } if (didCompleteChecking && toInstall.isNotEmpty) { + logs.add( + 'BG update task $taskId: Scheduling install task to run immediately.'); AndroidAlarmManager.oneShot( const Duration(minutes: 0), taskId + 1, bgUpdateCheck, params: {'toCheck': [], 'toInstall': toInstall}); @@ -198,17 +200,20 @@ Future bgUpdateCheck(int taskId, Map? params) async { String appId = toInstall[i]; try { logs.add( - 'BG update task $taskId: Attempting to update $appId in the background.'); + 'BG install task $taskId: Attempting to update $appId in the background.'); await appsProvider.downloadAndInstallLatestApps( [appId], null, settingsProvider, notificationsProvider: notificationsProvider); + await Future.delayed(const Duration( + seconds: + 5)); // Just in case task ending causes install fail (not clear) } catch (e) { logs.add( - 'BG update task $taskId: Got error on updating $appId \'${e.toString()}\'.'); + 'BG install task $taskId: Got error on updating $appId \'${e.toString()}\'.'); if (attemptCount < maxAttempts) { var remainingSeconds = 1; logs.add( - 'BG update task $taskId: Will continue in $remainingSeconds seconds (with $appId moved to the end of the line).'); + 'BG install task $taskId: Will continue in $remainingSeconds seconds (with $appId moved to the end of the line).'); var remainingToInstall = moveStrToEnd(toInstall.sublist(i), appId); AndroidAlarmManager.oneShot( Duration(seconds: remainingSeconds), taskId + 1, bgUpdateCheck, @@ -225,6 +230,7 @@ Future bgUpdateCheck(int taskId, Map? params) async { } } } + logs.add('BG ${installMode ? 'install' : 'update'} task $taskId: Done.'); } void main() async {