From d807463f65fcd79b96d4d6de460250528a6ac8cf Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Tue, 19 Nov 2024 16:12:20 +0100 Subject: [PATCH] WIP --- .../TipKit/TipKitAppEventHandling.swift | 5 +++ .../Model/VPNDomainExclusionsTip.swift | 10 ------ .../Views/TipViews/Model/VPNTipsModel.swift | 33 ++++++++++++++--- .../TunnelControllerView.swift | 36 ++++++++----------- 4 files changed, 49 insertions(+), 35 deletions(-) diff --git a/DuckDuckGo/TipKit/TipKitAppEventHandling.swift b/DuckDuckGo/TipKit/TipKitAppEventHandling.swift index 24108f3cd1..c8850222a9 100644 --- a/DuckDuckGo/TipKit/TipKitAppEventHandling.swift +++ b/DuckDuckGo/TipKit/TipKitAppEventHandling.swift @@ -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 { diff --git a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TipViews/Model/VPNDomainExclusionsTip.swift b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TipViews/Model/VPNDomainExclusionsTip.swift index 15c4e85cd8..36ecb8a64b 100644 --- a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TipViews/Model/VPNDomainExclusionsTip.swift +++ b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TipViews/Model/VPNDomainExclusionsTip.swift @@ -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. @@ -71,9 +64,6 @@ extension VPNDomainExclusionsTip: Tip { #Rule(Self.$vpnEnabled) { $0 } - #Rule(Self.$canShow) { - $0 - } #Rule(Self.geolocationTipDismissedEvent) { $0.donations.count > 0 } diff --git a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TipViews/Model/VPNTipsModel.swift b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TipViews/Model/VPNTipsModel.swift index 8c2fef34e8..3e7a5f9a7b 100644 --- a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TipViews/Model/VPNTipsModel.swift +++ b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TipViews/Model/VPNTipsModel.swift @@ -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() @@ -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) @@ -80,6 +80,10 @@ public final class VPNTipsModel: ObservableObject { } } + var canShowTips: Bool { + !isMenuApp && featureFlag + } + @available(macOS 14.0, *) private func subscribeToFeatureFlagChanges(_ publisher: CurrentValuePublisher) { publisher @@ -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, *) @@ -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() diff --git a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TunnelControllerView/TunnelControllerView.swift b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TunnelControllerView/TunnelControllerView.swift index 8627fd1a37..e9321e1d34 100644 --- a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TunnelControllerView/TunnelControllerView.swift +++ b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/TunnelControllerView/TunnelControllerView.swift @@ -54,10 +54,10 @@ 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) } @@ -65,20 +65,12 @@ public struct TunnelControllerView: View { 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() @@ -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) @@ -253,7 +247,7 @@ public struct TunnelControllerView: View { return tip }()*/ - +/* let domainExclusionsTip: VPNDomainExclusionsTip = { let tip = VPNDomainExclusionsTip() @@ -270,9 +264,9 @@ public struct TunnelControllerView: View { } return tip - }() + }()*/ - let autoconnectTip = VPNAutoconnectTip() + //let autoconnectTip = VPNAutoconnectTip() // MARK: - Rows