Skip to content
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 35 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1beb4c9
WIP
diegoreymendez Oct 15, 2024
12c6d00
WIP
diegoreymendez Oct 17, 2024
c5723b2
WIP
diegoreymendez Oct 17, 2024
9c54287
WIP
diegoreymendez Oct 17, 2024
59b9348
Renames a few classes to improve readability
diegoreymendez Oct 17, 2024
2492fee
Makes several improvements to the code so that some publishers offer …
diegoreymendez Oct 17, 2024
80b97e0
WIP
diegoreymendez Oct 17, 2024
5d0687f
Updated BSK
diegoreymendez Oct 17, 2024
3c6260f
Changed the geolocation tip icon
diegoreymendez Oct 17, 2024
e6ccb08
Updated icons for VPN onboarding tips
diegoreymendez Oct 17, 2024
607feb0
WIP
diegoreymendez Oct 22, 2024
aa937d5
WIP
diegoreymendez Oct 22, 2024
7d0404a
WIP
diegoreymendez Oct 24, 2024
f5b3b71
WIP
diegoreymendez Oct 28, 2024
83899f3
WIP
diegoreymendez Oct 28, 2024
a2fa5dc
WIP
diegoreymendez Oct 29, 2024
9ca31ec
WIP
diegoreymendez Nov 19, 2024
31f022c
Merge branch 'main' into diego/add-vpn-tips
diegoreymendez Nov 19, 2024
865a5a7
Fixes TipKit on macOS. More fixes coming up.
diegoreymendez Nov 19, 2024
d807463
WIP
diegoreymendez Nov 19, 2024
a32cb01
Rolls back some unintentional changes
diegoreymendez Nov 19, 2024
a63b154
WIP
diegoreymendez Nov 19, 2024
ed60c48
Pushes additional fixes
diegoreymendez Nov 20, 2024
bf91f74
Addresses an issue with the code to handle the TipKit feature flag
diegoreymendez Nov 20, 2024
3ae5700
Fixes swiftlint warnings
diegoreymendez Nov 20, 2024
18b2b7a
Rolls back an unintentional change
diegoreymendez Nov 20, 2024
986777c
Makes some changes to improve TipKit support
diegoreymendez Nov 21, 2024
112a301
Fixes some issues with VPN tips
diegoreymendez Nov 21, 2024
cd57672
Fixes several UI issues in the new VPN tips
diegoreymendez Nov 22, 2024
3554610
Darkens the tip background
diegoreymendez Nov 22, 2024
6d99f53
Updates the VPN tips background color
diegoreymendez Nov 25, 2024
36d251c
Updates the tip background color
diegoreymendez Nov 25, 2024
5a77984
Fixes the conditions for showing our VPN tips
diegoreymendez Nov 26, 2024
5cd2212
Implements pixels for our VPN tips
diegoreymendez Nov 26, 2024
d1bb000
Updates some log messages that were off.
diegoreymendez Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 64 additions & 6 deletions DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

DataBrokerProtectionAppEvents(featureGatekeeper: pirGatekeeper).applicationDidFinishLaunching()

TipKitAppEventHandler(featureFlagger: featureFlagger).appDidFinishLaunching()

setUpAutoClearHandler()

setUpAutofillPixelReporter()
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/Menus/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,11 @@ final class MainMenu: NSMenu {
openSubscriptionTab: { WindowControllersManager.shared.showTab(with: .subscription($0)) },
subscriptionManager: Application.appDelegate.subscriptionManager)

