From 0e51c00bca437eaba3ef50fe7ffee7df42742a30 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 24 Apr 2024 17:08:13 -0300 Subject: [PATCH] Properly migrate existing users to new plugin setup --- .../seedvault/settings/SettingsManager.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt index 81251c47..d6e977c0 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt @@ -102,11 +102,23 @@ class SettingsManager(private val context: Context) { } internal val storagePluginType: StoragePluginEnum? - get() = prefs.getString(PREF_KEY_STORAGE_PLUGIN, StoragePluginEnum.SAF.name)?.let { - try { - StoragePluginEnum.valueOf(it) - } catch (e: IllegalArgumentException) { - null + get() { + val savedType = prefs.getString(PREF_KEY_STORAGE_PLUGIN, null) + return if (savedType == null) { + // check if this is an existing user that needs to be migrated + // this check could be removed after a reasonable migration time (added 2024) + if (prefs.getString(PREF_KEY_STORAGE_URI, null) != null) { + prefs.edit() + .putString(PREF_KEY_STORAGE_PLUGIN, StoragePluginEnum.SAF.name) + .apply() + StoragePluginEnum.SAF + } else null + } else savedType.let { + try { + StoragePluginEnum.valueOf(it) + } catch (e: IllegalArgumentException) { + null + } } }