This commit is contained in:
Imran Remtulla
2023-08-22 16:28:22 -04:00
parent e956ee9254
commit 82e08150ab
2 changed files with 14 additions and 23 deletions

View File

@@ -104,13 +104,13 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
params['attemptCount'] = (params['attemptCount'] ?? 0) + 1; params['attemptCount'] = (params['attemptCount'] ?? 0) + 1;
params['toCheck'] = params['toCheck'] =
params['toCheck'] ?? appsProvider.getAppsSortedByUpdateCheckTime(); params['toCheck'] ?? appsProvider.getAppsSortedByUpdateCheckTime();
params['toInstall'] = params['toInstall'] ?? []; params['toInstall'] = params['toInstall'] ?? (<String>[]);
List<String> toCheck = params['toCheck']; List<String> toCheck = <String>[...params['toCheck']];
List<String> toInstall = params['toCheck']; List<String> toInstall = <String>[...params['toInstall']];
logs.add( 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) { if (toCheck.isNotEmpty) {
String appId = toCheck.removeAt(0); String appId = toCheck.removeAt(0);
@@ -123,19 +123,19 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
if (newApp != null) { if (newApp != null) {
if (!(await appsProvider.canInstallSilently(app!.app))) { if (!(await appsProvider.canInstallSilently(app!.app))) {
notificationsProvider.notify( notificationsProvider.notify(
UpdateNotification([newApp], id: newApp.id.hashCode * 10)); UpdateNotification([newApp], id: newApp.id.hashCode - 1));
} else { } else {
toInstall.add(appId); toInstall.add(appId);
} }
} }
} catch (e) { } catch (e) {
logs.add( 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 || if (e is RateLimitError ||
e is ClientException && params['attemptCount'] < maxAttempts) { e is ClientException && params['attemptCount'] < maxAttempts) {
var remainingMinutes = e is RateLimitError ? e.remainingMinutes : 15; var remainingMinutes = e is RateLimitError ? e.remainingMinutes : 15;
logs.add( 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 toCheck = toInstall = []; // So the next task will not start
params['toCheck'] = moveStrToEnd(params['toCheck'], appId); params['toCheck'] = moveStrToEnd(params['toCheck'], appId);
AndroidAlarmManager.oneShot( AndroidAlarmManager.oneShot(
@@ -151,17 +151,19 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
} else if (toInstall.isNotEmpty) { } else if (toInstall.isNotEmpty) {
toInstall = moveStrToEnd(toInstall, obtainiumId); toInstall = moveStrToEnd(toInstall, obtainiumId);
String appId = toInstall.removeAt(0); 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, await appsProvider.downloadAndInstallLatestApps([appId], null,
notificationsProvider: notificationsProvider); notificationsProvider: notificationsProvider);
} }
logs.add('BG update task $taskId ended.');
if (toCheck.isNotEmpty || toInstall.isNotEmpty) { if (toCheck.isNotEmpty || toInstall.isNotEmpty) {
AndroidAlarmManager.oneShot(Duration(seconds: toCheck.isNotEmpty ? 1 : 5), logs.add('BG update task $taskId: Ended. Next task will start soon.');
taskId + 1, bgUpdateCheck, AndroidAlarmManager.oneShot(
const Duration(seconds: 0), taskId + 1, bgUpdateCheck,
params: {'toCheck': toCheck, 'toInstall': toInstall}); params: {'toCheck': toCheck, 'toInstall': toInstall});
} else {
logs.add('BG update task $taskId: Ended.');
} }
} }

View File

@@ -708,17 +708,6 @@ class AppsProvider with ChangeNotifier {
logs.add('Could not reconcile version formats for: ${app.id}'); logs.add('Could not reconcile version formats for: ${app.id}');
modded = true; 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; return modded ? app : null;
} }