From 82e08150ab312d92c90f35cfb772ee0dee8a5aab Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Tue, 22 Aug 2023 16:28:22 -0400 Subject: [PATCH] bugs --- lib/main.dart | 26 ++++++++++++++------------ lib/providers/apps_provider.dart | 11 ----------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 1a98726..25ad603 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -104,13 +104,13 @@ Future bgUpdateCheck(int taskId, Map? params) async { params['attemptCount'] = (params['attemptCount'] ?? 0) + 1; params['toCheck'] = params['toCheck'] ?? appsProvider.getAppsSortedByUpdateCheckTime(); - params['toInstall'] = params['toInstall'] ?? []; + params['toInstall'] = params['toInstall'] ?? ([]); - List toCheck = params['toCheck']; - List toInstall = params['toCheck']; + List toCheck = [...params['toCheck']]; + List toInstall = [...params['toInstall']]; logs.add( - 'BG update task $taskId started - ${toCheck.length} to check and ${toInstall.length} to install${params['attemptCount'] > 1 ? ' (attempt #${params['attemptCount']})' : ''}.'); + 'BG update task $taskId: Started [${toCheck.length},${toInstall.length}]${params['attemptCount'] > 1 ? '. ${params['attemptCount'] - 1} consecutive fail(s)' : ''}.'); if (toCheck.isNotEmpty) { String appId = toCheck.removeAt(0); @@ -123,19 +123,19 @@ Future bgUpdateCheck(int taskId, Map? params) async { if (newApp != null) { if (!(await appsProvider.canInstallSilently(app!.app))) { notificationsProvider.notify( - UpdateNotification([newApp], id: newApp.id.hashCode * 10)); + UpdateNotification([newApp], id: newApp.id.hashCode - 1)); } else { toInstall.add(appId); } } } catch (e) { logs.add( - 'BG update check got error on checking for $appId \'${e.toString()}\'.'); + 'BG update task $taskId: Got error on checking for $appId \'${e.toString()}\'.'); if (e is RateLimitError || e is ClientException && params['attemptCount'] < maxAttempts) { var remainingMinutes = e is RateLimitError ? e.remainingMinutes : 15; logs.add( - 'BG update task $taskId will be retried in $remainingMinutes minutes (with $appId moved to the end of the line).'); + 'BG update task $taskId: Next task will start in $remainingMinutes minutes (with $appId moved to the end of the line).'); toCheck = toInstall = []; // So the next task will not start params['toCheck'] = moveStrToEnd(params['toCheck'], appId); AndroidAlarmManager.oneShot( @@ -151,17 +151,19 @@ Future bgUpdateCheck(int taskId, Map? params) async { } else if (toInstall.isNotEmpty) { toInstall = moveStrToEnd(toInstall, obtainiumId); String appId = toInstall.removeAt(0); - logs.add('Attempting to update $appId in the background.'); + logs.add( + 'BG update task $taskId: Attempting to update $appId in the background.'); await appsProvider.downloadAndInstallLatestApps([appId], null, notificationsProvider: notificationsProvider); } - logs.add('BG update task $taskId ended.'); - if (toCheck.isNotEmpty || toInstall.isNotEmpty) { - AndroidAlarmManager.oneShot(Duration(seconds: toCheck.isNotEmpty ? 1 : 5), - taskId + 1, bgUpdateCheck, + logs.add('BG update task $taskId: Ended. Next task will start soon.'); + AndroidAlarmManager.oneShot( + const Duration(seconds: 0), taskId + 1, bgUpdateCheck, params: {'toCheck': toCheck, 'toInstall': toInstall}); + } else { + logs.add('BG update task $taskId: Ended.'); } } diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index b9f29a7..20cbbe9 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -708,17 +708,6 @@ class AppsProvider with ChangeNotifier { logs.add('Could not reconcile version formats for: ${app.id}'); modded = true; } - // if (app.installedVersion != null && - // app.additionalSettings['versionDetection'] == - // 'standardVersionDetection') { - // var correctedInstalledVersion = - // reconcileVersionDifferences(app.installedVersion!, app.latestVersion); - // if (correctedInstalledVersion == null) { - // app.additionalSettings['versionDetection'] = 'noVersionDetection'; - // logs.add('Could not reconcile version formats for: ${app.id}'); - // modded = true; - // } - // } return modded ? app : null; }