Fixed "return after delete" bug (#359)

This commit is contained in:
Imran Remtulla
2023-03-25 00:47:26 -04:00
parent 3bc5837999
commit 07c490bb0e
3 changed files with 15 additions and 8 deletions

View File

@ -210,7 +210,7 @@ class _ObtainiumState extends State<Obtainium> {
{'includePrereleases': true}, {'includePrereleases': true},
null, null,
false) false)
]); ], onlyIfExists: false);
} }
if (!supportedLocales if (!supportedLocales
.map((e) => e.languageCode) .map((e) => e.languageCode)

View File

@ -149,7 +149,7 @@ class _AddAppPageState extends State<AddAppPage> {
app.installedVersion = app.latestVersion; app.installedVersion = app.latestVersion;
} }
app.categories = pickedCategories; app.categories = pickedCategories;
await appsProvider.saveApps([app]); await appsProvider.saveApps([app], onlyIfExists: false);
return app; return app;
} }

View File

@ -628,7 +628,8 @@ class AppsProvider with ChangeNotifier {
} }
Future<void> saveApps(List<App> apps, Future<void> saveApps(List<App> apps,
{bool attemptToCorrectInstallStatus = true}) async { {bool attemptToCorrectInstallStatus = true,
bool onlyIfExists = true}) async {
attemptToCorrectInstallStatus = attemptToCorrectInstallStatus =
attemptToCorrectInstallStatus && (await doesInstalledAppsPluginWork()); attemptToCorrectInstallStatus && (await doesInstalledAppsPluginWork());
for (var app in apps) { for (var app in apps) {
@ -639,9 +640,15 @@ class AppsProvider with ChangeNotifier {
} }
File('${(await getAppsDir()).path}/${app.id}.json') File('${(await getAppsDir()).path}/${app.id}.json')
.writeAsStringSync(jsonEncode(app.toJson())); .writeAsStringSync(jsonEncode(app.toJson()));
this.apps.update( try {
app.id, (value) => AppInMemory(app, value.downloadProgress, info), this.apps.update(
ifAbsent: () => AppInMemory(app, null, info)); 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(); notifyListeners();
} }
@ -824,7 +831,7 @@ class AppsProvider with ChangeNotifier {
a.installedVersion = apps[a.id]?.app.installedVersion; a.installedVersion = apps[a.id]?.app.installedVersion;
} }
} }
await saveApps(importedApps); await saveApps(importedApps, onlyIfExists: false);
notifyListeners(); notifyListeners();
return importedApps.length; return importedApps.length;
} }
@ -844,7 +851,7 @@ class AppsProvider with ChangeNotifier {
if (apps.containsKey(app.id)) { if (apps.containsKey(app.id)) {
errorsMap.addAll({app.id: tr('appAlreadyAdded')}); errorsMap.addAll({app.id: tr('appAlreadyAdded')});
} else { } else {
await saveApps([app]); await saveApps([app], onlyIfExists: false);
} }
} }
List<List<String>> errors = List<List<String>> errors =