Add metrics and a UI of some sort

This commit is contained in:
2025-03-15 23:04:08 +01:00
parent 2228aeeafa
commit ebfce153ea
2 changed files with 88 additions and 43 deletions

View File

@@ -1,16 +1,16 @@
import 'package:flutter/material.dart';
import 'package:rimworld_modman/modloader.dart';
import 'dart:io';
// Global variable to store loaded mods for access across the app
late ModList modManager;
void main() {
// Initialize the mod manager
modManager = ModList(path: modsRoot);
modManager.load().listen((mod) {
print(mod);
});
// runApp(const RimWorldModManager());
// Start the app
runApp(const RimWorldModManager());
}
class RimWorldModManager extends StatelessWidget {
@@ -95,14 +95,14 @@ class _ModListPageState extends State<ModListPage> {
bool _isLoading = false;
String _loadingStatus = '';
int _totalModsFound = 0;
bool _skipFileCount = true; // Skip file counting by default for faster loading
@override
Widget build(BuildContext context) {
return Scaffold(
body:
_loadedMods.isEmpty && !_isLoading
? _buildEmptyState()
: _buildModList(),
body: _loadedMods.isEmpty && !_isLoading
? _buildEmptyState()
: _buildModList(),
);
}
@@ -119,6 +119,21 @@ class _ModListPageState extends State<ModListPage> {
'Ready to scan for RimWorld mods.',
style: Theme.of(context).textTheme.bodyLarge,
),
const SizedBox(height: 12),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Checkbox(
value: _skipFileCount,
onChanged: (value) {
setState(() {
_skipFileCount = value ?? true;
});
},
),
const Text('Skip file counting (faster loading)'),
],
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: _startLoadingMods,
@@ -205,14 +220,27 @@ class _ModListPageState extends State<ModListPage> {
_loadingStatus = 'Scanning for mods...';
});
// Use batch loading for better performance
// First get the mod directories to know the total count
final directory = Directory(modsRoot);
if (directory.existsSync()) {
final List<FileSystemEntity> entities = directory.listSync();
final List<String> modDirectories =
entities.whereType<Directory>().map((dir) => dir.path).toList();
setState(() {
_totalModsFound = modDirectories.length;
_loadingStatus = 'Found $_totalModsFound mod directories. Loading...';
});
}
// Use the serial loading with our skipFileCount option
modManager
.load()
.load(skipFileCount: _skipFileCount)
.listen(
(mod) {
setState(() {
_loadedMods.add(mod);
_loadingStatus = 'Loaded ${_loadedMods.length} mods...';
_loadingStatus = 'Loaded ${_loadedMods.length}/$_totalModsFound mods...';
});
},
onError: (error) {