Skip to content

Commit

Permalink
Merge branch 'main' into dominik/sync-feature-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Dec 20, 2023
2 parents 80f2bb9 + 00e4e18 commit 6dd5f7a
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 80 deletions.
116 changes: 74 additions & 42 deletions DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"branch" : "dominik/sync-feature-flags",
"revision" : "1c8fa640dd55a9a4d4d4acc433c96cb226448eea"
"revision" : "d671accf1bf7097c4e7f5cd55cd1c6dfa005cf92",
"version" : "97.0.0"
}
},
{
Expand Down
6 changes: 4 additions & 2 deletions DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
isSyncInProgressCancellable = syncService.isSyncInProgressPublisher
.filter { $0 }
.asVoid()
.prefix(1)
.sink {
.sink { [weak syncService] in
Pixel.fire(.syncDaily, limitTo: .dailyFirst)
syncService?.syncDailyStats.sendStatsIfNeeded(handler: { params in
Pixel.fire(.syncSuccessRateDaily, withAdditionalParameters: params)
})
}

subscribeSyncQueueToScreenLockedNotifications()
Expand Down
12 changes: 0 additions & 12 deletions DuckDuckGo/Bookmarks/Services/LocalBookmarkStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ final class LocalBookmarkStore: BookmarkStore {
// will return the children of the root folder, as the root folder is an implementation detail of the bookmarks store.
let rootFolder = self.bookmarksRoot(in: context)
let orphanedEntities = BookmarkUtils.fetchOrphanedEntities(context)
if !orphanedEntities.isEmpty {
self.reportOrphanedBookmarksIfNeeded()
}
results = (rootFolder?.childrenArray ?? []) + orphanedEntities
case .favorites:
results = self.favoritesRoot(in: context)?.favoritesArray ?? []
Expand All @@ -300,15 +297,6 @@ final class LocalBookmarkStore: BookmarkStore {
}
}

private func reportOrphanedBookmarksIfNeeded() {
Task { @MainActor in
guard let syncService = NSApp.delegateTyped.syncService, syncService.authState == .inactive else {
return
}
Pixel.fire(.debug(event: .orphanedBookmarksPresent))
}
}

func save(bookmark: Bookmark, parent: BookmarkFolder?, index: Int?, completion: @escaping (Bool, Error?) -> Void) {
applyChangesAndSave(changes: { [weak self] context in
guard let self = self else {
Expand Down
2 changes: 0 additions & 2 deletions DuckDuckGo/Statistics/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ extension Pixel {
case missingParent
case bookmarksSaveFailed
case bookmarksSaveFailedOnImport
case orphanedBookmarksPresent

case bookmarksCouldNotLoadDatabase
case bookmarksCouldNotPrepareDatabase
Expand Down Expand Up @@ -753,7 +752,6 @@ extension Pixel.Event.Debug {
case .missingParent: return "bookmark_missing_parent"
case .bookmarksSaveFailed: return "bookmarks_save_failed"
case .bookmarksSaveFailedOnImport: return "bookmarks_save_failed_on_import"
case .orphanedBookmarksPresent: return "bookmarks_orphans_present"

case .bookmarksCouldNotLoadDatabase: return "bookmarks_could_not_load_database"
case .bookmarksCouldNotPrepareDatabase: return "bookmarks_could_not_prepare_database"
Expand Down
15 changes: 7 additions & 8 deletions DuckDuckGo/Tab/Navigation/ExternalAppSchemeHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ final class ExternalAppSchemeHandler {

extension ExternalAppSchemeHandler: NavigationResponder {

@MainActor
func decidePolicy(for navigationAction: NavigationAction, preferences: inout NavigationPreferences) async -> NavigationActionPolicy? {
// swiftlint:disable:next function_body_length
@MainActor func decidePolicy(for navigationAction: NavigationAction, preferences: inout NavigationPreferences) async -> NavigationActionPolicy? {
let externalUrl = navigationAction.url
// only proceed with non-external-scheme navigations
guard externalUrl.isExternalSchemeLink, let scheme = externalUrl.scheme else {
Expand Down Expand Up @@ -114,19 +114,18 @@ extension ExternalAppSchemeHandler: NavigationResponder {
}

let permissionType = PermissionType.externalScheme(scheme: scheme)
// use domain from the url for user-entered app schemes, otherwise use current website domain
let domain = navigationAction.isUserEnteredUrl ? navigationAction.url.host ?? "" : navigationAction.sourceFrame.securityOrigin.host
permissionModel.permissions([permissionType], requestedForDomain: domain, url: externalUrl) { [workspace, weak self] isGranted in
// Check for cross-origin redirects first, then use domain from the url for user-entered app schemes, then use current website domain
let redirectDomain = navigationAction.redirectHistory?.reversed().first(where: { $0.url.host != navigationAction.url.host })?.url.host
let domain = redirectDomain ?? (navigationAction.isUserEnteredUrl ? navigationAction.url.host ?? "" : navigationAction.sourceFrame.securityOrigin.host)
permissionModel.permissions([permissionType], requestedForDomain: domain, url: externalUrl) { [workspace] isGranted in
if isGranted {
workspace.open(externalUrl)

// if "Always allow" is set and this is the only navigation in the tab: close the tab
if self?.shouldCloseTabOnExternalAppOpen == true, let webView = navigationAction.targetFrame?.webView {
if self.shouldCloseTabOnExternalAppOpen == true, let webView = navigationAction.targetFrame?.webView {
webView.close()
}
}
}

return .cancel
}

Expand Down
18 changes: 17 additions & 1 deletion DuckDuckGo/Tab/View/BrowserTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,30 @@ final class BrowserTabViewController: NSViewController {
tabCollectionViewModel.tabCollection.$tabs
.sink(receiveValue: setDelegate())
.store(in: &cancellables)

tabCollectionViewModel.tabCollection.$tabs
.sink(receiveValue: removeDataBrokerViewIfNecessary())
.store(in: &cancellables)
}

private func subscribeToPinnedTabs() {
pinnedTabsDelegatesCancellable = tabCollectionViewModel.pinnedTabsCollection?.$tabs
.sink(receiveValue: setDelegate())
}

private func removeDataBrokerViewIfNecessary() -> ([Tab]) -> Void {
{ [weak self] (tabs: [Tab]) in
guard let self else { return }
#if DBP
if let dataBrokerProtectionHomeViewController,
!tabs.contains(where: { $0.content == .dataBrokerProtection }) {
dataBrokerProtectionHomeViewController.removeCompletely()
self.dataBrokerProtectionHomeViewController = nil
}
#endif
}
}

private func setDelegate() -> ([Tab]) -> Void {
{ [weak self] (tabs: [Tab]) in
guard let self else { return }
Expand Down Expand Up @@ -431,7 +448,6 @@ final class BrowserTabViewController: NSViewController {
bookmarksViewController?.removeCompletely()
#if DBP
dataBrokerProtectionHomeViewController?.removeCompletely()
dataBrokerProtectionHomeViewController = nil
#endif
if includingWebView {
self.removeWebViewFromHierarchy()
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/Account/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
targets: ["Account"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
.package(path: "../Purchase")
],
targets: [
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
targets: ["DataBrokerProtection"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
.package(path: "../PixelKit"),
.package(path: "../SwiftUIExtensions"),
.package(path: "../XPCHelper")
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/LoginItems/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let package = Package(
.library(name: "NetworkProtectionUI", targets: ["NetworkProtectionUI"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
.package(path: "../XPCHelper"),
.package(path: "../SwiftUIExtensions")
],
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/PixelKit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/Purchase/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/Subscription/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
.package(path: "../Account"),
.package(path: "../Purchase"),
.package(path: "../SwiftUIExtensions"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SwiftUIExtensions/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SyncUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
],
dependencies: [
.package(path: "../SwiftUIExtensions"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SystemExtensionManager/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/XPCHelper/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let package = Package(
.library(name: "XPCHelper", targets: ["XPCHelper"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "95.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "97.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
4 changes: 4 additions & 0 deletions UnitTests/Sync/SyncPreferencesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Combine
import Persistence
import SyncUI
import XCTest
import TestUtils
@testable import BrowserServicesKit
@testable import DDGSync
@testable import DuckDuckGo_Privacy_Browser
Expand Down Expand Up @@ -136,6 +137,7 @@ final class SyncPreferencesTests: XCTestCase {
}

class MockDDGSyncing: DDGSyncing {

let registeredDevices = [RegisteredDevice(id: "1", name: "Device 1", type: "desktop"), RegisteredDevice(id: "2", name: "Device 2", type: "mobile"), RegisteredDevice(id: "3", name: "Device 1", type: "desktop")]
var disconnectCalled = false

Expand All @@ -157,6 +159,8 @@ class MockDDGSyncing: DDGSyncing {

var scheduler: Scheduling

var syncDailyStats = SyncDailyStats(store: MockKeyValueStore())

@Published var isSyncInProgress: Bool

var isSyncInProgressPublisher: AnyPublisher<Bool, Never> {
Expand Down

0 comments on commit 6dd5f7a

Please sign in to comment.