Merge pull request #646 from ericszimmermann/ez_backup-restore
Backup and Restore functionality
This commit is contained in:
42 files changed
+7629
-251
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,14 @@ class MessageFilterService extends ChangeNotifier {
|
||||
@visibleForTesting
|
||||
int get recentCleanCount => _recentClean.length;
|
||||
|
||||
@visibleForTesting
|
||||
bool hasRecentCleanExample(String text) {
|
||||
final key = MessageFilterText.normalize(text);
|
||||
return _recentClean.any(
|
||||
(example) => MessageFilterText.normalize(example.text) == key,
|
||||
);
|
||||
}
|
||||
|
||||
/// Loads persisted state and trains the classifier.
|
||||
Future<void> load() async {
|
||||
try {
|
||||
|
||||
@@ -143,18 +143,25 @@ class TranslationService extends ChangeNotifier {
|
||||
return availableModels.isNotEmpty ? availableModels.first : null;
|
||||
}
|
||||
|
||||
Future<void> refreshDownloadedModels() async {
|
||||
Future<void> refreshDownloadedModels({bool clearMissing = false}) async {
|
||||
if (_isDownloading) return;
|
||||
final scanned = await _fileStore.scanDownloadedModels();
|
||||
if (scanned.isEmpty && !clearMissing) return;
|
||||
if (scanned.isEmpty) {
|
||||
await _appSettingsService.setTranslationDownloadedModels(const []);
|
||||
return;
|
||||
}
|
||||
final existingByPath = {
|
||||
for (final model in _settings.translationDownloadedModels)
|
||||
model.localPath: model,
|
||||
};
|
||||
final existingByName = {
|
||||
for (final model in _settings.translationDownloadedModels)
|
||||
model.name: model,
|
||||
};
|
||||
final merged = scanned.map((model) {
|
||||
final existing = existingByPath[model.localPath];
|
||||
final existing =
|
||||
existingByPath[model.localPath] ?? existingByName[model.name];
|
||||
if (existing == null) {
|
||||
return model;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user