Skip to content

Commit

Permalink
Show last NetP disconnect error in Debug view (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
quanganhdo authored Jan 26, 2024
1 parent 4c64dfe commit eb90ec6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo/Feedback/VPNMetadataCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ final class DefaultVPNMetadataCollector: VPNMetadataCollector {
connectedServerIP: connectedServerIP)
}

private func lastDisconnectError() async -> String {
public func lastDisconnectError() async -> String {
if #available(iOS 16, *) {
guard let tunnelManager = try? await NETunnelProviderManager.loadAllFromPreferences().first else {
return "none"
Expand Down
28 changes: 28 additions & 0 deletions DuckDuckGo/NetworkProtectionDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ final class NetworkProtectionDebugViewController: UITableViewController {
Sections.registrationKey: "Registration Key",
Sections.notifications: "Notifications",
Sections.networkPath: "Network Path",
Sections.lastDisconnectError: "Last Disconnect Error",
Sections.connectionTest: "Connection Test",
Sections.vpnConfiguration: "VPN Configuration"

Expand All @@ -56,6 +57,7 @@ final class NetworkProtectionDebugViewController: UITableViewController {
case notifications
case connectionTest
case networkPath
case lastDisconnectError
case vpnConfiguration
}

Expand Down Expand Up @@ -90,6 +92,10 @@ final class NetworkProtectionDebugViewController: UITableViewController {
case networkPath
}

enum LastDisconnectErrorRows: Int, CaseIterable {
case lastDisconnectError
}

enum ConnectionTestRows: Int, CaseIterable {
case runConnectionTest
}
Expand All @@ -106,6 +112,7 @@ final class NetworkProtectionDebugViewController: UITableViewController {
private let pathMonitor = NWPathMonitor()

private var currentNetworkPath: String?
private var lastDisconnectError: String?
private var baseConfigurationData: String?
private var fullProtocolConfigurationData: String?

Expand Down Expand Up @@ -138,6 +145,7 @@ final class NetworkProtectionDebugViewController: UITableViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
loadLastDisconnectError()
loadConfigurationData()
startPathMonitor()
}
Expand Down Expand Up @@ -188,6 +196,9 @@ final class NetworkProtectionDebugViewController: UITableViewController {
case .networkPath:
configure(cell, forNetworkPathRow: indexPath.row)

case .lastDisconnectError:
configure(cell, forLastDisconnectErrorRow: indexPath.row)

case .connectionTest:
configure(cell, forConnectionTestRow: indexPath.row)

Expand All @@ -209,6 +220,7 @@ final class NetworkProtectionDebugViewController: UITableViewController {
case .registrationKey: return RegistrationKeyRows.allCases.count
case .notifications: return NotificationsRows.allCases.count
case .networkPath: return NetworkPathRows.allCases.count
case .lastDisconnectError: return LastDisconnectErrorRows.allCases.count
case .connectionTest: return ConnectionTestRows.allCases.count + connectionTestResults.count
case .vpnConfiguration: return ConfigurationRows.allCases.count
case .none: return 0
Expand All @@ -235,6 +247,8 @@ final class NetworkProtectionDebugViewController: UITableViewController {
didSelectTestNotificationAction(at: indexPath)
case .networkPath:
break
case .lastDisconnectError:
break
case .connectionTest:
if indexPath.row == connectionTestResults.count {
Task {
Expand Down Expand Up @@ -394,6 +408,20 @@ final class NetworkProtectionDebugViewController: UITableViewController {
pathMonitor.start(queue: .main)
}

// MARK: Last disconnect error

private func configure(_ cell: UITableViewCell, forLastDisconnectErrorRow row: Int) {
cell.textLabel?.font = .monospacedSystemFont(ofSize: 13.0, weight: .regular)
cell.textLabel?.text = lastDisconnectError ?? "Loading Last Disconnect Error..."
}

private func loadLastDisconnectError() {
Task { @MainActor in
lastDisconnectError = await DefaultVPNMetadataCollector().lastDisconnectError()
tableView.reloadData()
}
}

// MARK: Connection Test

private func configure(_ cell: UITableViewCell, forConnectionTestRow row: Int) {
Expand Down
12 changes: 0 additions & 12 deletions DuckDuckGo/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2067,18 +2067,6 @@ But if you *do* want a peek under the hood, you can find more information about
/* Subscription Expiration Data */
"subscription.subscription.active.caption" = "Your Privacy Pro subscription renews on %@";

/* Cancel action for the existing subscription dialog */
"subscription.subscription.found.cancel" = "Cancel";

/* Restore action for the existing subscription dialog */
"subscription.subscription.found.restore" = "Restore";

/* Message for the existing subscription dialog */
"subscription.subscription.found.text" = "We found a subscription associated with this Apple ID.";

/* Title for the existing subscription dialog */
"subscription.subscription.found.title" = "Subscription Found";

/* Message confirming that recovery code was copied to clipboard */
"sync.code.copied" = "Recovery code copied to clipboard";

Expand Down

0 comments on commit eb90ec6

Please sign in to comment.