Skip to content

Commit

Permalink
feat: update UserDefaults+Ext.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Sep 22, 2023
1 parent 0891041 commit 5ffc441
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions IVPNClient/Managers/ConnectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ConnectionManager {
}
}
DispatchQueue.delay(2.5) {
if V2RayCore.shared.isV2ray && !V2RayCore.shared.reconnectWithV2ray {
if UserDefaults.shared.isV2ray && !V2RayCore.shared.reconnectWithV2ray {
V2RayCore.shared.reconnectWithV2ray = true
self.reconnect()
} else {
Expand Down Expand Up @@ -255,7 +255,7 @@ class ConnectionManager {
return
}

if V2RayCore.shared.isV2ray && V2RayCore.shared.reconnectWithV2ray {
if UserDefaults.shared.isV2ray && V2RayCore.shared.reconnectWithV2ray {
DispatchQueue.global(qos: .userInitiated).async {
let error = V2RayCore.shared.start()
if error != nil {
Expand Down Expand Up @@ -287,7 +287,7 @@ class ConnectionManager {
}
}

if V2RayCore.shared.isV2ray {
if UserDefaults.shared.isV2ray {
DispatchQueue.global(qos: .userInitiated).async {
let error = V2RayCore.shared.close()
if error != nil {
Expand Down
1 change: 0 additions & 1 deletion IVPNClient/Models/V2Ray/V2RayCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class V2RayCore {

static let shared = V2RayCore()
var instance: V2rayControlInstance?
var isV2ray = true
var reconnectWithV2ray = false

// MARK: - Methods -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ extension NETunnelProviderProtocol {
KeyChain.wgIpv6Host = ipv6.localIP
}

if V2RayCore.shared.isV2ray && V2RayCore.shared.reconnectWithV2ray {
if UserDefaults.shared.isV2ray && V2RayCore.shared.reconnectWithV2ray {
endpoint = Peer.endpoint(host: Config.v2rayHost, port: Config.v2rayPort)
v2raySettings?.inboundIp = v2rayInboundIp
v2raySettings?.inboundPort = v2rayInboundPort
Expand Down
12 changes: 12 additions & 0 deletions IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ extension UserDefaults {
static let antiTrackerDns = "antiTrackerDns"
static let disableLanAccess = "disableLanAccess"
static let v2raySettings = "v2raySettings"
static let v2rayProtocol = "v2rayProtocol"
static let isV2ray = "isV2ray"
}

@objc dynamic var wireguardTunnelProviderError: String {
Expand Down Expand Up @@ -241,6 +243,14 @@ extension UserDefaults {
return bool(forKey: Key.disableLanAccess)
}

@objc dynamic var v2rayProtocol: String {
return string(forKey: Key.v2rayProtocol) ?? ""
}

@objc dynamic var isV2ray: Bool {
return bool(forKey: Key.isV2ray)
}

static func registerUserDefaults() {
shared.register(defaults: [Key.networkProtectionUntrustedConnect: true])
shared.register(defaults: [Key.networkProtectionTrustedDisconnect: true])
Expand Down Expand Up @@ -278,6 +288,8 @@ extension UserDefaults {
shared.removeObject(forKey: Key.antiTrackerDns)
shared.removeObject(forKey: Key.disableLanAccess)
shared.removeObject(forKey: Key.v2raySettings)
shared.removeObject(forKey: Key.v2rayProtocol)
shared.removeObject(forKey: Key.isV2ray)
standard.removeObject(forKey: Key.serviceStatus)
standard.removeObject(forKey: Key.selectedHost)
standard.removeObject(forKey: Key.selectedExitHost)
Expand Down

0 comments on commit 5ffc441

Please sign in to comment.