Skip to content

Commit

Permalink
feat(account): update UserDefaults+Ext.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Sep 10, 2024
1 parent 45a4f5d commit 5e3a9d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions IVPNClient/Scenes/AccountScreen/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 -
Expand All @@ -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()
}

Expand Down
7 changes: 7 additions & 0 deletions IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -261,13 +262,18 @@ 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])
shared.register(defaults: [Key.keepAlive: true])
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])
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5e3a9d9

Please sign in to comment.