Skip to content

An open-source cross-platform alternative to AirDrop

fix: migrate old quick save settings to prevent a startup crash (#3558)

Shlomo14f3a87426ee
diff --git a/app/lib/provider/persistence_provider.dart b/app/lib/provider/persistence_provider.dart
index 250edf9e..cc77c075 100644
--- a/app/lib/provider/persistence_provider.dart
+++ b/app/lib/provider/persistence_provider.dart
@@ -130,14 +130,16 @@ class PersistenceService {
}
final bool isFirstAppStart;
- final existingVersion = (await SharedPreferencesStorePlatform.instance.getAll())['flutter.$_version'] as int?;
+ final existingPrefs = await SharedPreferencesStorePlatform.instance.getAll();
+ final existingVersion = existingPrefs['flutter.$_version'] as int?;
_logger.info('Existing version: $existingVersion');
- if (existingVersion == null && !usingLegacyStore) {
- isFirstAppStart = true;
+ isFirstAppStart = existingVersion == null && !usingLegacyStore && !existingPrefs.keys.any((key) => key.startsWith('flutter.ls_'));
+ if (isFirstAppStart) {
await SharedPreferencesStorePlatform.instance.setValue('Int', 'flutter.$_version', _latestVersion);
} else {
- isFirstAppStart = false;
- final fromVersion = existingVersion ?? 1;
+ // Unversioned profiles in the current store may already contain string modes.
+ // Only apply the repair migration; older migrations would replace those modes.
+ final fromVersion = existingVersion ?? (usingLegacyStore ? 1 : 3);
if (fromVersion < _latestVersion) {
await _runMigrations(fromVersion);
}
diff --git a/app/lib/provider/persistence_provider_migrations.dart b/app/lib/provider/persistence_provider_migrations.dart
index 1bfad218..f2c43280 100644
--- a/app/lib/provider/persistence_provider_migrations.dart
+++ b/app/lib/provider/persistence_provider_migrations.dart
@@ -1,6 +1,6 @@
part of 'persistence_provider.dart';
-const _latestVersion = 3;
+const _latestVersion = 4;
Future<void> _runMigrations(int from) async {
if (from < 2) {
@@ -11,6 +11,10 @@ Future<void> _runMigrations(int from) async {
await _migrate3();
await SharedPreferencesStorePlatform.instance.setValue('Int', 'flutter.$_version', 3);
}
+ if (from < 4) {
+ await _migrate4();
+ await SharedPreferencesStorePlatform.instance.setValue('Int', 'flutter.$_version', 4);
+ }
}
Future<void> _migrate2() async {
@@ -49,3 +53,14 @@ Future<void> _migrate3() async {
// some users disabled HTTPS for performance reasons which no longer apply since the Rust migration
await SharedPreferencesStorePlatform.instance.setValue('Bool', 'flutter.$_https', true);
}
+
+Future<void> _migrate4() async {
+ _logger.info('Migrating to version 4');
+ final prefs = await SharedPreferencesStorePlatform.instance.getAll();
+ final value = prefs['flutter.$_quickSave'];
+ if (value is bool) {
+ // Match migration 3 and the favorites-only default announced in What's new in 1.18.0.
+ final quickSave = value ? QuickSaveMode.on : QuickSaveMode.paired;
+ await SharedPreferencesStorePlatform.instance.setValue('String', 'flutter.$_quickSave', quickSave.name);
+ }
+}