Persist masking flag

This commit is contained in:
Davide De Rosa 2019-03-22 19:04:33 +01:00
parent e4c1ea4def
commit c391663d11
3 changed files with 19 additions and 2 deletions

View File

@ -401,6 +401,7 @@ class ServiceViewController: UIViewController, TableModelHost {
}
private func togglePrivateDataMasking(cell: ToggleTableViewCell) {
TransientStore.shared.masksPrivateData = cell.isOn
AppConstants.VPN.baseConfiguration.masksPrivateData = cell.isOn
service.baseConfiguration = AppConstants.VPN.baseConfiguration.build()
@ -738,7 +739,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
case .masksPrivateData:
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
cell.caption = L10n.Service.Cells.MasksPrivateData.caption
cell.isOn = AppConstants.VPN.baseConfiguration.masksPrivateData ?? true
cell.isOn = TransientStore.shared.masksPrivateData
return cell
// feedback

View File

@ -55,7 +55,7 @@ public class AppConstants {
// builder.debugLogFormat = "$Dyyyy-MM-dd HH:mm:ss.SSS$d $L $N.$F:$l - $M"
// builder.debugLogFormat = "$DHH:mm:ss$d $N.$F:$l - $M"
builder.debugLogFormat = Log.debugFormat
builder.masksPrivateData = true
builder.masksPrivateData = TransientStore.shared.masksPrivateData
return builder
}()

View File

@ -31,6 +31,8 @@ private let log = SwiftyBeaver.self
public class TransientStore {
private struct Keys {
static let didHandleSubreddit = "DidHandleSubreddit"
static let masksPrivateData = "MasksPrivateData"
}
public static let shared = TransientStore()
@ -50,7 +52,21 @@ public class TransientStore {
}
}
public var masksPrivateData: Bool {
get {
return UserDefaults.standard.bool(forKey: Keys.masksPrivateData)
}
set {
UserDefaults.standard.set(newValue, forKey: Keys.masksPrivateData)
}
}
private init() {
UserDefaults.standard.register(defaults: [
Keys.didHandleSubreddit: false,
Keys.masksPrivateData: true
])
TransientStore.migrateDocumentsToAppGroup()
// this must be graceful