From 5e3a9d917063275cc3c6b9c44dc42e5962d48363 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 Sep 2024 10:54:08 +0200 Subject: [PATCH] feat(account): update UserDefaults+Ext.swift --- .../Scenes/AccountScreen/AccountViewController.swift | 7 ++++--- IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift index 0168cec15..5f251cd8e 100644 --- a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift +++ b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift @@ -37,7 +37,6 @@ class AccountViewController: UITableViewController { private var serviceType = ServiceType.getType(currentPlan: Application.shared.serviceStatus.currentPlan) private var deleteSettings = false private var forceLogOut = false - private var accountHidden = false var sessionManager: SessionManager { let sessionManager = SessionManager() @@ -79,8 +78,9 @@ class AccountViewController: UITableViewController { } @IBAction func toggleAccountHidden(_ sender: Any) { - accountView.toggleAccountVisibility(hide: accountHidden) - accountHidden = !accountHidden + let hidden = UserDefaults.shared.isAccountHidden + accountView.toggleAccountVisibility(hide: hidden) + UserDefaults.shared.set(!hidden, forKey: UserDefaults.Key.isAccountHidden) } // MARK: - View Lifecycle - @@ -96,6 +96,7 @@ class AccountViewController: UITableViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) accountView.initQRCode(viewModel: viewModel) + accountView.toggleAccountVisibility(hide: UserDefaults.shared.isAccountHidden) sessionManager.getSessionStatus() } diff --git a/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift b/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift index ec4449b09..551e40c57 100644 --- a/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift +++ b/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift @@ -95,6 +95,7 @@ extension UserDefaults { static let v2rayProtocol = "v2rayProtocol" static let isV2ray = "isV2ray" static let disableWidgetPrompt = "disableWidgetPrompt" + static let isAccountHidden = "isAccountHidden" } @objc dynamic var wireguardTunnelProviderError: String { @@ -261,6 +262,10 @@ extension UserDefaults { return bool(forKey: Key.disableWidgetPrompt) } + @objc dynamic var isAccountHidden: Bool { + return bool(forKey: Key.isAccountHidden) + } + static func registerUserDefaults() { shared.register(defaults: [Key.networkProtectionUntrustedConnect: true]) shared.register(defaults: [Key.networkProtectionTrustedDisconnect: true]) @@ -268,6 +273,7 @@ extension UserDefaults { shared.register(defaults: [Key.wgRegenerationRate: Config.wgKeyRegenerationRate]) shared.register(defaults: [Key.wgKeyTimestamp: Date()]) shared.register(defaults: [Key.serversSort: "city"]) + shared.register(defaults: [Key.isAccountHidden: true]) standard.register(defaults: [Key.selectedServerFastest: true]) standard.register(defaults: [Key.showIPv4Servers: true]) standard.register(defaults: [Key.preventSameCountryMultiHop: true]) @@ -302,6 +308,7 @@ extension UserDefaults { shared.removeObject(forKey: Key.v2rayProtocol) shared.removeObject(forKey: Key.isV2ray) shared.removeObject(forKey: Key.disableWidgetPrompt) + shared.removeObject(forKey: Key.isAccountHidden) standard.removeObject(forKey: Key.serviceStatus) standard.removeObject(forKey: Key.selectedHost) standard.removeObject(forKey: Key.selectedExitHost)