mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-16 11:48:09 +02:00
More efficient loading (addresses #110)
This commit is contained in:
@@ -424,22 +424,28 @@ class AppsProvider with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
loadingApps = true;
|
loadingApps = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
List<FileSystemEntity> appFiles = (await getAppsDir())
|
List<App> newApps = (await getAppsDir())
|
||||||
.listSync()
|
.listSync()
|
||||||
.where((item) => item.path.toLowerCase().endsWith('.json'))
|
.where((item) => item.path.toLowerCase().endsWith('.json'))
|
||||||
|
.map((e) => App.fromJson(jsonDecode(File(e.path).readAsStringSync())))
|
||||||
.toList();
|
.toList();
|
||||||
apps.clear();
|
var idsToDelete = apps.values
|
||||||
|
.map((e) => e.app.id)
|
||||||
|
.toSet()
|
||||||
|
.difference(newApps.map((e) => e.id).toSet());
|
||||||
|
for (var id in idsToDelete) {
|
||||||
|
apps.remove(id);
|
||||||
|
}
|
||||||
var sp = SourceProvider();
|
var sp = SourceProvider();
|
||||||
List<List<String>> errors = [];
|
List<List<String>> errors = [];
|
||||||
for (int i = 0; i < appFiles.length; i++) {
|
for (int i = 0; i < newApps.length; i++) {
|
||||||
App app =
|
var info = await getInstalledInfo(newApps[i].id);
|
||||||
App.fromJson(jsonDecode(File(appFiles[i].path).readAsStringSync()));
|
|
||||||
var info = await getInstalledInfo(app.id);
|
|
||||||
try {
|
try {
|
||||||
sp.getSource(app.url);
|
sp.getSource(newApps[i].url);
|
||||||
apps.putIfAbsent(app.id, () => AppInMemory(app, null, info));
|
apps.putIfAbsent(
|
||||||
|
newApps[i].id, () => AppInMemory(newApps[i], null, info));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errors.add([app.id, app.name, e.toString()]);
|
errors.add([newApps[i].id, newApps[i].name, e.toString()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (errors.isNotEmpty) {
|
if (errors.isNotEmpty) {
|
||||||
|
Reference in New Issue
Block a user