@@ -24,11 +24,14 @@ import Foundation
24
24
import LoginItems
25
25
import NetworkProtection
26
26
import NetworkProtectionIPC
27
+ import NetworkProtectionProxy
27
28
import NetworkProtectionUI
29
+ import os. log
28
30
import Subscription
29
- import VPNAppLauncher
30
31
import SwiftUI
31
- import NetworkProtectionProxy
32
+ import VPNAppLauncher
33
+ import BrowserServicesKit
34
+ import FeatureFlags
32
35
33
36
protocol NetworkProtectionIPCClient {
34
37
var ipcStatusObserver : ConnectionStatusObserver { get }
@@ -55,8 +58,8 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager {
55
58
let vpnUninstaller : VPNUninstalling
56
59
57
60
@Published
58
- private var siteInfo : SiteTroubleshootingInfo ?
59
- private let siteTroubleshootingInfoPublisher : SiteTroubleshootingInfoPublisher
61
+ private var siteInfo : ActiveSiteInfo ?
62
+ private let activeSitePublisher : ActiveSiteInfoPublisher
60
63
private var cancellables = Set < AnyCancellable > ( )
61
64
62
65
init ( ipcClient: VPNControllerXPCClient ,
@@ -67,15 +70,15 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager {
67
70
68
71
let activeDomainPublisher = ActiveDomainPublisher ( windowControllersManager: . shared)
69
72
70
- siteTroubleshootingInfoPublisher = SiteTroubleshootingInfoPublisher (
73
+ activeSitePublisher = ActiveSiteInfoPublisher (
71
74
activeDomainPublisher: activeDomainPublisher. eraseToAnyPublisher ( ) ,
72
75
proxySettings: TransparentProxySettings ( defaults: . netP) )
73
76
74
77
subscribeToCurrentSitePublisher ( )
75
78
}
76
79
77
80
private func subscribeToCurrentSitePublisher( ) {
78
- siteTroubleshootingInfoPublisher
81
+ activeSitePublisher
79
82
. assign ( to: \. siteInfo, onWeaklyHeld: self )
80
83
. store ( in: & cancellables)
81
84
}
@@ -87,9 +90,10 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager {
87
90
func show( positionedBelow view: NSView , withDelegate delegate: NSPopoverDelegate ) -> NSPopover {
88
91
89
92
/// Since the favicon doesn't have a publisher we force refreshing here
90
- siteTroubleshootingInfoPublisher . refreshSiteTroubleshootingInfo ( )
93
+ activeSitePublisher . refreshActiveSiteInfo ( )
91
94
92
95
let popover : NSPopover = {
96
+ let vpnSettings = VPNSettings ( defaults: . netP)
93
97
let controller = NetworkProtectionIPCTunnelController ( ipcClient: ipcClient)
94
98
95
99
let statusReporter = DefaultNetworkProtectionStatusReporter (
@@ -103,15 +107,22 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager {
103
107
)
104
108
105
109
let onboardingStatusPublisher = UserDefaults . netP. networkProtectionOnboardingStatusPublisher
106
- _ = VPNSettings ( defaults: . netP)
107
110
let appLauncher = AppLauncher ( appBundleURL: Bundle . main. bundleURL)
108
111
let vpnURLEventHandler = VPNURLEventHandler ( )
109
112
let proxySettings = TransparentProxySettings ( defaults: . netP)
110
113
let uiActionHandler = VPNUIActionHandler ( vpnURLEventHandler: vpnURLEventHandler, proxySettings: proxySettings)
111
114
115
+ let connectionStatusPublisher = CurrentValuePublisher (
116
+ initialValue: statusReporter. statusObserver. recentValue,
117
+ publisher: statusReporter. statusObserver. publisher)
118
+
119
+ let activeSitePublisher = CurrentValuePublisher (
120
+ initialValue: siteInfo,
121
+ publisher: $siteInfo. eraseToAnyPublisher ( ) )
122
+
112
123
let siteTroubleshootingViewModel = SiteTroubleshootingView . Model (
113
- connectionStatusPublisher: statusReporter . statusObserver . publisher ,
114
- siteTroubleshootingInfoPublisher : $siteInfo . eraseToAnyPublisher ( ) ,
124
+ connectionStatusPublisher: connectionStatusPublisher ,
125
+ activeSitePublisher : activeSitePublisher ,
115
126
uiActionHandler: uiActionHandler)
116
127
117
128
let statusViewModel = NetworkProtectionStatusView . Model ( controller: controller,
@@ -157,10 +168,36 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager {
157
168
_ = try ? await self ? . vpnUninstaller. uninstall ( removeSystemExtension: true )
158
169
} )
159
170
171
+ let featureFlagger = NSApp . delegateTyped. featureFlagger
172
+ let tipsFeatureFlagInitialValue = featureFlagger. isFeatureOn ( . networkProtectionUserTips)
173
+ let tipsFeatureFlagPublisher : CurrentValuePublisher < Bool , Never >
174
+
175
+ if let overridesHandler = featureFlagger. localOverrides? . actionHandler as? FeatureFlagOverridesPublishingHandler < FeatureFlag > {
176
+
177
+ let featureFlagPublisher = overridesHandler. flagDidChangePublisher
178
+ . filter { $0. 0 == . networkProtectionUserTips }
179
+
180
+ tipsFeatureFlagPublisher = CurrentValuePublisher (
181
+ initialValue: tipsFeatureFlagInitialValue,
182
+ publisher: Just ( tipsFeatureFlagInitialValue) . eraseToAnyPublisher ( ) )
183
+ } else {
184
+ tipsFeatureFlagPublisher = CurrentValuePublisher (
185
+ initialValue: tipsFeatureFlagInitialValue,
186
+ publisher: Just ( tipsFeatureFlagInitialValue) . eraseToAnyPublisher ( ) )
187
+ }
188
+
189
+ let tipsModel = VPNTipsModel ( featureFlagPublisher: tipsFeatureFlagPublisher,
190
+ statusObserver: statusReporter. statusObserver,
191
+ activeSitePublisher: activeSitePublisher,
192
+ forMenuApp: false ,
193
+ vpnSettings: vpnSettings,
194
+ logger: Logger ( subsystem: " DuckDuckGo " , category: " TipKit " ) )
195
+
160
196
let popover = NetworkProtectionPopover (
161
197
statusViewModel: statusViewModel,
162
198
statusReporter: statusReporter,
163
199
siteTroubleshootingViewModel: siteTroubleshootingViewModel,
200
+ tipsModel: tipsModel,
164
201
debugInformationViewModel: DebugInformationViewModel ( showDebugInformation: false ) )
165
202
popover. delegate = delegate
166
203
0 commit comments