@@ -87,12 +87,31 @@ public struct UserDefaultObject<T: Codable & Sendable> {
8787 }
8888}
8989
90- @MainActor
91- public struct HomePreferences : Codable , Equatable {
90+ public struct HomePreferences : Codable , Equatable , Sendable {
91+ private enum CodingKeys : String , CodingKey {
92+ case id
93+ case defaultView
94+ case demomode
95+ case realTimeSliders
96+ case showSearchField
97+ case iconType
98+ case defaultSitemap
99+ case sortSitemapsBy
100+ case defaultMainUIPath
101+ case alwaysAllowWebRTC
102+ case sitemapForWatch
103+ case localConnectionConfig
104+ case remoteConnectionConfig
105+ case sitemapForWatchLabel
106+ case homeName
107+ case sseCommandItem
108+ }
109+
92110 public let id : UUID
93111 public var defaultView = " web "
94112 public var demomode = true
95113 public var realTimeSliders = false
114+ public var showSearchField = true
96115 public var iconType = 0
97116 public var defaultSitemap = " demo "
98117 public var sortSitemapsBy = 0
@@ -108,25 +127,30 @@ public struct HomePreferences: Codable, Equatable {
108127 fileprivate init ( id: UUID ) {
109128 self . id = id
110129 }
111- }
112130
113- @MainActor
114- public struct ApplicationPreferences : Codable , Equatable {
115- public var showSearchField = true
131+ public init ( from decoder: Decoder ) throws {
132+ let container = try decoder. container ( keyedBy: CodingKeys . self)
133+ id = ( try ? container. decode ( UUID . self, forKey: . id) ) ?? UUID ( )
134+ defaultView = try container. decodeIfPresent ( String . self, forKey: . defaultView) ?? " web "
135+ demomode = try container. decodeIfPresent ( Bool . self, forKey: . demomode) ?? true
136+ realTimeSliders = try container. decodeIfPresent ( Bool . self, forKey: . realTimeSliders) ?? false
137+ showSearchField = try container. decodeIfPresent ( Bool . self, forKey: . showSearchField) ?? true
138+ iconType = try container. decodeIfPresent ( Int . self, forKey: . iconType) ?? 0
139+ defaultSitemap = try container. decodeIfPresent ( String . self, forKey: . defaultSitemap) ?? " demo "
140+ sortSitemapsBy = try container. decodeIfPresent ( Int . self, forKey: . sortSitemapsBy) ?? 0
141+ defaultMainUIPath = try container. decodeIfPresent ( String . self, forKey: . defaultMainUIPath) ?? " "
142+ alwaysAllowWebRTC = try container. decodeIfPresent ( Bool . self, forKey: . alwaysAllowWebRTC) ?? false
143+ sitemapForWatch = try container. decodeIfPresent ( String . self, forKey: . sitemapForWatch) ?? " watch "
144+ localConnectionConfig = try container. decodeIfPresent ( ConnectionConfiguration . self, forKey: . localConnectionConfig) ?? . localDefault
145+ remoteConnectionConfig = try container. decodeIfPresent ( ConnectionConfiguration . self, forKey: . remoteConnectionConfig) ?? . remoteDefault
146+ sitemapForWatchLabel = try container. decodeIfPresent ( String . self, forKey: . sitemapForWatchLabel) ?? " watch "
147+ homeName = try container. decodeIfPresent ( String . self, forKey: . homeName) ?? " Home "
148+ sseCommandItem = try container. decodeIfPresent ( String . self, forKey: . sseCommandItem) ?? " "
149+ }
116150}
117151
118152// MARK: Retrieving preference from user defaults, reacting to preference change
119153
120- // MARK: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
121-
122- // MARK: !!
123-
124- // MARK: When making changes to Preferences, always consider a migration for existing users. Otherwise, they risk to loose their existing preferences.
125-
126- // MARK: !!
127-
128- // MARK: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
129-
130154private enum PreferencesAccess {
131155 @MainActor fileprivate static func getPreference< T> ( key: String , defaultValue: T , encoder: ( T ) -> ( some Sendable ) ? , decoder: ( Any ? ) -> T ? ) -> T {
132156 let preferenceValue = sharedDefaults. object ( forKey: key)
@@ -176,12 +200,8 @@ public actor Preferences {
176200 @UserDefault ( " idleOff " , defaultValue: false )
177201 public var idleOff : Bool
178202
179- @UserDefaultObject (
180- " applicationPreferences " ,
181- defaultValue:
182- ApplicationPreferences ( )
183- )
184- public private( set) var applicationPreferences : ApplicationPreferences
203+ @UserDefault ( " showSearchField " , defaultValue: true )
204+ public var showSearchField : Bool
185205
186206 @UserDefault ( " screensaverEnabled " , defaultValue: false )
187207 public var screensaverEnabled : Bool
@@ -355,12 +375,6 @@ public extension Preferences {
355375 currentHomePreferences = homePreferences
356376 storeActiveHome ( )
357377 }
358-
359- func modifyApplicationPreferences( modificationFunction: @MainActor ( inout ApplicationPreferences ) -> Void ) {
360- var applicationPreferences = applicationPreferences
361- modificationFunction ( & applicationPreferences)
362- self . applicationPreferences = applicationPreferences
363- }
364378}
365379
366380@MainActor
@@ -404,6 +418,7 @@ public extension Preferences {
404418 currentHomePreferences. remoteConnectionConfig. ignoreSSL = UserDefaults . standard. object ( forKey: " ignoreSSL " ) as? Bool ?? currentHomePreferences. remoteConnectionConfig. ignoreSSL
405419 currentHomePreferences. demomode = UserDefaults . standard. object ( forKey: " demomode " ) as? Bool ?? currentHomePreferences. demomode
406420 currentHomePreferences. realTimeSliders = UserDefaults . standard. object ( forKey: " realTimeSliders " ) as? Bool ?? currentHomePreferences. realTimeSliders
421+ currentHomePreferences. showSearchField = UserDefaults . standard. object ( forKey: " showSearchField " ) as? Bool ?? currentHomePreferences. showSearchField
407422 currentHomePreferences. iconType = UserDefaults . standard. object ( forKey: " iconType " ) as? Int ?? currentHomePreferences. iconType
408423 currentHomePreferences. defaultSitemap = UserDefaults . standard. string ( forKey: " defaultSitemap " ) ?? currentHomePreferences. defaultSitemap
409424 }
@@ -446,6 +461,7 @@ public extension Preferences {
446461 currentHomePreferences. defaultView = sharedDefaults. string ( forKey: " defaultView " ) ?? currentHomePreferences. defaultView
447462 currentHomePreferences. demomode = sharedDefaults. object ( forKey: " demomode " ) as? Bool ?? currentHomePreferences. demomode
448463 currentHomePreferences. realTimeSliders = sharedDefaults. object ( forKey: " realTimeSliders " ) as? Bool ?? currentHomePreferences. realTimeSliders
464+ currentHomePreferences. showSearchField = sharedDefaults. object ( forKey: " showSearchField " ) as? Bool ?? currentHomePreferences. showSearchField
449465 currentHomePreferences. iconType = sharedDefaults. object ( forKey: " iconType " ) as? Int ?? currentHomePreferences. iconType
450466 currentHomePreferences. defaultSitemap = sharedDefaults. string ( forKey: " defaultSitemap " ) ?? currentHomePreferences. defaultSitemap
451467 currentHomePreferences. sortSitemapsBy = sharedDefaults. object ( forKey: " sortSitemapsBy " ) as? Int ?? currentHomePreferences. sortSitemapsBy
0 commit comments