Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit dc1d84e

Browse files
authored
Fixes App Data Clearing State Status In Settings (#3041)
Task/Issue URL: https://app.asana.com/0/1204099484721401/1207731330276486/f Description: Fixes an issue that caused the "Automatically Clear Data" state in settings to be out of sync. Fixed by observing Data Clearing updates. – (Eventually, this and all other parts of AppSettings should adopt Combine publishers instead of Notifications, but this does the trick today)
1 parent 2a5a11f commit dc1d84e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

DuckDuckGo/AppUserDefaults.swift

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class AppUserDefaults: AppSettings {
4040
public static let showsFullURLAddressSettingChanged = Notification.Name("com.duckduckgo.app.ShowsFullURLAddressSettingChanged")
4141
public static let autofillDebugScriptToggled = Notification.Name("com.duckduckgo.app.DidToggleAutofillDebugScript")
4242
public static let duckPlayerSettingsUpdated = Notification.Name("com.duckduckgo.app.DuckPlayerSettingsUpdated")
43+
public static let appDataClearingUpdated = Notification.Name("com.duckduckgo.app.dataClearingUpdates")
4344
}
4445

4546
private let groupName: String
@@ -154,6 +155,7 @@ public class AppUserDefaults: AppSettings {
154155

155156
set {
156157
userDefaults?.setValue(newValue.rawValue, forKey: Keys.autoClearActionKey)
158+
NotificationCenter.default.post(name: Notifications.appDataClearingUpdated, object: nil)
157159
}
158160

159161
}

DuckDuckGo/SettingsViewModel.swift

+13
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ final class SettingsViewModel: ObservableObject {
6060
private lazy var isPad = UIDevice.current.userInterfaceIdiom == .pad
6161
private var cancellables = Set<AnyCancellable>()
6262

63+
// App Data State Notification Observer
64+
private var appDataClearingObserver: Any?
65+
6366
// Closures to interact with legacy view controllers through the container
6467
var onRequestPushLegacyView: ((UIViewController) -> Void)?
6568
var onRequestPresentLegacyView: ((UIViewController, _ modal: Bool) -> Void)?
@@ -345,6 +348,7 @@ final class SettingsViewModel: ObservableObject {
345348

346349
deinit {
347350
subscriptionSignOutObserver = nil
351+
appDataClearingObserver = nil
348352
}
349353
}
350354
// swiftlint:enable type_body_length
@@ -732,6 +736,15 @@ extension SettingsViewModel {
732736
}
733737
}
734738
}
739+
740+
// Observe App Data clearing state
741+
appDataClearingObserver = NotificationCenter.default.addObserver(forName: AppUserDefaults.Notifications.appDataClearingUpdated,
742+
object: nil,
743+
queue: .main) { [weak self] _ in
744+
guard let settings = self?.appSettings else { return }
745+
self?.state.autoclearDataEnabled = (AutoClearSettingsModel(settings: settings) != nil)
746+
}
747+
735748
}
736749

737750
@available(iOS 15.0, *)

0 commit comments

Comments
 (0)