Enable experimental BG update support (not well tested) (#25)

This commit is contained in:
Imran Remtulla
2023-08-20 22:32:33 -04:00
parent 7c41692d5f
commit b59d3e77f9
15 changed files with 164 additions and 44 deletions

View File

@@ -247,6 +247,9 @@
"sortByFileNamesNotLinks": "Sort by file names instead of full links", "sortByFileNamesNotLinks": "Sort by file names instead of full links",
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "Želite li ukloniti aplikaciju?", "one": "Želite li ukloniti aplikaciju?",
"other": "Želite li ukloniti aplikacije?" "other": "Želite li ukloniti aplikacije?"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "{} i još 1 aplikacija je ažurirana.", "one": "{} i još 1 aplikacija je ažurirana.",
"other": "{} i još {} aplikacija je ažurirano." "other": "{} i još {} aplikacija je ažurirano."
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -247,6 +247,9 @@
"sortByFileNamesNotLinks": "Sortiere nach Dateinamen, anstelle von ganzen Links", "sortByFileNamesNotLinks": "Sortiere nach Dateinamen, anstelle von ganzen Links",
"filterReleaseNotesByRegEx": "Versionshinweise nach regulärem Ausdruck filtern", "filterReleaseNotesByRegEx": "Versionshinweise nach regulärem Ausdruck filtern",
"customLinkFilterRegex": "Benutzerdefinierter Link Filter nach Regulärem Ausdruck (Standard '.apk$')", "customLinkFilterRegex": "Benutzerdefinierter Link Filter nach Regulärem Ausdruck (Standard '.apk$')",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "App entfernen?", "one": "App entfernen?",
"other": "Apps entfernen?" "other": "Apps entfernen?"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "{} und 1 weitere Anwendung wurden aktualisiert.", "one": "{} und 1 weitere Anwendung wurden aktualisiert.",
"other": "{} und {} weitere Anwendungen wurden aktualisiert." "other": "{} und {} weitere Anwendungen wurden aktualisiert."
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -247,6 +247,9 @@
"sortByFileNamesNotLinks": "Sort by file names instead of full links", "sortByFileNamesNotLinks": "Sort by file names instead of full links",
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "Remove App?", "one": "Remove App?",
"other": "Remove Apps?" "other": "Remove Apps?"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "{} and 1 more app were updated.", "one": "{} and 1 more app were updated.",
"other": "{} and {} more apps were updated." "other": "{} and {} more apps were updated."
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -247,6 +247,9 @@
"sortByFileNamesNotLinks": "Sort by file names instead of full links", "sortByFileNamesNotLinks": "Sort by file names instead of full links",
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "¿Eliminar Aplicación?", "one": "¿Eliminar Aplicación?",
"other": "¿Eliminar Aplicaciones?" "other": "¿Eliminar Aplicaciones?"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "{} y 1 aplicación más han sido actualizadas.", "one": "{} y 1 aplicación más han sido actualizadas.",
"other": "{} y {} aplicaciones más han sido actualizadas." "other": "{} y {} aplicaciones más han sido actualizadas."
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -247,6 +247,9 @@
"sortByFileNamesNotLinks": "مرتب سازی بر اساس نام فایل به جای پیوندهای کامل", "sortByFileNamesNotLinks": "مرتب سازی بر اساس نام فایل به جای پیوندهای کامل",
"filterReleaseNotesByRegEx": "یادداشت های انتشار را با بیان منظم فیلتر کنید", "filterReleaseNotesByRegEx": "یادداشت های انتشار را با بیان منظم فیلتر کنید",
"customLinkFilterRegex": "فیلتر پیوند سفارشی بر اساس عبارت منظم (پیش‌فرض '.apk$')", "customLinkFilterRegex": "فیلتر پیوند سفارشی بر اساس عبارت منظم (پیش‌فرض '.apk$')",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "برنامه حذف شود؟", "one": "برنامه حذف شود؟",
"other": "برنامه ها حذف شوند؟" "other": "برنامه ها حذف شوند؟"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "{} و 1 برنامه دیگر به روز شدند.", "one": "{} و 1 برنامه دیگر به روز شدند.",
"other": "{} و {} برنامه دیگر به روز شدند." "other": "{} و {} برنامه دیگر به روز شدند."
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -247,6 +247,9 @@
"sortByFileNamesNotLinks": "Sort by file names instead of full links", "sortByFileNamesNotLinks": "Sort by file names instead of full links",
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "Supprimer l'application ?", "one": "Supprimer l'application ?",
"other": "Supprimer les applications ?" "other": "Supprimer les applications ?"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "{} et 1 autre application ont été mises à jour.", "one": "{} et 1 autre application ont été mises à jour.",
"other": "{} et {} autres applications ont été mises à jour." "other": "{} et {} autres applications ont été mises à jour."
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -246,6 +246,9 @@
"sortByFileNamesNotLinks": "Fájlnevek szerinti elrendezés teljes linkek helyett", "sortByFileNamesNotLinks": "Fájlnevek szerinti elrendezés teljes linkek helyett",
"filterReleaseNotesByRegEx": "Kiadási megjegyzések szűrése reguláris kifejezéssel", "filterReleaseNotesByRegEx": "Kiadási megjegyzések szűrése reguláris kifejezéssel",
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "Eltávolítja az alkalmazást?", "one": "Eltávolítja az alkalmazást?",
"other": "Eltávolítja az alkalmazást?" "other": "Eltávolítja az alkalmazást?"
@@ -293,5 +296,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "A(z) {} és 1 további alkalmazás frissítve.", "one": "A(z) {} és 1 további alkalmazás frissítve.",
"other": "{} és {} további alkalmazás frissítve." "other": "{} és {} további alkalmazás frissítve."
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -247,6 +247,9 @@
"sortByFileNamesNotLinks": "Sort by file names instead of full links", "sortByFileNamesNotLinks": "Sort by file names instead of full links",
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "Rimuovere l'app?", "one": "Rimuovere l'app?",
"other": "Rimuovere le app?" "other": "Rimuovere le app?"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "{} e un'altra app sono state aggiornate.", "one": "{} e un'altra app sono state aggiornate.",
"other": "{} e altre {} app sono state aggiornate." "other": "{} e altre {} app sono state aggiornate."
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -247,6 +247,9 @@
"sortByFileNamesNotLinks": "フルのリンクではなくファイル名でソートする", "sortByFileNamesNotLinks": "フルのリンクではなくファイル名でソートする",
"filterReleaseNotesByRegEx": "正規表現でリリースノートをフィルタリングする", "filterReleaseNotesByRegEx": "正規表現でリリースノートをフィルタリングする",
"customLinkFilterRegex": "正規表現によるカスタムリンクフィルター (デフォルト '.apk$')", "customLinkFilterRegex": "正規表現によるカスタムリンクフィルター (デフォルト '.apk$')",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "アプリを削除しますか?", "one": "アプリを削除しますか?",
"other": "アプリを削除しますか?" "other": "アプリを削除しますか?"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "{} とさらに {} 個のアプリがアップデートされました", "one": "{} とさらに {} 個のアプリがアップデートされました",
"other": "{} とさらに {} 個のアプリがアップデートされました" "other": "{} とさらに {} 個のアプリがアップデートされました"
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -251,6 +251,9 @@
"sortByFileNamesNotLinks": "Sortuj wg nazw plików zamiast pełnych linków", "sortByFileNamesNotLinks": "Sortuj wg nazw plików zamiast pełnych linków",
"filterReleaseNotesByRegEx": "Filtruj informacje o wersji według wyrażenia regularnego", "filterReleaseNotesByRegEx": "Filtruj informacje o wersji według wyrażenia regularnego",
"customLinkFilterRegex": "Niestandardowy filtr linków wg. wyrażenia regularnego (domyślnie \".apk$\")", "customLinkFilterRegex": "Niestandardowy filtr linków wg. wyrażenia regularnego (domyślnie \".apk$\")",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "Usunąć aplikację?", "one": "Usunąć aplikację?",
"other": "Usunąć aplikacje?" "other": "Usunąć aplikacje?"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "Zaktualizowano {} i jeszcze 1 aplikację.", "one": "Zaktualizowano {} i jeszcze 1 aplikację.",
"other": "Zaktualizowano {} i {} aplik." "other": "Zaktualizowano {} i {} aplik."
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -247,6 +247,9 @@
"sortByFileNamesNotLinks": "Sort by file names instead of full links", "sortByFileNamesNotLinks": "Sort by file names instead of full links",
"filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression", "filterReleaseNotesByRegEx": "Filter Release Notes by Regular Expression",
"customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')", "customLinkFilterRegex": "Custom Link Filter by Regular Expression (Default '.apk$')",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "Удалить приложение?", "one": "Удалить приложение?",
"other": "Удалить приложения?" "other": "Удалить приложения?"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "{} и еще 1 приложение были обновлены.", "one": "{} и еще 1 приложение были обновлены.",
"other": "{} и еще {} приложений были обновлены." "other": "{} и еще {} приложений были обновлены."
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -247,6 +247,9 @@
"sortByFileNamesNotLinks": "根据文件名而不是完整链接来排序", "sortByFileNamesNotLinks": "根据文件名而不是完整链接来排序",
"filterReleaseNotesByRegEx": "用正则表达式筛选发布说明", "filterReleaseNotesByRegEx": "用正则表达式筛选发布说明",
"customLinkFilterRegex": "用正则表达式自定义链接筛选(默认 '.apk$'", "customLinkFilterRegex": "用正则表达式自定义链接筛选(默认 '.apk$'",
"appsPossiblyUpdated": "App Updates Attempted",
"appsPossiblyUpdatedNotifDescription": "Notifies the user that updates to one or more Apps were potentially applied in the background",
"xWasPossiblyUpdatedToY": "An attempt was made to update {} to {}.",
"removeAppQuestion": { "removeAppQuestion": {
"one": "是否删除应用?", "one": "是否删除应用?",
"other": "是否删除应用?" "other": "是否删除应用?"
@@ -294,5 +297,9 @@
"xAndNMoreUpdatesInstalled": { "xAndNMoreUpdatesInstalled": {
"one": "{} 和另外 1 个应用已更新。", "one": "{} 和另外 1 个应用已更新。",
"other": "{} 和另外 {} 个应用已更新。" "other": "{} 和另外 {} 个应用已更新。"
},
"xAndNMoreUpdatesPossiblyInstalled": {
"one": "Attempts were made to update {} and 1 more app.",
"other": "Attempts were made to update {} and {} more apps."
} }
} }

View File

@@ -88,10 +88,8 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
: null; : null;
logs.add(tr('bgUpdateIgnoreAfterIs', args: [ignoreAfter.toString()])); logs.add(tr('bgUpdateIgnoreAfterIs', args: [ignoreAfter.toString()]));
var notificationsProvider = NotificationsProvider(); var notificationsProvider = NotificationsProvider();
await notificationsProvider.notify(checkingUpdatesNotification);
try { try {
var appsProvider = AppsProvider(); var appsProvider = AppsProvider();
await notificationsProvider.cancel(ErrorCheckingUpdatesNotification('').id);
await appsProvider.loadApps(); await appsProvider.loadApps();
List<String> existingUpdateIds = List<String> existingUpdateIds =
appsProvider.findExistingUpdates(installedOnly: true); appsProvider.findExistingUpdates(installedOnly: true);
@@ -100,7 +98,9 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
try { try {
logs.add(tr('startedActualBGUpdateCheck')); logs.add(tr('startedActualBGUpdateCheck'));
await appsProvider.checkUpdates( await appsProvider.checkUpdates(
ignoreAppsCheckedAfter: ignoreAfter, throwErrorsForRetry: true); ignoreAppsCheckedAfter: ignoreAfter,
throwErrorsForRetry: true,
notificationsProvider: notificationsProvider);
} catch (e) { } catch (e) {
if (e is RateLimitError || e is ClientException) { if (e is RateLimitError || e is ClientException) {
var remainingMinutes = e is RateLimitError ? e.remainingMinutes : 15; var remainingMinutes = e is RateLimitError ? e.remainingMinutes : 15;
@@ -124,34 +124,29 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
.where((id) => !existingUpdateIds.contains(id)) .where((id) => !existingUpdateIds.contains(id))
.map((e) => appsProvider.apps[e]!.app) .map((e) => appsProvider.apps[e]!.app)
.toList(); .toList();
List<App> nonSilentUpdates = [];
// TODO: This silent update code doesn't work yet List<App> silentUpdates = [];
// List<String> silentlyUpdated = await appsProvider for (var a in newUpdates) {
// .downloadAndInstallLatestApp( if (await appsProvider.canInstallSilently(a)) {
// [...newUpdates.map((e) => e.id), ...existingUpdateIds], null); silentUpdates.add(a);
// if (silentlyUpdated.isNotEmpty) { } else {
// newUpdates = newUpdates nonSilentUpdates.add(a);
// .where((element) => !silentlyUpdated.contains(element.id)) }
// .toList();
// notificationsProvider.notify(
// SilentUpdateNotification(
// silentlyUpdated.map((e) => appsProvider.apps[e]!.app).toList()),
// cancelExisting: true);
// }
logs.add(
plural('bgCheckFoundUpdatesWillNotifyIfNeeded', newUpdates.length));
if (newUpdates.isNotEmpty) {
notificationsProvider.notify(UpdateNotification(newUpdates));
} }
if (silentUpdates.isNotEmpty) {
await appsProvider.downloadAndInstallLatestApps(
silentUpdates.map((e) => e.id).toList(), null,
notificationsProvider: notificationsProvider);
}
logs.add(plural(
'bgCheckFoundUpdatesWillNotifyIfNeeded', nonSilentUpdates.length));
if (err != null) { if (err != null) {
throw err; throw err;
} }
} catch (e) { } catch (e) {
notificationsProvider logs.add('${tr('errorCheckingUpdates')}: ${e.toString()}');
.notify(ErrorCheckingUpdatesNotification(e.toString()));
} finally { } finally {
logs.add(tr('bgUpdateTaskFinished')); logs.add(tr('bgUpdateTaskFinished'));
await notificationsProvider.cancel(checkingUpdatesNotification.id);
} }
} }

View File

@@ -239,9 +239,8 @@ class AppsProvider with ChangeNotifier {
return downloadedFile; return downloadedFile;
} }
Future<Object> downloadApp(App app, BuildContext? context) async { Future<Object> downloadApp(App app, BuildContext? context,
NotificationsProvider? notificationsProvider = {NotificationsProvider? notificationsProvider}) async {
context?.read<NotificationsProvider>();
var notifId = DownloadNotification(app.finalName, 0).id; var notifId = DownloadNotification(app.finalName, 0).id;
if (apps[app.id] != null) { if (apps[app.id] != null) {
apps[app.id]!.downloadProgress = 0; apps[app.id]!.downloadProgress = 0;
@@ -507,7 +506,10 @@ class AppsProvider with ChangeNotifier {
// 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, BuildContext? context, List<String> appIds, BuildContext? context,
{SettingsProvider? settingsProvider}) async { {SettingsProvider? settingsProvider,
NotificationsProvider? notificationsProvider}) async {
notificationsProvider =
notificationsProvider ?? context?.read<NotificationsProvider>();
List<String> appsToInstall = []; List<String> appsToInstall = [];
List<String> trackOnlyAppsToUpdate = []; List<String> trackOnlyAppsToUpdate = [];
// For all specified Apps, filter out those for which: // For all specified Apps, filter out those for which:
@@ -567,8 +569,10 @@ class AppsProvider with ChangeNotifier {
for (var id in appsToInstall) { for (var id in appsToInstall) {
try { try {
// ignore: use_build_context_synchronously var downloadedArtifact =
var downloadedArtifact = await downloadApp(apps[id]!.app, context); // ignore: use_build_context_synchronously
await downloadApp(apps[id]!.app, context,
notificationsProvider: notificationsProvider);
DownloadedApk? downloadedFile; DownloadedApk? downloadedFile;
DownloadedXApkDir? downloadedDir; DownloadedXApkDir? downloadedDir;
if (downloadedArtifact is DownloadedApk) { if (downloadedArtifact is DownloadedApk) {
@@ -576,8 +580,8 @@ class AppsProvider with ChangeNotifier {
} else { } else {
downloadedDir = downloadedArtifact as DownloadedXApkDir; downloadedDir = downloadedArtifact as DownloadedXApkDir;
} }
bool willBeSilent = await canInstallSilently( var appId = downloadedFile?.appId ?? downloadedDir!.appId;
apps[downloadedFile?.appId ?? downloadedDir!.appId]!.app); bool willBeSilent = await canInstallSilently(apps[appId]!.app);
if (!(await settingsProvider?.getInstallPermission(enforce: false) ?? if (!(await settingsProvider?.getInstallPermission(enforce: false) ??
true)) { true)) {
throw ObtainiumError(tr('cancelled')); throw ObtainiumError(tr('cancelled'));
@@ -590,9 +594,24 @@ class AppsProvider with ChangeNotifier {
notifyListeners(); notifyListeners();
try { try {
if (downloadedFile != null) { if (downloadedFile != null) {
await installApk(downloadedFile); if (willBeSilent) {
// Would await forever - workaround - TODO
installApk(downloadedFile);
} else {
await installApk(downloadedFile);
}
} else { } else {
await installXApkDir(downloadedDir!); if (willBeSilent) {
// Would await forever - workaround - TODO
installXApkDir(downloadedDir!);
} else {
await installXApkDir(downloadedDir!);
}
}
if (willBeSilent) {
notificationsProvider?.notify(SilentUpdateAttemptNotification(
[apps[appId]!.app],
id: appId.hashCode));
} }
} finally { } finally {
apps[id]?.downloadProgress = null; apps[id]?.downloadProgress = null;
@@ -608,8 +627,6 @@ class AppsProvider with ChangeNotifier {
throw errors; throw errors;
} }
NotificationsProvider().cancel(UpdateNotification([]).id);
return installedIds; return installedIds;
} }
@@ -971,7 +988,8 @@ class AppsProvider with ChangeNotifier {
Future<List<App>> checkUpdates( Future<List<App>> checkUpdates(
{DateTime? ignoreAppsCheckedAfter, {DateTime? ignoreAppsCheckedAfter,
bool throwErrorsForRetry = false}) async { bool throwErrorsForRetry = false,
NotificationsProvider? notificationsProvider}) async {
List<App> updates = []; List<App> updates = [];
MultiAppMultiError errors = MultiAppMultiError(); MultiAppMultiError errors = MultiAppMultiError();
if (!gettingUpdates) { if (!gettingUpdates) {
@@ -998,9 +1016,14 @@ class AppsProvider with ChangeNotifier {
rethrow; rethrow;
} }
errors.add(appIds[i], e.toString()); errors.add(appIds[i], e.toString());
notificationsProvider?.notify(ErrorCheckingUpdatesNotification(
'${appIds[i]}: ${e.toString()}',
id: appIds[i].hashCode));
} }
if (newApp != null) { if (newApp != null) {
updates.add(newApp); updates.add(newApp);
notificationsProvider
?.notify(UpdateNotification([newApp], id: newApp.id.hashCode));
} }
} }
} finally { } finally {

View File

@@ -22,9 +22,9 @@ class ObtainiumNotification {
} }
class UpdateNotification extends ObtainiumNotification { class UpdateNotification extends ObtainiumNotification {
UpdateNotification(List<App> updates) UpdateNotification(List<App> updates, {int? id})
: super( : super(
2, id ?? 2,
tr('updatesAvailable'), tr('updatesAvailable'),
'', '',
'UPDATES_AVAILABLE', 'UPDATES_AVAILABLE',
@@ -41,8 +41,8 @@ class UpdateNotification extends ObtainiumNotification {
} }
class SilentUpdateNotification extends ObtainiumNotification { class SilentUpdateNotification extends ObtainiumNotification {
SilentUpdateNotification(List<App> updates) SilentUpdateNotification(List<App> updates, {int? id})
: super(3, tr('appsUpdated'), '', 'APPS_UPDATED', tr('appsUpdated'), : super(id ?? 3, tr('appsUpdated'), '', 'APPS_UPDATED', tr('appsUpdated'),
tr('appsUpdatedNotifDescription'), Importance.defaultImportance) { tr('appsUpdatedNotifDescription'), Importance.defaultImportance) {
message = updates.length == 1 message = updates.length == 1
? tr('xWasUpdatedToY', ? tr('xWasUpdatedToY',
@@ -52,10 +52,28 @@ class SilentUpdateNotification extends ObtainiumNotification {
} }
} }
class ErrorCheckingUpdatesNotification extends ObtainiumNotification { class SilentUpdateAttemptNotification extends ObtainiumNotification {
ErrorCheckingUpdatesNotification(String error) SilentUpdateAttemptNotification(List<App> updates, {int? id})
: super( : super(
5, id ?? 3,
tr('appsPossiblyUpdated'),
'',
'APPS_POSSIBLY_UPDATED',
tr('appsPossiblyUpdated'),
tr('appsPossiblyUpdatedNotifDescription'),
Importance.defaultImportance) {
message = updates.length == 1
? tr('xWasPossiblyUpdatedToY',
args: [updates[0].finalName, updates[0].latestVersion])
: plural('xAndNMoreUpdatesPossiblyInstalled', updates.length - 1,
args: [updates[0].finalName, (updates.length - 1).toString()]);
}
}
class ErrorCheckingUpdatesNotification extends ObtainiumNotification {
ErrorCheckingUpdatesNotification(String error, {int? id})
: super(
id ?? 5,
tr('errorCheckingUpdates'), tr('errorCheckingUpdates'),
error, error,
'BG_UPDATE_CHECK_ERROR', 'BG_UPDATE_CHECK_ERROR',