Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoreymendez committed Oct 20, 2024
1 parent e6ccb08 commit cd61d52
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import Foundation
import LoginItems
import NetworkProtection
import NetworkProtectionIPC
import NetworkProtectionProxy
import NetworkProtectionUI
import os.log
import Subscription
import VPNAppLauncher
import SwiftUI
import NetworkProtectionProxy
import VPNAppLauncher

protocol NetworkProtectionIPCClient {
var ipcStatusObserver: ConnectionStatusObserver { get }
Expand Down Expand Up @@ -167,7 +168,8 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager {
statusObserver: statusReporter.statusObserver,
activeSitePublisher: activeSitePublisher,
forMenuApp: false,
vpnSettings: vpnSettings)
vpnSettings: vpnSettings,
logger: Logger(subsystem: "DuckDuckGo", category: "TipKit"))

let popover = NetworkProtectionPopover(
statusViewModel: statusViewModel,
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGoVPN/DuckDuckGoVPNDebug.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<string>$(NETP_APP_GROUP)</string>
<string>$(IPC_APP_GROUP)</string>
<string>$(SUBSCRIPTION_APP_GROUP)</string>
<string>$(APP_CONFIGURATION_APP_GROUP)</string>
</array>
<key>keychain-access-groups</key>
<array>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import AppKit
import Foundation
import Combine
import Common
import SwiftUI
import NetworkProtection
import LoginItems
import NetworkProtection
import os.log
import SwiftUI
import TipKitUtils

/// Abstraction of the the VPN status bar menu with a simple interface.
Expand Down Expand Up @@ -150,7 +151,8 @@ public final class StatusBarMenu: NSObject {
statusObserver: statusReporter.statusObserver,
activeSitePublisher: activeSitePublisher,
forMenuApp: true,
vpnSettings: VPNSettings(defaults: userDefaults))
vpnSettings: VPNSettings(defaults: userDefaults),
logger: Logger.init(subsystem: "DuckDuckGo", category: "TipKit"))

let debugInformationViewModel = DebugInformationViewModel(showDebugInformation: isOptionKeyPressed)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ import TipKit

/// A tip to suggest to the user to use the autoconnect option for the VPN.
///
struct VPNAutoconnectTip {}