NSMenuItem(title: "TipKit") {
NSMenuItem(title: "Reset", action: #selector(MainViewController.resetTipKit))
NSMenuItem(title: "⚠️ App restart required.", action: nil, target: nil)
}
Comment on lines +726 to +729
Copy link
Contributor Author

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.


NSMenuItem(title: "Logging").submenu(setupLoggingMenu())
NSMenuItem(title: "AI Chat").submenu(AIChatDebugMenu())

Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/Menus/MainMenuActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,10 @@ extension MainViewController {
SyncPromoManager().resetPromos()
}

@objc func resetTipKit(_ sender: Any?) {
TipKitDebugOptionsUIActionHandler().resetTipKitTapped()
}

@objc func internalUserState(_ sender: Any?) {
guard let internalUserDecider = NSApp.delegateTyped.internalUserDecider as? DefaultInternalUserDecider else { return }
let state = internalUserDecider.isInternalUser
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SiteTroubleshootingInfoPublisher.swift
// ActiveSiteInfoPublisher.swift
samsymons marked this conversation as resolved.
Show resolved Hide resolved
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
Expand All @@ -22,15 +22,15 @@ import NetworkProtectionProxy
import NetworkProtectionUI

@MainActor
final class SiteTroubleshootingInfoPublisher {
final class ActiveSiteInfoPublisher {

private var activeDomain: String? {
didSet {
refreshSiteTroubleshootingInfo()
refreshActiveSiteInfo()
}
}

private let subject: CurrentValueSubject<SiteTroubleshootingInfo?, Never>
private let subject: CurrentValueSubject<ActiveSiteInfo?, Never>

private let activeDomainPublisher: AnyPublisher<String?, Never>
private let proxySettings: TransparentProxySettings
Expand All @@ -39,7 +39,7 @@ final class SiteTroubleshootingInfoPublisher {
init(activeDomainPublisher: AnyPublisher<String?, Never>,
proxySettings: TransparentProxySettings) {

subject = CurrentValueSubject<SiteTroubleshootingInfo?, Never>(nil)
subject = CurrentValueSubject<ActiveSiteInfo?, Never>(nil)
self.activeDomainPublisher = activeDomainPublisher
self.proxySettings = proxySettings

Expand All @@ -59,7 +59,7 @@ final class SiteTroubleshootingInfoPublisher {

switch change {
case .excludedDomains:
refreshSiteTroubleshootingInfo()
refreshActiveSiteInfo()
default:
break
}
Expand All @@ -68,29 +68,29 @@ final class SiteTroubleshootingInfoPublisher {

// MARK: - Refreshing

func refreshSiteTroubleshootingInfo() {
if activeSiteTroubleshootingInfo != subject.value {
subject.send(activeSiteTroubleshootingInfo)
func refreshActiveSiteInfo() {
if activeActiveSiteInfo != subject.value {
subject.send(activeActiveSiteInfo)
}
}

// MARK: - Active Site Troubleshooting Info

var activeSiteTroubleshootingInfo: SiteTroubleshootingInfo? {
var activeActiveSiteInfo: ActiveSiteInfo? {
guard let activeDomain else {
return nil
}

return site(forDomain: activeDomain.droppingWwwPrefix())
}

private func site(forDomain domain: String) -> SiteTroubleshootingInfo? {
private func site(forDomain domain: String) -> ActiveSiteInfo? {
let icon: NSImage?
let currentSite: NetworkProtectionUI.SiteTroubleshootingInfo?
let currentSite: NetworkProtectionUI.ActiveSiteInfo?

icon = FaviconManager.shared.getCachedFavicon(forDomainOrAnySubdomain: domain, sizeCategory: .small)?.image
let proxySettings = TransparentProxySettings(defaults: .netP)
currentSite = NetworkProtectionUI.SiteTroubleshootingInfo(
currentSite = NetworkProtectionUI.ActiveSiteInfo(
icon: icon,
domain: domain,
excluded: proxySettings.isExcluding(domain: domain))
Expand All @@ -99,12 +99,12 @@ final class SiteTroubleshootingInfoPublisher {
}
}

extension SiteTroubleshootingInfoPublisher: Publisher {
typealias Output = SiteTroubleshootingInfo?
extension ActiveSiteInfoPublisher: Publisher {
typealias Output = ActiveSiteInfo?
typealias Failure = Never

nonisolated
func receive<S>(subscriber: S) where S: Subscriber, Never == S.Failure, NetworkProtectionUI.SiteTroubleshootingInfo? == S.Input {
func receive<S>(subscriber: S) where S: Subscriber, Never == S.Failure, NetworkProtectionUI.ActiveSiteInfo? == S.Input {

subject.receive(subscriber: subscriber)
}
Expand Down
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 All @@ -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,
Expand All @@ -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)
}
Expand All @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Expand Down
28 changes: 28 additions & 0 deletions DuckDuckGo/TipKit/Logger+TipKit.swift
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")
}()
}
72 changes: 72 additions & 0 deletions DuckDuckGo/TipKit/TipKitAppEventHandling.swift
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 DuckDuckGo/TipKit/TipKitController+ConvenienceInitializers.swift
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)
}
}
Loading
Loading