Skip to content

Commit

Permalink
Properly migrate existing users to new plugin setup
Browse files Browse the repository at this point in the history
  • Loading branch information
grote committed Apr 24, 2024
1 parent e92c9c9 commit 2458263
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 2458263

Please sign in to comment.