Skip to content

Commit

Permalink
Fixes after difficult merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
graeme committed Mar 14, 2024
1 parent ea50ef5 commit 4862c41
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 67 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo/MainWindow/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ final class MainViewController: NSViewController {
let ipcClient = TunnelControllerIPCClient(machServiceName: vpnBundleID)
ipcClient.register()

return NetworkProtectionNavBarPopoverManager(ipcClient: ipcClient)
return NetworkProtectionNavBarPopoverManager(ipcClient: ipcClient, networkProtectionFeatureDisabler: NetworkProtectionFeatureDisabler())
}()
let networkProtectionStatusReporter: NetworkProtectionStatusReporter = {
var connectivityIssuesObserver: ConnectivityIssueObserver!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protocol NetworkProtectionIPCClient {
func start()
func stop()
}

extension TunnelControllerIPCClient: NetworkProtectionIPCClient {
public var ipcStatusObserver: any NetworkProtection.ConnectionStatusObserver { connectionStatusObserver }
public var ipcServerInfoObserver: any NetworkProtection.ConnectionServerInfoObserver { serverInfoObserver }
Expand All @@ -46,7 +47,7 @@ extension TunnelControllerIPCClient: NetworkProtectionIPCClient {

final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager {
private var networkProtectionPopover: NetworkProtectionPopover?
let ipcClient: TunnelControllerIPCClient
let ipcClient: NetworkProtectionIPCClient
let networkProtectionFeatureDisabler: NetworkProtectionFeatureDisabling

init(ipcClient: TunnelControllerIPCClient,
Expand Down Expand Up @@ -117,8 +118,13 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager {
}
},
agentLoginItem: LoginItem.vpnMenu,
isMenuBarStatusView: false
)
isMenuBarStatusView: false,
userDefaults: .netP,
uninstallHandler: { [weak self] in
Task { [weak self] in
await self?.networkProtectionFeatureDisabler.disable(keepAuthToken: false, uninstallSystemExtension: true)
}
})
popover.delegate = delegate

networkProtectionPopover = popover
Expand All @@ -128,58 +134,6 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager {
show(popover, positionedBelow: view)
}

private func createNetworkProtectionPopover() -> NetworkProtectionPopover {
let controller = NetworkProtectionIPCTunnelController(ipcClient: ipcClient)

let statusReporter = DefaultNetworkProtectionStatusReporter(
statusObserver: ipcClient.connectionStatusObserver,
serverInfoObserver: ipcClient.serverInfoObserver,
connectionErrorObserver: ipcClient.connectionErrorObserver,
connectivityIssuesObserver: ConnectivityIssueObserverThroughDistributedNotifications(),
controllerErrorMessageObserver: ControllerErrorMesssageObserverThroughDistributedNotifications()
)

let onboardingStatusPublisher = UserDefaults.netP.networkProtectionOnboardingStatusPublisher
_ = VPNSettings(defaults: .netP)
let appLauncher = AppLauncher(appBundleURL: Bundle.main.bundleURL)

return NetworkProtectionPopover(controller: controller,
onboardingStatusPublisher: onboardingStatusPublisher,
statusReporter: statusReporter,
appLauncher: appLauncher,
menuItems: {
if UserDefaults.netP.networkProtectionOnboardingStatus == .completed {
return [
NetworkProtectionStatusView.Model.MenuItem(
name: UserText.networkProtectionNavBarStatusMenuVPNSettings, action: {
await appLauncher.launchApp(withCommand: .showSettings)
}),
NetworkProtectionStatusView.Model.MenuItem(
name: UserText.networkProtectionNavBarStatusViewShareFeedback,
action: {
await appLauncher.launchApp(withCommand: .shareFeedback)
})
]
} else {
return [
NetworkProtectionStatusView.Model.MenuItem(
name: UserText.networkProtectionNavBarStatusViewShareFeedback,
action: {
await appLauncher.launchApp(withCommand: .shareFeedback)
})
]
}
},
agentLoginItem: LoginItem.vpnMenu,
isMenuBarStatusView: false,
userDefaults: .netP,
uninstallHandler: { [weak self] in
Task { [weak self] in
await self?.networkProtectionFeatureDisabler.disable(keepAuthToken: false, uninstallSystemExtension: true)
}
})
}

private func show(_ popover: NSPopover, positionedBelow view: NSView) {
view.isHidden = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr
#if SUBSCRIPTION
if let accessToken = accountManager.accessToken {
os_log(.error, log: .networkProtection, "🟢 TunnelController found token: %{public}d", accessToken)
return NetworkProtectionKeychainTokenStore.makeToken(from: accessToken) as NSString?
return NetworkProtectionKeychainTokenStore().makeToken(from: accessToken) as NSString?
}
#endif
os_log(.error, log: .networkProtection, "🔴 TunnelController found no token :(")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ final class NetworkProtectionSubscriptionEventHandler {
return
}
userDefaults.networkProtectionEntitlementsValid = true

Task {
do {
try NetworkProtectionKeychainTokenStore().store(NetworkProtectionKeychainTokenStore.makeToken(from: token))
print("[NetP Subscription] Stored derived NetP auth token")
} catch {
print("[NetP Subscription] Failed to store derived NetP auth token: \(error)")
}
}
}

@objc private func handleAccountDidSignOut() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Common

extension NetworkProtectionKeychainTokenStore: SubscriptionTokenStorage {
public func store(accessToken: String) throws {
let tokenToStore = Self.makeToken(from: accessToken)
let tokenToStore = makeToken(from: accessToken)
try store(tokenToStore)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum AppLaunchCommand: Codable {
case stopVPN
case enableOnDemand
case moveAppToApplications
case showPrivacyPro
}

public protocol AppLaunching {
Expand Down

0 comments on commit 4862c41

Please sign in to comment.