diff --git a/lib/main.dart b/lib/main.dart index 9d7f7ad..3ad511e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -210,7 +210,7 @@ class _ObtainiumState extends State { {'includePrereleases': true}, null, false) - ]); + ], onlyIfExists: false); } if (!supportedLocales .map((e) => e.languageCode) diff --git a/lib/pages/add_app.dart b/lib/pages/add_app.dart index f68ae3c..0138db1 100644 --- a/lib/pages/add_app.dart +++ b/lib/pages/add_app.dart @@ -149,7 +149,7 @@ class _AddAppPageState extends State { app.installedVersion = app.latestVersion; } app.categories = pickedCategories; - await appsProvider.saveApps([app]); + await appsProvider.saveApps([app], onlyIfExists: false); return app; } diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index f3069df..572f40b 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -628,7 +628,8 @@ class AppsProvider with ChangeNotifier { } Future saveApps(List apps, - {bool attemptToCorrectInstallStatus = true}) async { + {bool attemptToCorrectInstallStatus = true, + bool onlyIfExists = true}) async { attemptToCorrectInstallStatus = attemptToCorrectInstallStatus && (await doesInstalledAppsPluginWork()); for (var app in apps) { @@ -639,9 +640,15 @@ class AppsProvider with ChangeNotifier { } File('${(await getAppsDir()).path}/${app.id}.json') .writeAsStringSync(jsonEncode(app.toJson())); - this.apps.update( - app.id, (value) => AppInMemory(app, value.downloadProgress, info), - ifAbsent: () => AppInMemory(app, null, info)); + try { + this.apps.update( + app.id, (value) => AppInMemory(app, value.downloadProgress, info), + ifAbsent: onlyIfExists ? null : () => AppInMemory(app, null, info)); + } catch (e) { + if (e is! ArgumentError || e.name != 'key') { + rethrow; + } + } } notifyListeners(); } @@ -824,7 +831,7 @@ class AppsProvider with ChangeNotifier { a.installedVersion = apps[a.id]?.app.installedVersion; } } - await saveApps(importedApps); + await saveApps(importedApps, onlyIfExists: false); notifyListeners(); return importedApps.length; } @@ -844,7 +851,7 @@ class AppsProvider with ChangeNotifier { if (apps.containsKey(app.id)) { errorsMap.addAll({app.id: tr('appAlreadyAdded')}); } else { - await saveApps([app]); + await saveApps([app], onlyIfExists: false); } } List> errors =