Skip to content

Commit

Permalink
Add a pretty-crappy approach to showing the VPN on/off status.
Browse files Browse the repository at this point in the history
This gets the ship review started, but I don’t plan for it to survive code review.
  • Loading branch information
samsymons committed May 25, 2024
1 parent 0a58c50 commit 33c7ffd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
subscriptionManager.accountManager
}
public let subscriptionManager: SubscriptionManaging
public let vpnTunnelIPCClient = TunnelControllerIPCClient()
public let vpnSettings = VPNSettings(defaults: .netP)

private var networkProtectionSubscriptionEventHandler: NetworkProtectionSubscriptionEventHandler?
Expand Down
4 changes: 3 additions & 1 deletion DuckDuckGo/Preferences/Model/PreferencesSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ struct PreferencesSection: Hashable, Identifiable {

@MainActor
static func defaultSections(includingDuckPlayer: Bool, includingSync: Bool, includingVPN: Bool) -> [PreferencesSection] {
var privacyPanes: [PreferencePaneIdentifier] = [.defaultBrowser, .privateSearch, .webTrackingProtection, .cookiePopupProtection, .emailProtection]
let privacyPanes: [PreferencePaneIdentifier] = [
.defaultBrowser, .privateSearch, .webTrackingProtection, .cookiePopupProtection, .emailProtection
]

let regularPanes: [PreferencePaneIdentifier] = {
var panes: [PreferencePaneIdentifier] = [.general, .appearance, .autofill, .accessibility, .dataClearing]
Expand Down
20 changes: 20 additions & 0 deletions DuckDuckGo/Preferences/Model/PrivacyProtectionStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ final class PrivacyProtectionStatus: ObservableObject {
return PrivacyProtectionStatus(statusPublisher: publisher, initialValue: EmailManager().isSignedIn ? .on : .off) { _ in
EmailManager().isSignedIn ? .on : .off
}
case .vpn:
let recentConnectionStatus = Application.appDelegate.vpnTunnelIPCClient.connectionStatusObserver.recentValue
let initialValue: Bool

if case .connected = recentConnectionStatus {
initialValue = true
} else {
initialValue = false
}

return PrivacyProtectionStatus(
statusPublisher: Application.appDelegate.vpnTunnelIPCClient.connectionStatusObserver.publisher.receive(on: RunLoop.main),
initialValue: initialValue ? .on : .off
) { newStatus in
if case .connected = newStatus {
return .on
} else {
return .off
}
}
default:
return PrivacyProtectionStatus()
}
Expand Down

0 comments on commit 33c7ffd

Please sign in to comment.