@@ -147,6 +147,7 @@ class SettingsStore: ObservableObject {
147147 private let fingerprintingKey = " settings.tracking.blockFingerprinting "
148148 private let adBlockingKey = " settings.tracking.adBlocking "
149149 private let cookiesPolicyKey = " settings.cookies.policy "
150+ private let adBlockFilterListsKey = " settings.adBlock.filterLists "
150151 private let sitePermissionsKey = " settings.permissions.sitePermissions "
151152 private let customSearchEnginesKey = " settings.customSearchEngines "
152153 private let globalDefaultSearchEngineKey = " settings.globalDefaultSearchEngine "
@@ -176,6 +177,10 @@ class SettingsStore: ObservableObject {
176177 " settings.container. \( containerId. uuidString) .autoClearTabsAfter "
177178 }
178179
180+ private func keyForPrivacySettings( for containerId: UUID ) -> String {
181+ " settings.container. \( containerId. uuidString) .privacy "
182+ }
183+
179184 @Published var autoUpdateEnabled : Bool {
180185 didSet { defaults. set ( autoUpdateEnabled, forKey: autoUpdateKey) }
181186 }
@@ -200,6 +205,10 @@ class SettingsStore: ObservableObject {
200205 didSet { saveCodable ( sitePermissions, forKey: sitePermissionsKey) }
201206 }
202207
208+ @Published private( set) var adBlockFilterLists : [ FilterListRecord ] {
209+ didSet { saveCodable ( adBlockFilterLists, forKey: adBlockFilterListsKey) }
210+ }
211+
203212 @Published var customSearchEngines : [ CustomSearchEngine ] {
204213 didSet { saveCodable ( customSearchEngines, forKey: customSearchEnginesKey) }
205214 }
@@ -258,7 +267,7 @@ class SettingsStore: ObservableObject {
258267 init ( ) {
259268 autoUpdateEnabled = defaults. bool ( forKey: autoUpdateKey)
260269 blockThirdPartyTrackers = defaults. bool ( forKey: trackingThirdPartyKey)
261- blockFingerprinting = defaults. bool ( forKey: fingerprintingKey)
270+ blockFingerprinting = defaults. object ( forKey: fingerprintingKey) as? Bool ?? true
262271 adBlocking = defaults. bool ( forKey: adBlockingKey)
263272 if let raw = defaults. string ( forKey: cookiesPolicyKey) ,
264273 let policy = CookiesPolicy ( rawValue: raw)
@@ -271,6 +280,10 @@ class SettingsStore: ObservableObject {
271280 sitePermissions =
272281 Self . loadCodable ( [ String : SitePermissionSettings ] . self, key: sitePermissionsKey) ?? [ : ]
273282
283+ adBlockFilterLists = FilterListCatalogService . shared. normalizedRecords (
284+ from: Self . loadCodable ( [ FilterListRecord ] . self, key: adBlockFilterListsKey) ?? [ ]
285+ )
286+
274287 customSearchEngines =
275288 Self . loadCodable ( [ CustomSearchEngine ] . self, key: customSearchEnginesKey) ?? [ ]
276289
@@ -358,10 +371,29 @@ class SettingsStore: ObservableObject {
358371 objectWillChange. send ( )
359372 }
360373
374+ func privacySettings( for containerId: UUID ) -> SpacePrivacySettings {
375+ Self . loadCodable ( SpacePrivacySettings . self, key: keyForPrivacySettings ( for: containerId) )
376+ ?? legacyPrivacySettings
377+ }
378+
379+ func setPrivacySettings( _ value: SpacePrivacySettings , for containerId: UUID ) {
380+ saveCodable ( value, forKey: keyForPrivacySettings ( for: containerId) )
381+ objectWillChange. send ( )
382+ }
383+
384+ func notifySpacePrivacySettingsChanged( for containerId: UUID ) {
385+ NotificationCenter . default. post (
386+ name: . spacePrivacySettingsChanged,
387+ object: nil ,
388+ userInfo: [ " containerId " : containerId]
389+ )
390+ }
391+
361392 func removeContainerSettings( for containerId: UUID ) {
362393 defaults. removeObject ( forKey: keyForDefaultSearch ( for: containerId) )
363394 defaults. removeObject ( forKey: keyForDefaultAI ( for: containerId) )
364395 defaults. removeObject ( forKey: keyForAutoClear ( for: containerId) )
396+ defaults. removeObject ( forKey: keyForPrivacySettings ( for: containerId) )
365397 objectWillChange. send ( )
366398 }
367399
@@ -387,6 +419,32 @@ class SettingsStore: ObservableObject {
387419 customSearchEngines = engines
388420 }
389421
422+ // MARK: - Ad block filter catalog
423+
424+ func adBlockFilterList( id: String ) -> FilterListRecord ? {
425+ adBlockFilterLists. first { $0. id == id }
426+ }
427+
428+ func setAdBlockFilterLists( _ records: [ FilterListRecord ] ) {
429+ adBlockFilterLists = FilterListCatalogService . shared. normalizedRecords ( from: records)
430+ }
431+
432+ func upsertAdBlockFilterList( _ record: FilterListRecord ) {
433+ var records = adBlockFilterLists
434+ if let index = records. firstIndex ( where: { $0. id == record. id } ) {
435+ records [ index] = record
436+ } else {
437+ records. append ( record)
438+ }
439+ adBlockFilterLists = FilterListCatalogService . shared. normalizedRecords ( from: records)
440+ }
441+
442+ func removeAdBlockFilterList( id: String ) {
443+ adBlockFilterLists = FilterListCatalogService . shared. normalizedRecords (
444+ from: adBlockFilterLists. filter { $0. id != id }
445+ )
446+ }
447+
390448 func removeCustomSearchEngine( withId id: String ) {
391449 customSearchEngines = customSearchEngines. filter { $0. id != id }
392450 }
@@ -459,4 +517,13 @@ class SettingsStore: ObservableObject {
459517 abs ( lhs - value) < abs ( rhs - value)
460518 } ?? defaultSeconds
461519 }
520+
521+ private var legacyPrivacySettings : SpacePrivacySettings {
522+ SpacePrivacySettings (
523+ blockThirdPartyTrackers: blockThirdPartyTrackers,
524+ blockFingerprinting: blockFingerprinting,
525+ adBlocking: adBlocking,
526+ cookiesPolicy: cookiesPolicy
527+ )
528+ }
462529}
0 commit comments