Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoreymendez committed Nov 19, 2024
1 parent 865a5a7 commit d807463
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
5 changes: 5 additions & 0 deletions DuckDuckGo/TipKit/TipKitAppEventHandling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ struct TipKitAppEventHandler: TipKitAppEventHandling {
if #available(macOS 14.0, *) {
typealias DataStoreLocation = Tips.ConfigurationOption.DatastoreLocation

/// A this time TipKit does not seem to handle synchronization of state between multiple apps very well.
/// That said, we still use the app configuration group for the data store in hopes this will soon change.
/// As long as we don't use TipKit for the same views from multiple Apps we'll be fine, but we can test
/// whether it's still broken rather easily if we keep the state in a shared app group, and we avoid having
/// to migrate the store in the future.
let appConfigurationGroupIdentifier = Bundle.main.appGroup(bundle: .appConfiguration)

guard let dataStoreLocation = try? DataStoreLocation.groupContainer(identifier: appConfigurationGroupIdentifier) else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ extension VPNDomainExclusionsTip: Tip {
@Parameter(.transient)
static var hasActiveSite: Bool = false

/// Whether the tip can be shown.
///
/// This tip is not shown for the VPN menu app.
///
@Parameter(.transient)
static var canShow: Bool = false

static let geolocationTipDismissedEvent = Tips.Event(id: "com.duckduckgo.vpn.tip.domainExclusions.geolocationTipDismissedEvent")

/// The containing view was opened when the VPN was already connected.
Expand Down Expand Up @@ -71,9 +64,6 @@ extension VPNDomainExclusionsTip: Tip {
#Rule(Self.$vpnEnabled) {
$0
}
#Rule(Self.$canShow) {
$0
}
#Rule(Self.geolocationTipDismissedEvent) {
$0.donations.count > 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public final class VPNTipsModel: ObservableObject {
}

@Published
private(set) var featureFlag: Bool
private var featureFlag: Bool

private let isMenuApp: Bool
private let vpnSettings: VPNSettings
private let logger: Logger
private var cancellables = Set<AnyCancellable>()
Expand All @@ -65,12 +66,11 @@ public final class VPNTipsModel: ObservableObject {
self.activeSiteInfo = activeSitePublisher.value
self.connectionStatus = statusObserver.recentValue
self.featureFlag = featureFlagPublisher.value
self.isMenuApp = isMenuApp
self.logger = logger
self.vpnSettings = vpnSettings

if #available(macOS 14.0, *) {
VPNDomainExclusionsTip.canShow = !isMenuApp

handleActiveSiteInfoChanged(newValue: activeSiteInfo)
handleConnectionStatusChanged(oldValue: connectionStatus, newValue: connectionStatus)

Expand All @@ -80,6 +80,10 @@ public final class VPNTipsModel: ObservableObject {
}
}

var canShowTips: Bool {
!isMenuApp && featureFlag
}

@available(macOS 14.0, *)
private func subscribeToFeatureFlagChanges(_ publisher: CurrentValuePublisher<Bool, Never>) {
publisher
Expand Down Expand Up @@ -112,7 +116,8 @@ public final class VPNTipsModel: ObservableObject {

@available(macOS 14.0, *)
private func handleActiveSiteInfoChanged(newValue: ActiveSiteInfo?) {
VPNDomainExclusionsTip.hasActiveSite = (activeSiteInfo != nil)
Logger.networkProtection.debug("🧉 Active site info changed: \(String(describing: newValue))")
return VPNDomainExclusionsTip.hasActiveSite = (activeSiteInfo != nil)
}

@available(macOS 14.0, *)
Expand Down Expand Up @@ -140,6 +145,26 @@ public final class VPNTipsModel: ObservableObject {
}
}

// MARK: - Tips

let autoconnectTip = VPNAutoconnectTip()

let domainExclusionsTip: VPNDomainExclusionsTip = {
let tip = VPNDomainExclusionsTip()

if #available(macOS 14.0, *) {
Task {
for await status in tip.statusUpdates {
if case .invalidated = status {
await VPNAutoconnectTip.domainExclusionsTipDismissedEvent.donate()
}
}
}
}

return tip
}()

let geoswitchingTip: VPNGeoswitchingTip = {

let tip = VPNGeoswitchingTip()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,23 @@ public struct TunnelControllerView: View {

featureToggleRow()

if #available(macOS 14.0, *) {
TipView(autoconnectTip)
//VPNAutoconnectTipView()
//TipView(tipGroup.currentTip as? VPNAutoconnectTip)
if #available(macOS 14.0, *),
tipsModel.canShowTips {

TipView(tipsModel.autoconnectTip)
.padding(.horizontal, 9)
.padding(.vertical, 6)
}

SiteTroubleshootingView()
.padding(.top, 5)

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

if tipsModel.featureFlag {//,
//let tip = tipsModel.currentTip as? VPNDomainExclusionsTip {
if #available(macOS 14.0, *),
tipsModel.canShowTips {

TipView(domainExclusionsTip)
//TipView(tipGroup.currentTip as? VPNDomainExclusionsTip)
//VPNDomainExclusionsTipView()
.padding(.horizontal, 9)
.padding(.vertical, 6)
}
TipView(tipsModel.domainExclusionsTip)
.padding(.horizontal, 9)
.padding(.vertical, 6)
}

Divider()
Expand Down Expand Up @@ -202,7 +194,9 @@ public struct TunnelControllerView: View {
}
}

if #available(macOS 14.0, *) {
if #available(macOS 14.0, *),
tipsModel.canShowTips {

TipView(tipsModel.geoswitchingTip)
.padding(.horizontal, 9)
.padding(.vertical, 6)
Expand Down Expand Up @@ -253,7 +247,7 @@ public struct TunnelControllerView: View {

return tip
}()*/

/*
let domainExclusionsTip: VPNDomainExclusionsTip = {
let tip = VPNDomainExclusionsTip()

Expand All @@ -270,9 +264,9 @@ public struct TunnelControllerView: View {
}

return tip
}()
}()*/

let autoconnectTip = VPNAutoconnectTip()
//let autoconnectTip = VPNAutoconnectTip()

Check failure on line 269 in LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TunnelControllerView/TunnelControllerView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Prefer at least one space after slashes for comments (comment_spacing)

// MARK: - Rows

Expand Down

0 comments on commit d807463

Please sign in to comment.