ask for download models and fix problem with reloading discovered list after import.

This commit is contained in:
ericz committed 2026-11-08 14:13:33 +01:00
1 parent be28a1a258
commit a020eb30d0
32 files changed
+944 -9

No files matched your search

+12 -4
View File
@@ -385,7 +385,7 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
///
/// Call once at startup, next to
/// `await translationService.refreshDownloadedModels();` in `main.dart`.
Future<void> refreshDownloadedModels() async {
Future<void> refreshDownloadedModels({bool clearMissing = false}) async {
if (_isDownloading) return;
await _settingsStore.load();
if (kIsWeb) {
@@ -393,7 +393,7 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
return;
}
final scanned = await _fileStore.scanDownloadedModels();
if (scanned.isEmpty) {
if (scanned.isEmpty && !clearMissing) {
_notify();
return;
}
@@ -405,6 +405,9 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
final existingByPath = {
for (final model in preferences.downloadedModels) model.localPath: model,
};
final existingByName = {
for (final model in preferences.downloadedModels) model.name: model,
};
final merged = <ImageCodecModelRecord>[];
// Every filename the registry knows about, so a half-installed bundle's
// leftovers are never mistaken for standalone models.
@@ -457,9 +460,14 @@ class ImageCodecService extends ChangeNotifier implements ImageSendCodec {
// as its own single-file record so a hand-fetched graph is not deleted.
for (final model in scanned) {
if (claimed.contains(model.name)) continue;
final existing = existingByPath[model.localPath];
final existing =
existingByPath[model.localPath] ?? existingByName[model.name];
merged.add(
existing?.copyWith(fileSizeBytes: model.fileSizeBytes) ?? model,
existing?.copyWith(
localPath: model.localPath,
fileSizeBytes: model.fileSizeBytes,
) ??
model,
);
}