Move baseVPNConfiguration to TransientStore
Simplifies configuration update.
This commit is contained in:
parent
c391663d11
commit
fdc3869d29
|
@ -109,16 +109,16 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
|||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
if !didShowSubreddit && !TransientStore.shared.didHandleSubreddit {
|
||||
if !didShowSubreddit && !TransientStore.didHandleSubreddit {
|
||||
didShowSubreddit = true
|
||||
|
||||
let alert = Macros.alert(L10n.Reddit.title, L10n.Reddit.message)
|
||||
alert.addDefaultAction(L10n.Reddit.Buttons.subscribe) {
|
||||
TransientStore.shared.didHandleSubreddit = true
|
||||
TransientStore.didHandleSubreddit = true
|
||||
self.subscribeSubreddit()
|
||||
}
|
||||
alert.addAction(L10n.Reddit.Buttons.never) {
|
||||
TransientStore.shared.didHandleSubreddit = true
|
||||
TransientStore.didHandleSubreddit = true
|
||||
}
|
||||
alert.addCancelAction(L10n.Reddit.Buttons.remind)
|
||||
present(alert, animated: true, completion: nil)
|
||||
|
|
|
@ -360,7 +360,7 @@ class ServiceViewController: UIViewController, TableModelHost {
|
|||
|
||||
private func testInternetConnectivity() {
|
||||
let hud = HUD()
|
||||
Utils.checkConnectivityURL(AppConstants.VPN.connectivityURL, timeout: AppConstants.VPN.connectivityTimeout) {
|
||||
Utils.checkConnectivityURL(AppConstants.Web.connectivityURL, timeout: AppConstants.Web.connectivityTimeout) {
|
||||
hud.hide()
|
||||
|
||||
let V = L10n.Service.Alerts.TestConnectivity.Messages.self
|
||||
|
@ -401,9 +401,8 @@ 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()
|
||||
TransientStore.masksPrivateData = cell.isOn
|
||||
service.baseConfiguration = TransientStore.baseVPNConfiguration.build()
|
||||
|
||||
// for privacy, delete potentially unmasked data
|
||||
if vpn.status != .disconnected {
|
||||
|
@ -739,7 +738,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 = TransientStore.shared.masksPrivateData
|
||||
cell.isOn = TransientStore.masksPrivateData
|
||||
return cell
|
||||
|
||||
// feedback
|
||||
|
|
|
@ -46,32 +46,6 @@ public class AppConstants {
|
|||
public static let hostsDirectory = "Hosts"
|
||||
}
|
||||
|
||||
public class VPN {
|
||||
public static var baseConfiguration: TunnelKitProvider.ConfigurationBuilder = {
|
||||
let sessionBuilder = SessionProxy.ConfigurationBuilder(ca: CryptoContainer(pem: ""))
|
||||
var builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build())
|
||||
builder.mtu = 1250
|
||||
builder.shouldDebug = true
|
||||
// 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 = TransientStore.shared.masksPrivateData
|
||||
return builder
|
||||
}()
|
||||
|
||||
private static let connectivityStrings: [String] = [
|
||||
"https://www.amazon.com",
|
||||
"https://www.google.com",
|
||||
"https://www.twitter.com",
|
||||
"https://www.facebook.com",
|
||||
"https://www.instagram.com"
|
||||
]
|
||||
|
||||
public static let connectivityURL = URL(string: connectivityStrings.customRandomElement())!
|
||||
|
||||
public static let connectivityTimeout: TimeInterval = 10.0
|
||||
}
|
||||
|
||||
public class Web {
|
||||
private static let version = "v1"
|
||||
|
||||
|
@ -84,6 +58,18 @@ public class AppConstants {
|
|||
public static let timeout: TimeInterval = 3.0
|
||||
|
||||
public static let minimumUpdateInterval: TimeInterval = 600.0 // 10 minutes
|
||||
|
||||
private static let connectivityStrings: [String] = [
|
||||
"https://www.amazon.com",
|
||||
"https://www.google.com",
|
||||
"https://www.twitter.com",
|
||||
"https://www.facebook.com",
|
||||
"https://www.instagram.com"
|
||||
]
|
||||
|
||||
public static let connectivityURL = URL(string: connectivityStrings.customRandomElement())!
|
||||
|
||||
public static let connectivityTimeout: TimeInterval = 10.0
|
||||
}
|
||||
|
||||
public class Log {
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import TunnelKit
|
||||
import SwiftyBeaver
|
||||
|
||||
private let log = SwiftyBeaver.self
|
||||
|
@ -43,7 +44,7 @@ public class TransientStore {
|
|||
|
||||
public let service: ConnectionService
|
||||
|
||||
public var didHandleSubreddit: Bool {
|
||||
public static var didHandleSubreddit: Bool {
|
||||
get {
|
||||
return UserDefaults.standard.bool(forKey: Keys.didHandleSubreddit)
|
||||
}
|
||||
|
@ -52,7 +53,7 @@ public class TransientStore {
|
|||
}
|
||||
}
|
||||
|
||||
public var masksPrivateData: Bool {
|
||||
public static var masksPrivateData: Bool {
|
||||
get {
|
||||
return UserDefaults.standard.bool(forKey: Keys.masksPrivateData)
|
||||
}
|
||||
|
@ -61,6 +62,18 @@ public class TransientStore {
|
|||
}
|
||||
}
|
||||
|
||||
public static var baseVPNConfiguration: TunnelKitProvider.ConfigurationBuilder {
|
||||
let sessionBuilder = SessionProxy.ConfigurationBuilder(ca: CryptoContainer(pem: ""))
|
||||
var builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build())
|
||||
builder.mtu = 1250
|
||||
builder.shouldDebug = true
|
||||
// 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 = AppConstants.Log.debugFormat
|
||||
builder.masksPrivateData = masksPrivateData
|
||||
return builder
|
||||
}
|
||||
|
||||
private init() {
|
||||
UserDefaults.standard.register(defaults: [
|
||||
Keys.didHandleSubreddit: false,
|
||||
|
@ -72,7 +85,7 @@ public class TransientStore {
|
|||
// this must be graceful
|
||||
ConnectionService.migrateJSON(from: TransientStore.serviceURL, to: TransientStore.serviceURL)
|
||||
|
||||
let cfg = AppConstants.VPN.baseConfiguration.build()
|
||||
let cfg = TransientStore.baseVPNConfiguration.build()
|
||||
do {
|
||||
let data = try Data(contentsOf: TransientStore.serviceURL)
|
||||
if let content = String(data: data, encoding: .utf8) {
|
||||
|
|
Loading…
Reference in New Issue