Skip to content

Commit

Permalink
Merge branch 'main' into anh/pir/data-model-mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
quanganhdo committed Dec 5, 2024
2 parents 5d320d0 + 7b2a893 commit 6029e64
Show file tree
Hide file tree
Showing 38 changed files with 1,004 additions and 74 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/publish_dmg_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ jobs:
github_handle:"${{ github.actor }}" \
is_scheduled_release:"${{ github.event_name == 'schedule' }}" \
release_task_id:"${{ steps.task-id.outputs.asana_task_id }}" \
target_section_id:"${{ vars.MACOS_APP_BOARD_DONE_SECTION_ID }}"
target_section_id:"${{ vars.MACOS_APP_BOARD_DONE_SECTION_ID }}" \
tag:"${{ env.TAG }}"
- name: Get tasks since last internal release
id: get-tasks-since-last-internal-release
Expand Down
2 changes: 1 addition & 1 deletion Configuration/BuildNumber.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 323
CURRENT_PROJECT_VERSION = 324
46 changes: 45 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,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "befc1f1094353d8d88a99ac08885684c978b2016",
"version" : "217.0.0"
"revision" : "e5d390c8559fbe7b1ca67fd3982c91bcc0437d60",
"version" : "218.0.0"
}
},
{
Expand Down
4 changes: 3 additions & 1 deletion DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import MetricKit
import Networking
import Persistence
import PixelKit
import PixelExperimentKit
import ServiceManagement
import SyncDataProviders
import UserNotifications
Expand Down Expand Up @@ -282,7 +283,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
keyValueStore: UserDefaults.appConfiguration,
actionHandler: FeatureFlagOverridesPublishingHandler<FeatureFlag>()
),
experimentManager: ExperimentCohortsManager(store: ExperimentsDataStore()),
experimentManager: ExperimentCohortsManager(store: ExperimentsDataStore(), fireCohortAssigned: PixelKit.fireExperimentEnrollmentPixel(subfeatureID:experiment:)),
for: FeatureFlag.self
)

Expand Down Expand Up @@ -331,6 +332,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
#else
privacyStats = PrivacyStats(databaseProvider: PrivacyStatsDatabase())
#endif
PixelKit.configureExperimentKit(featureFlagger: featureFlagger, eventTracker: ExperimentEventTracker(store: UserDefaults.appConfiguration))
}

