summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/TunnelManager
diff options
context:
space:
mode:
authorJon Petersson <jon.petersson@mullvad.net>2024-12-04 10:18:22 +0100
committerJon Petersson <jon.petersson@mullvad.net>2024-12-13 14:31:41 +0100
commitc61b7d4e5a3a891562416692ee8d5b94de1e8549 (patch)
treee85b0edcfb08238a5714f59ddaa1a4b03662359e /ios/MullvadVPN/TunnelManager
parent9573f3ed7a449f2aeb9f8efe0c6f4335ed0c326c (diff)
downloadmullvadvpn-c61b7d4e5a3a891562416692ee8d5b94de1e8549.tar.xz
mullvadvpn-c61b7d4e5a3a891562416692ee8d5b94de1e8549.zip
Add state to new connection view
Diffstat (limited to 'ios/MullvadVPN/TunnelManager')
-rw-r--r--ios/MullvadVPN/TunnelManager/TunnelState+UI.swift97
-rw-r--r--ios/MullvadVPN/TunnelManager/TunnelState.swift16
2 files changed, 83 insertions, 30 deletions
diff --git a/ios/MullvadVPN/TunnelManager/TunnelState+UI.swift b/ios/MullvadVPN/TunnelManager/TunnelState+UI.swift
index e87afd87b3..f02bf005e1 100644
--- a/ios/MullvadVPN/TunnelManager/TunnelState+UI.swift
+++ b/ios/MullvadVPN/TunnelManager/TunnelState+UI.swift
@@ -9,14 +9,18 @@
import UIKit
extension TunnelState {
+ enum TunnelControlActionButton {
+ case connect
+ case disconnect
+ case cancel
+ }
+
var textColorForSecureLabel: UIColor {
switch self {
case .connecting, .reconnecting, .waitingForConnectivity(.noConnection), .negotiatingEphemeralPeer:
.white
-
case .connected:
.successColor
-
case .disconnecting, .disconnected, .pendingReconnect, .waitingForConnectivity(.noNetwork), .error:
.dangerColor
}
@@ -65,6 +69,7 @@ extension TunnelState {
comment: ""
)
}
+
case let .connected(_, isPostQuantum, _):
if isPostQuantum {
NSLocalizedString(
@@ -77,7 +82,7 @@ extension TunnelState {
NSLocalizedString(
"TUNNEL_STATE_CONNECTED",
tableName: "Main",
- value: "Secure connection",
+ value: "Connected",
comment: ""
)
}
@@ -89,6 +94,7 @@ extension TunnelState {
value: "Disconnecting",
comment: ""
)
+
case .disconnecting(.reconnect), .pendingReconnect:
NSLocalizedString(
"TUNNEL_STATE_PENDING_RECONNECT",
@@ -123,7 +129,7 @@ extension TunnelState {
}
}
- var localizedTitleForSelectLocationButton: String? {
+ var localizedTitleForSelectLocationButton: String {
switch self {
case .disconnecting(.reconnect), .pendingReconnect:
NSLocalizedString(
@@ -159,24 +165,6 @@ extension TunnelState {
}
}
- func secureConnectionLabel(isPostQuantum: Bool) -> String {
- if isPostQuantum {
- NSLocalizedString(
- "TUNNEL_STATE_PQ_CONNECTING_ACCESSIBILITY_LABEL",
- tableName: "Main",
- value: "Creating quantum secure connection",
- comment: ""
- )
- } else {
- NSLocalizedString(
- "TUNNEL_STATE_CONNECTING_ACCESSIBILITY_LABEL",
- tableName: "Main",
- value: "Creating secure connection",
- comment: ""
- )
- }
- }
-
var localizedAccessibilityLabel: String {
switch self {
case let .connecting(_, isPostQuantum, _):
@@ -263,4 +251,69 @@ extension TunnelState {
)
}
}
+
+ var actionButton: TunnelControlActionButton {
+ switch self {
+ case .disconnected, .disconnecting(.nothing), .waitingForConnectivity(.noNetwork):
+ .connect
+ case .connecting, .pendingReconnect, .disconnecting(.reconnect), .waitingForConnectivity(.noConnection):
+ .cancel
+ case .negotiatingEphemeralPeer:
+ .cancel
+ case .connected, .reconnecting, .error:
+ .disconnect
+ }
+ }
+
+ var titleForCountryAndCity: String? {
+ guard isSecured, let tunnelRelays = relays else {
+ return nil
+ }
+
+ return "\(tunnelRelays.exit.location.country), \(tunnelRelays.exit.location.city)"
+ }
+
+ func titleForServer(daitaEnabled: Bool) -> String? {
+ guard isSecured, let tunnelRelays = relays else {
+ return nil
+ }
+
+ let exitName = tunnelRelays.exit.hostname
+ let entryName = tunnelRelays.entry?.hostname
+ let usingDaita = daitaEnabled == true
+
+ return if let entryName {
+ String(format: NSLocalizedString(
+ "CONNECT_PANEL_TITLE",
+ tableName: "Main",
+ value: "%@ via %@\(usingDaita ? " using DAITA" : "")",
+ comment: ""
+ ), exitName, entryName)
+ } else {
+ String(format: NSLocalizedString(
+ "CONNECT_PANEL_TITLE",
+ tableName: "Main",
+ value: "%@\(usingDaita ? " using DAITA" : "")",
+ comment: ""
+ ), exitName)
+ }
+ }
+
+ func secureConnectionLabel(isPostQuantum: Bool) -> String {
+ if isPostQuantum {
+ NSLocalizedString(
+ "TUNNEL_STATE_PQ_CONNECTING_ACCESSIBILITY_LABEL",
+ tableName: "Main",
+ value: "Creating quantum secure connection",
+ comment: ""
+ )
+ } else {
+ NSLocalizedString(
+ "TUNNEL_STATE_CONNECTING_ACCESSIBILITY_LABEL",
+ tableName: "Main",
+ value: "Creating secure connection",
+ comment: ""
+ )
+ }
+ }
}
diff --git a/ios/MullvadVPN/TunnelManager/TunnelState.swift b/ios/MullvadVPN/TunnelManager/TunnelState.swift
index ea55431d5a..b235f8255c 100644
--- a/ios/MullvadVPN/TunnelManager/TunnelState.swift
+++ b/ios/MullvadVPN/TunnelManager/TunnelState.swift
@@ -84,8 +84,8 @@ enum TunnelState: Equatable, CustomStringConvertible {
case let .connecting(tunnelRelays, isPostQuantum, isDaita):
if let tunnelRelays {
"""
- connecting \(isPostQuantum ? "(PQ) " : "")\
- daita: \(isDaita) \
+ connecting \(isPostQuantum ? "(PQ) " : ""), \
+ daita: \(isDaita), \
to \(tunnelRelays.exit.hostname)\
\(tunnelRelays.entry.flatMap { " via \($0.hostname)" } ?? "")
"""
@@ -94,8 +94,8 @@ enum TunnelState: Equatable, CustomStringConvertible {
}
case let .connected(tunnelRelays, isPostQuantum, isDaita):
"""
- connected \(isPostQuantum ? "(PQ) " : "")\
- daita: \(isDaita) \
+ connected \(isPostQuantum ? "(PQ) " : ""), \
+ daita: \(isDaita), \
to \(tunnelRelays.exit.hostname)\
\(tunnelRelays.entry.flatMap { " via \($0.hostname)" } ?? "")
"""
@@ -105,8 +105,8 @@ enum TunnelState: Equatable, CustomStringConvertible {
"disconnected"
case let .reconnecting(tunnelRelays, isPostQuantum, isDaita):
"""
- reconnecting \(isPostQuantum ? "(PQ) " : "")\
- daita: \(isDaita) \
+ reconnecting \(isPostQuantum ? "(PQ) " : ""), \
+ daita: \(isDaita), \
to \(tunnelRelays.exit.hostname)\
\(tunnelRelays.entry.flatMap { " via \($0.hostname)" } ?? "")
"""
@@ -117,8 +117,8 @@ enum TunnelState: Equatable, CustomStringConvertible {
case let .negotiatingEphemeralPeer(tunnelRelays, _, isPostQuantum, isDaita):
"""
negotiating key with exit relay: \(tunnelRelays.exit.hostname)\
- \(tunnelRelays.entry.flatMap { " via \($0.hostname)" } ?? "")\
- , isPostQuantum: \(isPostQuantum), isDaita: \(isDaita)
+ \(tunnelRelays.entry.flatMap { " via \($0.hostname)" } ?? ""), \
+ isPostQuantum: \(isPostQuantum), isDaita: \(isDaita)
"""
}
}