/// Necessary split to support older iOS versions.
///
@available(macOS 14.0, *)
extension VPNAutoconnectTip: Tip {
struct VPNAutoconnectTip: Tip {

enum ActionIdentifiers: String {
case enable = "com.duckduckgo.vpn.tip.autoconnect.action.enable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ import TipKit

/// A tip to suggest using domain exclusions when a site doesn't work.
///
struct VPNDomainExclusionsTip {}

/// Necessary split to support older iOS versions.
///
@available(macOS 14.0, *)
extension VPNDomainExclusionsTip: Tip {
struct VPNDomainExclusionsTip: Tip {

@Parameter(.transient)
static var vpnEnabled: Bool = false
Expand All @@ -39,7 +35,7 @@ extension VPNDomainExclusionsTip: Tip {
/// This condition may be indicative that the user is struggling, so they might want
/// to exclude a site.
///
static let viewOpenedWhehVPNAlreadyConnectedEvent = Tips.Event(id: "com.duckduckgo.vpn.tip.domainExclusions.popoverOpenedWhileAlreadyConnected")
static let viewOpenedWhenVPNAlreadyConnectedEvent = Tips.Event(id: "com.duckduckgo.vpn.tip.domainExclusions.popoverOpenedWhileAlreadyConnected")

var id: String {
"com.duckduckgo.vpn.tip.domainExclusions"
Expand All @@ -64,7 +60,7 @@ extension VPNDomainExclusionsTip: Tip {
#Rule(Self.$vpnEnabled) {
$0 == true
}
#Rule(Self.viewOpenedWhehVPNAlreadyConnectedEvent) {
#Rule(Self.viewOpenedWhenVPNAlreadyConnectedEvent) {
$0.donations.count > 1
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import TipKit

/// A tip to suggest to the user to change their location using geo-switching
///
struct VPNGeoswitchingTip {}

@available(macOS 14.0, *)
extension VPNGeoswitchingTip: Tip {
struct VPNGeoswitchingTip: Tip {

static let vpnConnectedEvent = Tips.Event(id: "com.duckduckgo.vpn.tip.geoswitching.vpnConnectedEvent")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import AppKit
import Combine
import Common
import NetworkProtection
import os.log
import TipKit
import TipKitUtils

@MainActor
public final class VPNTipsModel: ObservableObject {

@Published
Expand All @@ -45,11 +47,18 @@ public final class VPNTipsModel: ObservableObject {

switch connectionStatus {
case .connected:
if case oldValue = .connecting {
Task {
await VPNGeoswitchingTip.vpnConnectedEvent.donate()
}
}

VPNAutoconnectTip.vpnEnabled = true
VPNDomainExclusionsTip.vpnEnabled = true
default:
VPNAutoconnectTip.vpnEnabled = false
VPNDomainExclusionsTip.vpnEnabled = false
break
}
}
}
Expand All @@ -59,54 +68,70 @@ public final class VPNTipsModel: ObservableObject {
let tips: TipGrouping

private let vpnSettings: VPNSettings
private let logger: Logger
private var cancellables = Set<AnyCancellable>()

static func makeTips(forMenuApp isMenuApp: Bool) -> TipGrouping {
static func makeTips(forMenuApp isMenuApp: Bool, logger: Logger) -> TipGrouping {

guard #available(macOS 14.0, *) else {
return EmptyTipGroup()
}

let autoconnectTip = VPNAutoconnectTip()
let domainExclusionsTip = VPNDomainExclusionsTip()
let geoswitchingTip = VPNGeoswitchingTip()
let tips: [any Tip] = {
if isMenuApp {
return [
geoswitchingTip,
autoconnectTip
]
} else {
return [
geoswitchingTip,
domainExclusionsTip,
autoconnectTip
]
}
}()

Task {
for await statusUpdate in geoswitchingTip.statusUpdates {
logger.debug("🪙 VPNGeoswitchingTip status updated: \(String(describing: statusUpdate), privacy: .public)")
}
}

Task {
for await statusUpdate in domainExclusionsTip.statusUpdates {
logger.debug("🪙 VPNDomainExclusionsTip status updated: \(String(describing: statusUpdate), privacy: .public)")
}
}

// This is temporarily disabled until Xcode 16 is available.
// Ref: https://app.asana.com/0/414235014887631/1208528787265444/f
//
// if #available(macOS 15.0, *) {
// if isMenuApp {
// return TipGroup(.ordered) {
// VPNGeoswitchingTip()
// VPNAutoconnectTip()
// }
// } else {
// return TipGroup(.ordered) {
// VPNGeoswitchingTip()
// VPNDomainExclusionsTip()
// VPNAutoconnectTip()
// }
// return TipGroup(.ordered) {
// tips
// }
// }
if #available(macOS 14, *) {
if isMenuApp {
return LegacyTipGroup(.ordered) {
VPNGeoswitchingTip()
VPNAutoconnectTip()
}
} else {
return LegacyTipGroup(.ordered) {
VPNGeoswitchingTip()
VPNDomainExclusionsTip()
VPNAutoconnectTip()
}
}
} else {
return EmptyTipGroup()
// } else { ... what's below
return LegacyTipGroup(.ordered) {
tips
}
}

public init(featureFlagPublisher: CurrentValuePublisher<Bool, Never>,
statusObserver: ConnectionStatusObserver,
activeSitePublisher: CurrentValuePublisher<ActiveSiteInfo?, Never>,
forMenuApp isMenuApp: Bool,
vpnSettings: VPNSettings) {
vpnSettings: VPNSettings,
logger: Logger) {

self.activeSiteInfo = activeSitePublisher.value
self.connectionStatus = statusObserver.recentValue
self.featureFlag = featureFlagPublisher.value
self.tips = Self.makeTips(forMenuApp: isMenuApp)
self.logger = logger
self.tips = Self.makeTips(forMenuApp: isMenuApp, logger: logger)
self.vpnSettings = vpnSettings

if #available(macOS 14.0, *) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public struct TunnelControllerView: View {
self.model = model
}

@EnvironmentObject
private var tipsModel: VPNTipsModel

// MARK: - View Contents

public var body: some View {
Expand All @@ -60,9 +63,17 @@ public struct TunnelControllerView: View {
.padding(.top, 5)

if #available(macOS 15.0, *) {
VPNDomainExclusionsTipView()
.padding(.horizontal, 9)
.padding(.vertical, 6)
//VPNDomainExclusionsTipView()
//.padding(.horizontal, 9)
//.padding(.vertical, 6)

if tipsModel.featureFlag,
let tip = tipsModel.tips.currentTip as? VPNDomainExclusionsTip {

TipView(tip)
.padding(.horizontal, 9)
.padding(.vertical, 6)
}
}

Divider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,6 @@ public final class TunnelControllerViewModel: ObservableObject {
}

Task { @MainActor in
if #available(macOS 14.0, *) {
await VPNGeoswitchingTip.vpnConnectedEvent.donate()
}

await tunnelController.start()
refreshInternalIsRunning()
}
Expand Down Expand Up @@ -541,7 +537,7 @@ public final class TunnelControllerViewModel: ObservableObject {

func handleTunnelControllerShown() async {
if #available(macOS 14.0, *) {
await VPNDomainExclusionsTip.viewOpenedWhehVPNAlreadyConnectedEvent.donate()
await VPNDomainExclusionsTip.viewOpenedWhenVPNAlreadyConnectedEvent.donate()
}
}
}
Expand Down

0 comments on commit cd61d52

Please sign in to comment.