Initial migratable Settings#1126
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the “show search field” setting to be stored as part of per-home preferences and makes HomePreferences decoding more resilient to schema changes, supporting smoother preference migrations.
Changes:
- Added
showSearchFieldtoHomePreferencesand implemented a custominit(from:)to supply defaults for missing keys during decoding. - Removed
ApplicationPreferencesand updated UI/view-model code to read/writeshowSearchFieldviacurrentHomePreferences. - Updated migration logic to carry forward the legacy
showSearchFieldvalue into the active home.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
OpenHABCore/Sources/OpenHABCore/Util/Preferences.swift |
Adds migratable decoding for HomePreferences, moves showSearchField into home-scoped preferences, and updates migrations. |
openHAB/UI/SettingsView/SettingsView.swift |
Reads/writes showSearchField from/to the active home preferences instead of application-level preferences. |
openHAB/Models/SitemapPageViewModel.swift |
Loads showSearchField from the active home preferences when applying settings. |
| // MARK: Retrieving preference from user defaults, reacting to preference change | ||
|
|
||
| // MARK: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| // MARK: !! | ||
|
|
||
| // MARK: When making changes to Preferences, always consider a migration for existing users. Otherwise, they risk to loose their existing preferences. | ||
|
|
||
| // MARK: !! | ||
|
|
||
| // MARK: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| private enum PreferencesAccess { | ||
| @MainActor fileprivate static func getPreference<T>(key: String, defaultValue: T, encoder: (T) -> (some Sendable)?, decoder: (Any?) -> T?) -> T { |
There was a problem hiding this comment.
The prominent in-file warning about needing migrations when changing Preferences was removed, and there doesn’t appear to be an equivalent note elsewhere in the repo. Given that UserDefaultObject falls back to defaults (and overwrites stored data) when decoding fails, keeping a clear reminder near the preference schema helps prevent accidental preference loss. Consider restoring a shorter version of the warning here or moving it to a central contributor doc with a reference from this file.
3e8c13b to
2c04d7c
Compare
Signed-off-by: DigiH <17110652+DigiH@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: DigiH <17110652+DigiH@users.noreply.github.com>
No description provided.