diff --git a/android/app/src/main/res/drawable/ic_notification.png b/android/app/src/main/res/drawable/ic_notification.png old mode 100644 new mode 100755 index ec6c2ca..41641ef Binary files a/android/app/src/main/res/drawable/ic_notification.png and b/android/app/src/main/res/drawable/ic_notification.png differ diff --git a/lib/main.dart b/lib/main.dart index 7a1e78e..53a0dd8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,25 +8,49 @@ import 'package:provider/provider.dart'; import 'package:workmanager/workmanager.dart'; import 'package:dynamic_color/dynamic_color.dart'; +@pragma('vm:entry-point') void backgroundUpdateCheck() { Workmanager().executeTask((task, inputData) async { var appsProvider = AppsProvider(bg: true); - await appsProvider.loadApps(); - List updates = await appsProvider.getUpdates(); - if (updates.isNotEmpty) { - String message = updates.length == 1 - ? '${updates[0].name} has an update.' - : '${(updates.length == 2 ? '${updates[0].name} and ${updates[1].name}' : '${updates[0].name} and ${updates.length - 1} more apps')} have updates.'; - await appsProvider.downloaderNotifications.cancel(2); + await appsProvider.notify( + 4, + 'Checking for Updates', + '', + 'BG_UPDATE_CHECK', + 'Checking for Updates', + 'Transient notification that appears when checking for updates', + important: false); + try { + await appsProvider.loadApps(); + List updates = await appsProvider.getUpdates(); + if (updates.isNotEmpty) { + String message = updates.length == 1 + ? '${updates[0].name} has an update.' + : '${(updates.length == 2 ? '${updates[0].name} and ${updates[1].name}' : '${updates[0].name} and ${updates.length - 1} more apps')} have updates.'; + await appsProvider.downloaderNotifications.cancel(2); + await appsProvider.notify( + 2, + 'Updates Available', + message, + 'UPDATES_AVAILABLE', + 'Updates Available', + 'Notifies the user that updates are available for one or more Apps tracked by Obtainium'); + } + return Future.value(true); + } catch (e) { + await appsProvider.downloaderNotifications.cancel(5); await appsProvider.notify( - 2, - 'Updates Available', - message, - 'UPDATES_AVAILABLE', - 'Updates Available', - 'Notifies the user that updates are available for one or more Apps tracked by Obtainium'); + 5, + 'Error Checking for Updates', + e.toString(), + 'BG_UPDATE_CHECK_ERROR', + 'Error Checking for Updates', + 'A notification that shows when background update checking fails', + important: false); + return Future.value(false); + } finally { + await appsProvider.downloaderNotifications.cancel(4); } - return Future.value(true); }); }