func applicationWillFinishLaunching(_ notification: Notification) {
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/FileDownload/View/DownloadsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ final class DownloadsViewController: NSViewController {
clearDownloadsButton.imagePosition = .imageOnly
clearDownloadsButton.imageScaling = .scaleProportionallyDown
clearDownloadsButton.toolTip = UserText.clearDownloadHistoryTooltip
clearDownloadsButton.setAccessibilityIdentifier("DownloadsViewController.clearDownloadsButton")
clearDownloadsButton.cornerRadius = 4
clearDownloadsButton.backgroundInset = CGPoint(x: 2, y: 2)
clearDownloadsButton.normalTintColor = .button
Expand Down
54 changes: 44 additions & 10 deletions DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import AppKit
import BrowserServicesKit
import Combine
import Common
import Foundation
import PixelKit
Expand All @@ -26,6 +27,20 @@ import Subscription
import NetworkProtection
import NetworkProtectionUI

protocol ContinueSetUpModelTabOpening {
@MainActor
func openTab(_ tab: Tab)
}

struct TabCollectionViewModelTabOpener: ContinueSetUpModelTabOpening {
let tabCollectionViewModel: TabCollectionViewModel

@MainActor
func openTab(_ tab: Tab) {
tabCollectionViewModel.insertOrAppend(tab: tab, selected: true)
}
}

extension HomePage.Models {

static let newHomePageTabOpen = Notification.Name("newHomePageAppOpen")
Expand All @@ -49,7 +64,7 @@ extension HomePage.Models {
private let defaultBrowserProvider: DefaultBrowserProvider
private let dockCustomizer: DockCustomization
private let dataImportProvider: DataImportStatusProviding
private let tabCollectionViewModel: TabCollectionViewModel
private let tabOpener: ContinueSetUpModelTabOpening
private let emailManager: EmailManager
private let duckPlayerPreferences: DuckPlayerPreferencesPersistor
private let subscriptionManager: SubscriptionManager
Expand All @@ -58,9 +73,13 @@ extension HomePage.Models {
var shouldShowAllFeatures: Bool {
didSet {
updateVisibleMatrix()
shouldShowAllFeaturesSubject.send(shouldShowAllFeatures)
}
}

let shouldShowAllFeaturesPublisher: AnyPublisher<Bool, Never>
private let shouldShowAllFeaturesSubject = PassthroughSubject<Bool, Never>()

struct Settings {
@UserDefaultsWrapper(key: .homePageShowMakeDefault, defaultValue: true)
var shouldShowMakeDefaultSetting: Bool
Expand Down Expand Up @@ -102,36 +121,43 @@ extension HomePage.Models {

lazy var listOfFeatures = settings.isFirstSession ? firstRunFeatures : randomisedFeatures

private var featuresMatrix: [[FeatureType]] = [[]] {
@Published var featuresMatrix: [[FeatureType]] = [[]] {
didSet {
updateVisibleMatrix()
}
}

@Published var visibleFeaturesMatrix: [[FeatureType]] = [[]]

init(defaultBrowserProvider: DefaultBrowserProvider,
dockCustomizer: DockCustomization,
dataImportProvider: DataImportStatusProviding,
tabCollectionViewModel: TabCollectionViewModel,
init(defaultBrowserProvider: DefaultBrowserProvider = SystemDefaultBrowserProvider(),
dockCustomizer: DockCustomization = DockCustomizer(),
dataImportProvider: DataImportStatusProviding = BookmarksAndPasswordsImportStatusProvider(),
tabOpener: ContinueSetUpModelTabOpening,
emailManager: EmailManager = EmailManager(),
duckPlayerPreferences: DuckPlayerPreferencesPersistor,
duckPlayerPreferences: DuckPlayerPreferencesPersistor = DuckPlayerPreferencesUserDefaultsPersistor(),
privacyConfigurationManager: PrivacyConfigurationManaging = AppPrivacyFeatures.shared.contentBlocking.privacyConfigurationManager,
subscriptionManager: SubscriptionManager = Application.appDelegate.subscriptionManager) {

self.defaultBrowserProvider = defaultBrowserProvider
self.dockCustomizer = dockCustomizer
self.dataImportProvider = dataImportProvider
self.tabCollectionViewModel = tabCollectionViewModel
self.tabOpener = tabOpener
self.emailManager = emailManager
self.duckPlayerPreferences = duckPlayerPreferences
self.privacyConfigurationManager = privacyConfigurationManager
self.subscriptionManager = subscriptionManager
self.settings = .init()

shouldShowAllFeaturesPublisher = shouldShowAllFeaturesSubject.removeDuplicates().eraseToAnyPublisher()

refreshFeaturesMatrix()

NotificationCenter.default.addObserver(self, selector: #selector(newTabOpenNotification(_:)), name: HomePage.Models.newHomePageTabOpen, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(windowDidBecomeKey(_:)), name: NSWindow.didBecomeKeyNotification, object: nil)

// HTML NTP doesn't refresh on appear so we have to connect to the appear signal
// (the notification in this case) to trigger a refresh.
NotificationCenter.default.addObserver(self, selector: #selector(refreshFeaturesForHTMLNewTabPage(_:)), name: .newTabPageWebViewDidAppear, object: nil)
}

@MainActor func performAction(for featureType: FeatureType) {
Expand Down Expand Up @@ -166,14 +192,14 @@ extension HomePage.Models {
private func performDuckPlayerAction() {
if let videoUrl = URL(string: duckPlayerURL) {
let tab = Tab(content: .url(videoUrl, source: .link), shouldLoadInBackground: true)
tabCollectionViewModel.append(tab: tab)
tabOpener.openTab(tab)
}
}

@MainActor
private func performEmailProtectionAction() {
let tab = Tab(content: .url(EmailUrls().emailProtectionLink, source: .ui), shouldLoadInBackground: true)
tabCollectionViewModel.append(tab: tab)
tabOpener.openTab(tab)
}

func performDockAction() {
Expand Down Expand Up @@ -243,6 +269,14 @@ extension HomePage.Models {
}

@objc private func windowDidBecomeKey(_ notification: Notification) {
// Async dispatch allows default browser setting to propagate
// after being changed in the system dialog
DispatchQueue.main.async {
self.refreshFeaturesMatrix()
}
}

@objc private func refreshFeaturesForHTMLNewTabPage(_ notification: Notification) {
refreshFeaturesMatrix()
}

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/HomePage/View/ContinueSetUpView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ extension HomePage.Views {
.onAppear {
if featureType == .dock {
PixelKit.fire(GeneralPixel.addToDockNewTabPageCardPresented,
frequency: .unique,
frequency: .uniqueByName,
includeAppVersionParameter: false)
}
}
Expand Down Expand Up @@ -292,7 +292,7 @@ extension HomePage.Views {
defaultBrowserProvider: SystemDefaultBrowserProvider(),
dockCustomizer: DockCustomizer(),
dataImportProvider: BookmarksAndPasswordsImportStatusProvider(),
tabCollectionViewModel: TabCollectionViewModel(),
tabOpener: TabCollectionViewModelTabOpener(tabCollectionViewModel: TabCollectionViewModel()),
duckPlayerPreferences: DuckPlayerPreferencesUserDefaultsPersistor()
))
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ extension HomePage.Views.BackgroundCategoryView {
defaultBrowserProvider: SystemDefaultBrowserProvider(),
dockCustomizer: DockCustomizer(),
dataImportProvider: BookmarksAndPasswordsImportStatusProvider(),
tabCollectionViewModel: TabCollectionViewModel(),
tabOpener: TabCollectionViewModelTabOpener(tabCollectionViewModel: TabCollectionViewModel()),
duckPlayerPreferences: DuckPlayerPreferencesUserDefaultsPersistor()
))
.environmentObject(HomePage.Models.FavoritesModel(
Expand Down Expand Up @@ -276,7 +276,7 @@ extension HomePage.Views.BackgroundCategoryView {
defaultBrowserProvider: SystemDefaultBrowserProvider(),
dockCustomizer: DockCustomizer(),
dataImportProvider: BookmarksAndPasswordsImportStatusProvider(),
tabCollectionViewModel: TabCollectionViewModel(),
tabOpener: TabCollectionViewModelTabOpener(tabCollectionViewModel: TabCollectionViewModel()),
duckPlayerPreferences: DuckPlayerPreferencesUserDefaultsPersistor()
))
.environmentObject(HomePage.Models.FavoritesModel(
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/HomePage/View/HomePageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ final class HomePageViewController: NSViewController {
defaultBrowserProvider: SystemDefaultBrowserProvider(),
dockCustomizer: DockCustomizer(),
dataImportProvider: BookmarksAndPasswordsImportStatusProvider(),
tabCollectionViewModel: tabCollectionViewModel,
tabOpener: TabCollectionViewModelTabOpener(tabCollectionViewModel: tabCollectionViewModel),
duckPlayerPreferences: DuckPlayerPreferencesUserDefaultsPersistor()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ final class NavigationBarViewController: NSViewController {
bookmarkListButton.delegate = self
bookmarkListButton.setAccessibilityIdentifier("NavigationBarViewController.bookmarkListButton")
downloadsButton.sendAction(on: .leftMouseDown)
downloadsButton.setAccessibilityIdentifier("NavigationBarViewController.downloadsButton")
networkProtectionButton.sendAction(on: .leftMouseDown)
passwordManagementButton.sendAction(on: .leftMouseDown)
aiChatButton.sendAction(on: .leftMouseDown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr

PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionNewUser,
frequency: .unique,
frequency: .uniqueByName,
includeAppVersionParameter: true) { [weak self] fired, error in
guard let self, error == nil, fired else { return }
self.defaults.vpnFirstEnabled = PixelKit.pixelLastFireDate(event: NetworkProtectionPixelEvent.networkProtectionNewUser)
Expand Down
8 changes: 8 additions & 0 deletions DuckDuckGo/NewTabPage/NewTabPageActionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,16 @@ extension NewTabPageActionsManager {
self.init(scriptClients: [
NewTabPageConfigurationClient(appearancePreferences: appearancePreferences),
NewTabPageRMFClient(remoteMessageProvider: activeRemoteMessageModel, openURLHandler: openURLHandler),
NewTabPageNextStepsCardsClient(model: HomePage.Models.ContinueSetUpModel(tabOpener: NewTabPageTabOpener())),
NewTabPageFavoritesClient(favoritesModel: NewTabPageFavoritesModel()),
NewTabPagePrivacyStatsClient(model: privacyStatsModel)
])
}
}

struct NewTabPageTabOpener: ContinueSetUpModelTabOpening {
@MainActor
func openTab(_ tab: Tab) {
WindowControllersManager.shared.lastKeyMainWindowController?.mainViewController.tabCollectionViewModel.insertOrAppend(tab: tab, selected: true)
}
}
3 changes: 2 additions & 1 deletion DuckDuckGo/NewTabPage/NewTabPageConfigurationClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ final class NewTabPageConfigurationClient: NewTabPageScriptClient {
return NewTabPageUserScript.NewTabPageConfiguration(
widgets: [
.init(id: .rmf),
.init(id: .nextSteps),
.init(id: .favorites),
.init(id: .privacyStats)
],
Expand Down Expand Up @@ -174,7 +175,7 @@ final class NewTabPageConfigurationClient: NewTabPageScriptClient {
extension NewTabPageUserScript {

enum WidgetId: String, Codable {
case rmf, favorites, privacyStats
case rmf, nextSteps, favorites, privacyStats
}

struct ContextMenuParams: Codable {
Expand Down
11 changes: 10 additions & 1 deletion DuckDuckGo/NewTabPage/NewTabPageWebViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ final class NewTabPageWebViewModel: NSObject {

windowCancellable = webView.publisher(for: \.window)
.map { $0 != nil }
.assign(to: \.isViewOnScreen, on: activeRemoteMessageModel)
.sink { [weak activeRemoteMessageModel] isOnScreen in
activeRemoteMessageModel?.isViewOnScreen = isOnScreen
if isOnScreen {
NotificationCenter.default.post(name: .newTabPageWebViewDidAppear, object: nil)
}
}
}
}

Expand All @@ -61,3 +66,7 @@ extension NewTabPageWebViewModel: WKNavigationDelegate {
navigationAction.request.url == .newtab ? .allow : .cancel
}
}

extension Notification.Name {
static var newTabPageWebViewDidAppear = Notification.Name("newTabPageWebViewDidAppear")
}
Loading

0 comments on commit 6029e64

Please sign in to comment.