-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show VPN onboarding tips #3410
Merged
Merged
Show VPN onboarding tips #3410
Changes from 21 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
1beb4c9
WIP
diegoreymendez 12c6d00
WIP
diegoreymendez c5723b2
WIP
diegoreymendez 9c54287
WIP
diegoreymendez 59b9348
Renames a few classes to improve readability
diegoreymendez 2492fee
Makes several improvements to the code so that some publishers offer …
diegoreymendez 80b97e0
WIP
diegoreymendez 5d0687f
Updated BSK
diegoreymendez 3c6260f
Changed the geolocation tip icon
diegoreymendez e6ccb08
Updated icons for VPN onboarding tips
diegoreymendez 607feb0
WIP
diegoreymendez aa937d5
WIP
diegoreymendez 7d0404a
WIP
diegoreymendez f5b3b71
WIP
diegoreymendez 83899f3
WIP
diegoreymendez a2fa5dc
WIP
diegoreymendez 9ca31ec
WIP
diegoreymendez 31f022c
Merge branch 'main' into diego/add-vpn-tips
diegoreymendez 865a5a7
Fixes TipKit on macOS. More fixes coming up.
diegoreymendez d807463
WIP
diegoreymendez a32cb01
Rolls back some unintentional changes
diegoreymendez a63b154
WIP
diegoreymendez ed60c48
Pushes additional fixes
diegoreymendez bf91f74
Addresses an issue with the code to handle the TipKit feature flag
diegoreymendez 3ae5700
Fixes swiftlint warnings
diegoreymendez 18b2b7a
Rolls back an unintentional change
diegoreymendez 986777c
Makes some changes to improve TipKit support
diegoreymendez 112a301
Fixes some issues with VPN tips
diegoreymendez cd57672
Fixes several UI issues in the new VPN tips
diegoreymendez 3554610
Darkens the tip background
diegoreymendez 6d99f53
Updates the VPN tips background color
diegoreymendez 36d251c
Updates the tip background color
diegoreymendez 5a77984
Fixes the conditions for showing our VPN tips
diegoreymendez 5cd2212
Implements pixels for our VPN tips
diegoreymendez d1bb000
Updates some log messages that were off.
diegoreymendez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 } | ||
|
@@ -55,8 +56,8 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager { | |
let vpnUninstaller: VPNUninstalling | ||
|
||
@Published | ||
private var siteInfo: SiteTroubleshootingInfo? | ||
private let siteTroubleshootingInfoPublisher: SiteTroubleshootingInfoPublisher | ||
private var siteInfo: ActiveSiteInfo? | ||
private let activeSitePublisher: ActiveSiteInfoPublisher | ||
private var cancellables = Set<AnyCancellable>() | ||
|
||
init(ipcClient: VPNControllerXPCClient, | ||
|
@@ -67,15 +68,15 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager { | |
|
||
let activeDomainPublisher = ActiveDomainPublisher(windowControllersManager: .shared) | ||
|
||
siteTroubleshootingInfoPublisher = SiteTroubleshootingInfoPublisher( | ||
activeSitePublisher = ActiveSiteInfoPublisher( | ||
activeDomainPublisher: activeDomainPublisher.eraseToAnyPublisher(), | ||
proxySettings: TransparentProxySettings(defaults: .netP)) | ||
|
||
subscribeToCurrentSitePublisher() | ||
} | ||
|
||
private func subscribeToCurrentSitePublisher() { | ||
siteTroubleshootingInfoPublisher | ||
activeSitePublisher | ||
.assign(to: \.siteInfo, onWeaklyHeld: self) | ||
.store(in: &cancellables) | ||
} | ||
|
@@ -87,9 +88,10 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager { | |
func show(positionedBelow view: NSView, withDelegate delegate: NSPopoverDelegate) -> NSPopover { | ||
|
||
/// Since the favicon doesn't have a publisher we force refreshing here | ||
siteTroubleshootingInfoPublisher.refreshSiteTroubleshootingInfo() | ||
activeSitePublisher.refreshActiveSiteInfo() | ||
|
||
let popover: NSPopover = { | ||
let vpnSettings = VPNSettings(defaults: .netP) | ||
let controller = NetworkProtectionIPCTunnelController(ipcClient: ipcClient) | ||
|
||
let statusReporter = DefaultNetworkProtectionStatusReporter( | ||
|
@@ -103,15 +105,18 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager { | |
) | ||
|
||
let onboardingStatusPublisher = UserDefaults.netP.networkProtectionOnboardingStatusPublisher | ||
_ = VPNSettings(defaults: .netP) | ||
let appLauncher = AppLauncher(appBundleURL: Bundle.main.bundleURL) | ||
let vpnURLEventHandler = VPNURLEventHandler() | ||
let proxySettings = TransparentProxySettings(defaults: .netP) | ||
let uiActionHandler = VPNUIActionHandler(vpnURLEventHandler: vpnURLEventHandler, proxySettings: proxySettings) | ||
|
||
let activeSitePublisher = CurrentValuePublisher( | ||
initialValue: nil, | ||
publisher: $siteInfo.eraseToAnyPublisher()) | ||
|
||
let siteTroubleshootingViewModel = SiteTroubleshootingView.Model( | ||
connectionStatusPublisher: statusReporter.statusObserver.publisher, | ||
siteTroubleshootingInfoPublisher: $siteInfo.eraseToAnyPublisher(), | ||
activeSitePublisher: activeSitePublisher.eraseToAnyPublisher(), | ||
uiActionHandler: uiActionHandler) | ||
|
||
let statusViewModel = NetworkProtectionStatusView.Model(controller: controller, | ||
|
@@ -157,10 +162,21 @@ final class NetworkProtectionNavBarPopoverManager: NetPPopoverManager { | |
_ = try? await self?.vpnUninstaller.uninstall(removeSystemExtension: true) | ||
}) | ||
|
||
// TODO: replace with access to actual feature flag | ||
let tipsFeatureFlagPublisher = CurrentValuePublisher(initialValue: true, publisher: Just(true).eraseToAnyPublisher()) | ||
|
||
let tipsModel = VPNTipsModel(featureFlagPublisher: tipsFeatureFlagPublisher, | ||
statusObserver: statusReporter.statusObserver, | ||
activeSitePublisher: activeSitePublisher, | ||
forMenuApp: false, | ||
vpnSettings: vpnSettings, | ||
logger: Logger(subsystem: "DuckDuckGo", category: "TipKit")) | ||
Comment on lines
+189
to
+194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new model for handling the tips. |
||
|
||
let popover = NetworkProtectionPopover( | ||
statusViewModel: statusViewModel, | ||
statusReporter: statusReporter, | ||
siteTroubleshootingViewModel: siteTroubleshootingViewModel, | ||
tipsModel: tipsModel, | ||
debugInformationViewModel: DebugInformationViewModel(showDebugInformation: false)) | ||
popover.delegate = delegate | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Logger+TipKit.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import os.log | ||
|
||
extension Logger { | ||
|
||
static var tipKit: Logger = { | ||
Logger(subsystem: Bundle.main.bundleIdentifier ?? "DuckDuckGo", category: "TipKit") | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// TipKitAppEventHandling.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import BrowserServicesKit | ||
import os.log | ||
import TipKit | ||
|
||
protocol TipKitAppEventHandling { | ||
func appDidFinishLaunching() | ||
} | ||
|
||
struct TipKitAppEventHandler: TipKitAppEventHandling { | ||
|
||
private let controller: TipKitController | ||
private let featureFlagger: FeatureFlagger | ||
private let logger: Logger | ||
|
||
init(controller: TipKitController = .make(), | ||
featureFlagger: FeatureFlagger, | ||
logger: Logger = .tipKit) { | ||
|
||
self.controller = controller | ||
self.featureFlagger = featureFlagger | ||
self.logger = logger | ||
} | ||
|
||
func appDidFinishLaunching() { | ||
guard featureFlagger.isFeatureOn(.networkProtectionUserTips) else { | ||
logger.log("TipKit disabled by remote feature flag.") | ||
return | ||
} | ||
|
||
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 { | ||
fatalError() | ||
} | ||
|
||
controller.configureTipKit([ | ||
.displayFrequency(.immediate), | ||
.datastoreLocation(dataStoreLocation) | ||
]) | ||
} else { | ||
logger.log("TipKit initialization skipped: iOS 17.0 or later is required.") | ||
diegoreymendez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
DuckDuckGo/TipKit/TipKitController+ConvenienceInitializers.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// TipKitController+ConvenienceInitializers.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import os | ||
|
||
extension TipKitController { | ||
|
||
static func make(logger: Logger = .tipKit, | ||
userDefaults: UserDefaults = .appConfiguration) -> Self { | ||
|
||
self.init(logger: logger, userDefaults: userDefaults) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convenience menu to test TipKit.