Implement incremental loading via streaming

This commit is contained in:
2025-03-15 22:50:41 +01:00
parent b80959e58e
commit 2228aeeafa
2 changed files with 142 additions and 9 deletions

View File

@@ -177,7 +177,7 @@ class ModList {
ModList({required this.path});
void load() {
Stream<Mod> load() async* {
final directory = Directory(path);
print('Loading configuration from: $path');
@@ -187,8 +187,12 @@ class ModList {
entities.whereType<Directory>().map((dir) => dir.path).toList();
print('Found ${modDirectories.length} mod directories:');
for (final modDir in modDirectories) {
try {
// Add a small delay to prevent UI freezing and give time for rendering
await Future.delayed(const Duration(milliseconds: 5));
final mod = Mod.fromDirectory(modDir);
mods[mod.id] = mod;
print(
@@ -198,6 +202,8 @@ class ModList {
'Soft Dependencies: ${mod.softDependencies.join(', ')}, '
'Incompatibilities: ${mod.incompatabilities.join(', ')}',
);
yield mod;
print('Current total mods loaded: ${mods.length}');
} catch (e) {
print('Error loading mod from directory: $modDir');