Skip to content

Commit

Permalink
Sabrina/new onboarding (#2925)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/414235014887631/1207310947118104/f

**Description**: Brings the Windows onboarding to macOS as A/B test
  • Loading branch information
SabrinaTardio authored Jul 1, 2024
1 parent fac0a43 commit d9a7070
Show file tree
Hide file tree
Showing 70 changed files with 2,379 additions and 113 deletions.
124 changes: 123 additions & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "6b579d512d7e4fbb9d0f0ede5ffd7901b390806b",
"version" : "164.1.0"
"revision" : "912001a8676345e96a8be360d5a6e3dca6d8e0ec",
"version" : "164.2.0"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "4689746e42b24c40c18896d697ea02b854e90d35",
"version" : "5.21.0"
"revision" : "7ac68ae3bc052fa59adbc1ba8fd5cb5849a6bc99",
"version" : "5.25.0"
}
},
{
Expand Down
11 changes: 3 additions & 8 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
_ = DownloadListCoordinator.shared
_ = RecentlyClosedCoordinator.shared

// Clean up previous experiment
// if PixelExperiment.allocatedCohortDoesNotMatchCurrentCohorts { // Re-implement https://app.asana.com/0/0/1207002879349166/f
// PixelExperiment.cleanup()
// }
PixelExperiment.install()

if LocalStatisticsStore().atb == nil {
AppDelegate.firstLaunchDate = Date()
Expand Down Expand Up @@ -374,6 +371,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidBecomeActive(_ notification: Notification) {
guard didFinishLaunching else { return }

PixelExperiment.fireOnboardingTestPixels()
syncService?.initializeIfNeeded()
syncService?.scheduler.notifyAppLifecycleEvent()

Expand Down Expand Up @@ -495,10 +493,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

#if DEBUG || REVIEW
let environment = ServerEnvironment(
UserDefaultsWrapper(
key: .syncEnvironment,
defaultValue: defaultEnvironment.description
).wrappedValue
UserDefaultsWrapper(key: .syncEnvironment, defaultValue: defaultEnvironment.description).wrappedValue
) ?? defaultEnvironment
#else
let environment = defaultEnvironment
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Application/DockCustomizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ final class DockCustomizer: DockCustomization {
// to restart after a brief delay to apply the changes.
@discardableResult
func addToDock() -> Bool {
PixelExperiment.fireOnboardingAddToDockRequestedPixel()
let appPath = Bundle.main.bundleURL.path
guard !isAddedToDock,
let bundleIdentifier = Bundle.main.bundleIdentifier,
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Bookmarks/View/BookmarkListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ extension BookmarkListViewController: FolderMenuItemSelectors {

let tabs = Tab.withContentOfBookmark(folder: folder, burnerMode: tabCollection.burnerMode)
tabCollection.append(tabs: tabs)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

func openAllInNewWindow(_ sender: NSMenuItem) {
Expand All @@ -625,6 +626,7 @@ extension BookmarkListViewController: FolderMenuItemSelectors {

let newTabCollection = TabCollection.withContentOfBookmark(folder: folder, burnerMode: tabCollection.burnerMode)
WindowsManager.openNewWindow(with: newTabCollection, isBurner: tabCollection.isBurner)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ extension BookmarkManagementDetailViewController: NSTableViewDelegate, NSTableVi
burnerMode: tabCollection.burnerMode)
}
tabCollection.append(tabs: tabs)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}
}

Expand Down Expand Up @@ -683,6 +684,7 @@ extension BookmarkManagementDetailViewController: FolderMenuItemSelectors {
} else {
assertionFailure("Failed to open entity in new tabs")
}
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

func openAllInNewWindow(_ sender: NSMenuItem) {
Expand All @@ -695,6 +697,7 @@ extension BookmarkManagementDetailViewController: FolderMenuItemSelectors {

let newTabCollection = TabCollection.withContentOfBookmark(folder: folder, burnerMode: tabCollection.burnerMode)
WindowsManager.openNewWindow(with: newTabCollection, isBurner: tabCollection.isBurner)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

}
Expand All @@ -709,6 +712,7 @@ extension BookmarkManagementDetailViewController: BookmarkMenuItemSelectors {
}

WindowControllersManager.shared.show(url: url, source: .bookmark, newTab: true)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

func openBookmarkInNewWindow(_ sender: NSMenuItem) {
Expand All @@ -719,6 +723,7 @@ extension BookmarkManagementDetailViewController: BookmarkMenuItemSelectors {
}

WindowsManager.openNewWindow(with: url, source: .bookmark, isBurner: false)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

func toggleBookmarkAsFavorite(_ sender: NSMenuItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ extension BookmarkManagementSidebarViewController: FolderMenuItemSelectors {

let tabs = Tab.withContentOfBookmark(folder: folder, burnerMode: tabCollection.burnerMode)
tabCollection.append(tabs: tabs)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

func openAllInNewWindow(_ sender: NSMenuItem) {
Expand All @@ -363,6 +364,7 @@ extension BookmarkManagementSidebarViewController: FolderMenuItemSelectors {

let newTabCollection = TabCollection.withContentOfBookmark(folder: folder, burnerMode: tabCollection.burnerMode)
WindowsManager.openNewWindow(with: newTabCollection, isBurner: tabCollection.isBurner)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

}
Expand Down
14 changes: 14 additions & 0 deletions DuckDuckGo/BookmarksBar/View/BookmarksBar.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="X6g-3K-JDi">
<rect key="frame" x="0.0" y="-2" width="676" height="5"/>
</box>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Pbn-uk-iJf">
<rect key="frame" x="7" y="11" width="174" height="32"/>
<buttonCell key="cell" type="push" title="Import Bookmarks..." bezelStyle="rounded" image="square.and.arrow.down" catalog="system" imagePosition="leading" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="CgH-qm-9us">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<connections>
<action selector="importBookmarksClicked:" target="JFF-Nj-8om" id="L2L-md-2OA"/>
</connections>
</buttonCell>
</button>
</subviews>
<constraints>
<constraint firstItem="X6g-3K-JDi" firstAttribute="leading" secondItem="R54-3G-cms" secondAttribute="leading" id="0AB-Ps-M7N"/>
Expand All @@ -67,6 +77,8 @@
<constraint firstItem="cjE-4p-vxI" firstAttribute="centerX" secondItem="R54-3G-cms" secondAttribute="centerX" id="T6z-7g-NZA"/>
<constraint firstAttribute="trailing" secondItem="Mgr-xJ-Pl5" secondAttribute="trailing" constant="8" id="UCG-Ww-dsY"/>
<constraint firstAttribute="trailing" secondItem="X6g-3K-JDi" secondAttribute="trailing" id="ZaK-nU-eHk"/>
<constraint firstItem="Pbn-uk-iJf" firstAttribute="leading" secondItem="R54-3G-cms" secondAttribute="leading" constant="14" id="bPU-D0-qHa"/>
<constraint firstItem="Pbn-uk-iJf" firstAttribute="centerY" secondItem="R54-3G-cms" secondAttribute="centerY" id="cPZ-VT-0aI"/>
<constraint firstItem="Mgr-xJ-Pl5" firstAttribute="centerY" secondItem="R54-3G-cms" secondAttribute="centerY" constant="-1" id="eoh-hW-GcD"/>
<constraint firstItem="D39-Of-BIh" firstAttribute="leading" secondItem="R54-3G-cms" secondAttribute="leading" id="hOd-Bz-o5j"/>
<constraint firstAttribute="bottom" secondItem="X6g-3K-JDi" secondAttribute="bottom" id="iWj-iC-9gW"/>
Expand All @@ -81,6 +93,7 @@
<connections>
<outlet property="bookmarksBarCollectionView" destination="vwg-NL-UPk" id="1LG-QE-Dgd"/>
<outlet property="clippedItemsIndicator" destination="Mgr-xJ-Pl5" id="4ww-Po-dNb"/>
<outlet property="importBookmarksButton" destination="Pbn-uk-iJf" id="DTf-Qt-3Cl"/>
<outlet property="promptAnchor" destination="cjE-4p-vxI" id="IGH-2v-PGD"/>
</connections>
</viewController>
Expand All @@ -91,6 +104,7 @@
</scenes>
<resources>
<image name="Chevron-Double-Right-16" width="16" height="16"/>
<image name="square.and.arrow.down" catalog="system" width="15" height="17"/>
<namedColor name="AddressBarFocusedBackgroundColor">
<color red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class BookmarksBarCollectionViewItem: NSCollectionViewItem {

static let identifier = NSUserInterfaceItemIdentifier(rawValue: "BookmarksBarCollectionViewItem")

@IBOutlet private weak var mouseOverView: MouseOverView!
@IBOutlet var stackView: NSStackView!
@IBOutlet private var faviconView: NSImageView! {
didSet {
Expand Down Expand Up @@ -69,7 +70,7 @@ final class BookmarksBarCollectionViewItem: NSCollectionViewItem {
createMenu()
}

func updateItem(from entity: BaseBookmarkEntity) {
func updateItem(from entity: BaseBookmarkEntity, isInteractionPrevented: Bool) {
self.title = entity.title

if let bookmark = entity as? Bookmark {
Expand Down Expand Up @@ -101,6 +102,10 @@ final class BookmarksBarCollectionViewItem: NSCollectionViewItem {
case .folder:
faviconView.image = .folder16
}
mouseOverView.isEnabled = !isInteractionPrevented
faviconView.isEnabled = !isInteractionPrevented
titleLabel.isEnabled = !isInteractionPrevented
titleLabel.alphaValue = isInteractionPrevented ? 0.3 : 1
}

private func configureLayer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -64,6 +64,7 @@
<collectionViewItem id="mo5-Bi-OJI" customClass="BookmarksBarCollectionViewItem" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target">
<connections>
<outlet property="faviconView" destination="aEY-jN-qvL" id="vuC-Cm-ECU"/>
<outlet property="mouseOverView" destination="IHK-ff-XkT" id="bZ1-cF-QUA"/>
<outlet property="titleLabel" destination="fMp-kj-J3A" id="Sxw-1t-GqZ"/>
<outlet property="view" destination="Hz6-mo-xeY" id="Zhf-KI-eAw"/>
</connections>
Expand Down
24 changes: 24 additions & 0 deletions DuckDuckGo/BookmarksBar/View/BookmarksBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Foundation

final class BookmarksBarViewController: NSViewController {

@IBOutlet weak var importBookmarksButton: NSButton!
@IBOutlet private var bookmarksBarCollectionView: NSCollectionView!
@IBOutlet private var clippedItemsIndicator: NSButton!
@IBOutlet private var promptAnchor: NSView!
Expand Down Expand Up @@ -76,6 +77,7 @@ final class BookmarksBarViewController: NSViewController {
BookmarkPasteboardWriter.bookmarkUTIInternalType,
FolderPasteboardWriter.folderUTIInternalType
])
importBookmarksButton.title = UserText.importBookmarks

bookmarksBarCollectionView.delegate = viewModel
bookmarksBarCollectionView.dataSource = viewModel
Expand Down Expand Up @@ -109,6 +111,13 @@ final class BookmarksBarViewController: NSViewController {
self.bookmarksBarPromptShown = true
}

func userInteraction(prevented: Bool) {
bookmarksBarCollectionView.isSelectable = !prevented
clippedItemsIndicator.isEnabled = !prevented
viewModel.isInteractionPrevented = prevented
bookmarksBarCollectionView.reloadData()
}

private func frameDidChangeNotification() {
self.viewModel.clipOrRestoreBookmarksBarItems()
self.refreshClippedIndicator()
Expand Down Expand Up @@ -142,6 +151,13 @@ final class BookmarksBarViewController: NSViewController {
self?.refreshClippedIndicator()
}
.store(in: &cancellables)

viewModel.$bookmarksBarItems
.receive(on: DispatchQueue.main)
.sink { [weak self] items in
self?.importBookmarksButton.isHidden = !items.isEmpty
}
.store(in: &cancellables)
}

private func unsubscribeFromEvents() {
Expand Down Expand Up @@ -169,6 +185,9 @@ final class BookmarksBarViewController: NSViewController {
dispatchPrecondition(condition: .onQueue(.main))
bookmarksBarCollectionView.reloadData()
}
@IBAction func importBookmarksClicked(_ sender: Any) {
DataImportView().show()
}

@IBAction
private func clippedItemsIndicatorClicked(_ sender: NSButton) {
Expand Down Expand Up @@ -238,6 +257,7 @@ private extension BookmarksBarViewController {
openInNewWindow(bookmark: bookmark)
case .clickItem:
WindowControllersManager.shared.open(bookmark: bookmark)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
case .toggleFavorites:
bookmark.isFavorite.toggle()
bookmarkManager.update(bookmark: bookmark)
Expand Down Expand Up @@ -289,21 +309,25 @@ private extension BookmarksBarViewController {
func openInNewTab(bookmark: Bookmark) {
guard let url = bookmark.urlObject else { return }
tabCollectionViewModel.appendNewTab(with: .url(url, source: .bookmark), selected: true)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

func openInNewWindow(bookmark: Bookmark) {
guard let url = bookmark.urlObject else { return }
WindowsManager.openNewWindow(with: url, source: .bookmark, isBurner: false)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

func openAllInNewTabs(folder: BookmarkFolder) {
let tabs = Tab.withContentOfBookmark(folder: folder, burnerMode: tabCollectionViewModel.burnerMode)
tabCollectionViewModel.append(tabs: tabs)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

func openAllInNewWindow(folder: BookmarkFolder) {
let tabCollection = TabCollection.withContentOfBookmark(folder: folder, burnerMode: tabCollectionViewModel.burnerMode)
WindowsManager.openNewWindow(with: tabCollection, isBurner: tabCollectionViewModel.isBurner)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}

func showSubmenuFor(folder: BookmarkFolder, fromView view: NSView) {
Expand Down
5 changes: 3 additions & 2 deletions DuckDuckGo/BookmarksBar/View/BookmarksBarViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ protocol BookmarksBarViewModelDelegate: AnyObject {
func bookmarksBarViewModelReceived(action: BookmarksBarViewModel.BookmarksBarItemAction, for item: BookmarksBarCollectionViewItem)
func bookmarksBarViewModelWidthForContainer() -> CGFloat
func bookmarksBarViewModelReloadedData()

}

final class BookmarksBarViewModel: NSObject {
Expand Down Expand Up @@ -71,6 +70,7 @@ final class BookmarksBarViewModel: NSObject {
}

weak var delegate: BookmarksBarViewModelDelegate?
var isInteractionPrevented = false

private let bookmarkManager: BookmarkManager
private let tabCollectionViewModel: TabCollectionViewModel
Expand All @@ -90,6 +90,7 @@ final class BookmarksBarViewModel: NSObject {
return calculationLabel
}()

@Published
private(set) var bookmarksBarItems: [BookmarksBarItem] = [] {
didSet {
let itemsWidth = bookmarksBarItems.reduce(CGFloat(0)) { total, item in
Expand Down Expand Up @@ -327,7 +328,7 @@ extension BookmarksBarViewModel: NSCollectionViewDelegate, NSCollectionViewDataS

let bookmarksBarItem = bookmarksBarItems[indexPath.item]
bookmarksCollectionViewItem.delegate = self
bookmarksCollectionViewItem.updateItem(from: bookmarksBarItem.entity)
bookmarksCollectionViewItem.updateItem(from: bookmarksBarItem.entity, isInteractionPrevented: isInteractionPrevented)

return bookmarksCollectionViewItem
}
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/Common/Extensions/URLExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ extension URL {

// MARK: - DuckDuckGo

static var onboarding: URL {
let onboardingUrlString = "duck://onboarding"
return URL(string: onboardingUrlString)!
}

static var duckDuckGo: URL {
let duckDuckGoUrlString = "https://duckduckgo.com/"
return URL(string: duckDuckGoUrlString)!
Expand Down
13 changes: 12 additions & 1 deletion DuckDuckGo/ContentBlocker/ScriptSourceProviding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protocol ScriptSourceProviding {
var privacyConfigurationManager: PrivacyConfigurationManaging { get }
var autofillSourceProvider: AutofillUserScriptSourceProvider? { get }
var sessionKey: String? { get }
var onboardingActionsManager: OnboardingActionsManaging? { get }
func buildAutofillSource() -> AutofillUserScriptSourceProvider

}
Expand All @@ -41,9 +42,9 @@ func DefaultScriptSourceProvider() -> ScriptSourceProviding {
}

struct ScriptSourceProvider: ScriptSourceProviding {

private(set) var contentBlockerRulesConfig: ContentBlockerUserScriptConfig?
private(set) var surrogatesConfig: SurrogatesUserScriptConfig?
private(set) var onboardingActionsManager: OnboardingActionsManaging?
private(set) var autofillSourceProvider: AutofillUserScriptSourceProvider?
private(set) var sessionKey: String?

Expand Down Expand Up @@ -72,6 +73,7 @@ struct ScriptSourceProvider: ScriptSourceProviding {
self.surrogatesConfig = buildSurrogatesConfig()
self.sessionKey = generateSessionKey()
self.autofillSourceProvider = buildAutofillSource()
self.onboardingActionsManager = buildOnboardingActionsManager()
}

private func generateSessionKey() -> String {
Expand Down Expand Up @@ -125,6 +127,15 @@ struct ScriptSourceProvider: ScriptSourceProviding {
isDebugBuild: isDebugBuild)
}

private func buildOnboardingActionsManager() -> OnboardingActionsManaging {
return OnboardingActionsManager(
navigationDelegate: WindowControllersManager.shared,
dockCustomization: DockCustomizer(),
defaultBrowserProvider: SystemDefaultBrowserProvider(),
appearancePreferences: AppearancePreferences.shared,
startupPreferences: StartupPreferences.shared)
}

private func loadTextFile(_ fileName: String, _ fileExt: String) -> String? {
let url = Bundle.main.url(
forResource: fileName,
Expand Down
Loading

0 comments on commit d9a7070

Please sign in to comment.