Skip to content

Commit

Permalink
Merge branch 'main' into sam/vpn-snooze-initial-support
Browse files Browse the repository at this point in the history
* main:
  Remove unused VPN session utilities (#898)
  Add new deprecated Mac remote message attribute. (#903)
  Resetting all state for the VPN will cancel the tunnel and stop the monitors (#900)
  Add support for skipping sending usage pixels for remote messages (#902)
  Bump Tests/BrowserServicesKitTests/Resources/privacy-reference-tests (#896)
  Removes the listen port from the wireguard client (#901)
  Be explicit when performing developer redirects (#884)
  C-S-S cross origin fixes
  Update C-S-S version (#892)
  Add a debug menu action to reset Remote Messages on macOS (#891)
  Add desktop specific RMF attributes (#883)
  Upload exception message to Sentry (#856)
  Add locale to broken site report (#889)
  Add new subfeature for duckplayer (#885)
  Swiftlint refactoring (#882)
  Remote Messaging Framework for macOS (#876)
  • Loading branch information
samsymons committed Jul 19, 2024
2 parents 14f513b + 6db80af commit 4a27033
Show file tree
Hide file tree
Showing 126 changed files with 4,869 additions and 1,661 deletions.
13 changes: 6 additions & 7 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ disabled_rules:
- line_length
- type_name
- implicit_getter
- function_parameter_count
- trailing_comma
- nesting
- opening_brace
- function_parameter_count
- function_body_length
- file_length
- type_body_length

opt_in_rules:
- file_header
Expand Down Expand Up @@ -40,15 +43,11 @@ analyzer_rules: # Rules run by `swiftlint analyze`
- explicit_self

# Rule Config
cyclomatic_complexity:
ignores_case_statements: true
identifier_name:
min_length: 1
max_length: 1000
file_length:
warning: 1200
error: 1200
type_body_length:
warning: 500
error: 500
large_tuple:
warning: 4
error: 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,48 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BrowserServicesKitTestsUtils"
BuildableName = "BrowserServicesKitTestsUtils"
BlueprintName = "BrowserServicesKitTestsUtils"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "RemoteMessagingTestsUtils"
BuildableName = "RemoteMessagingTestsUtils"
BlueprintName = "RemoteMessagingTestsUtils"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CxxCrashHandler"
BuildableName = "CxxCrashHandler"
BlueprintName = "CxxCrashHandler"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "9c65477457126ab7ad963a32b7f85ce08e6bd1a7",
"version" : "6.0.0"
"revision" : "dc26bfc6e33ad9c79a719b7f21d5ca0564db1859",
"version" : "6.3.0"
}
},
{
Expand Down
33 changes: 31 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ let package = Package(
.library(name: "Common", targets: ["Common"]),
.library(name: "TestUtils", targets: ["TestUtils"]),
.library(name: "DDGSync", targets: ["DDGSync"]),
.library(name: "BrowserServicesKitTestsUtils", targets: ["BrowserServicesKitTestsUtils"]),
.library(name: "Persistence", targets: ["Persistence"]),
.library(name: "Bookmarks", targets: ["Bookmarks"]),
.library(name: "BloomFilterWrapper", targets: ["BloomFilterWrapper"]),
.library(name: "UserScript", targets: ["UserScript"]),
.library(name: "Crashes", targets: ["Crashes"]),
.library(name: "CxxCrashHandler", targets: ["CxxCrashHandler"]),
.library(name: "ContentBlocking", targets: ["ContentBlocking"]),
.library(name: "PrivacyDashboard", targets: ["PrivacyDashboard"]),
.library(name: "Configuration", targets: ["Configuration"]),
.library(name: "Networking", targets: ["Networking"]),
.library(name: "RemoteMessaging", targets: ["RemoteMessaging"]),
.library(name: "RemoteMessagingTestsUtils", targets: ["RemoteMessagingTestsUtils"]),
.library(name: "Navigation", targets: ["Navigation"]),
.library(name: "SyncDataProviders", targets: ["SyncDataProviders"]),
.library(name: "NetworkProtection", targets: ["NetworkProtection"]),
Expand All @@ -44,7 +47,7 @@ let package = Package(
.package(url: "https://github.com/duckduckgo/TrackerRadarKit", exact: "2.1.2"),
.package(url: "https://github.com/duckduckgo/sync_crypto", exact: "0.2.0"),
.package(url: "https://github.com/gumob/PunycodeSwift.git", exact: "2.1.0"),
.package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "6.0.0"),
.package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "6.3.0"),
.package(url: "https://github.com/duckduckgo/privacy-dashboard", exact: "4.2.0"),
.package(url: "https://github.com/httpswift/swifter.git", exact: "1.5.0"),
.package(url: "https://github.com/duckduckgo/bloom_cpp.git", exact: "3.0.0"),
Expand Down Expand Up @@ -76,6 +79,12 @@ let package = Package(
.define("DEBUG", .when(configuration: .debug))
]
),
.target(
name: "BrowserServicesKitTestsUtils",
dependencies: [
"BrowserServicesKit",
]
),
.target(
name: "Persistence",
dependencies: [
Expand Down Expand Up @@ -148,7 +157,12 @@ let package = Package(
name: "Crashes",
dependencies: [
"Common",
"CxxCrashHandler",
]),
.target(
name: "CxxCrashHandler",
dependencies: ["Common"]
),
.target(
name: "DDGSync",
dependencies: [
Expand Down Expand Up @@ -261,9 +275,11 @@ let package = Package(
name: "RemoteMessaging",
dependencies: [
"Common",
"Configuration",
"BrowserServicesKit",
"Networking",
"Persistence",
"Subscription"
],
resources: [
.process("CoreData/RemoteMessaging.xcdatamodeld")
Expand All @@ -272,6 +288,12 @@ let package = Package(
.define("DEBUG", .when(configuration: .debug))
]
),
.target(
name: "RemoteMessagingTestsUtils",
dependencies: [
"RemoteMessaging",
]
),
.target(
name: "SyncDataProviders",
dependencies: [
Expand Down Expand Up @@ -400,7 +422,7 @@ let package = Package(
name: "BrowserServicesKitTests",
dependencies: [
"BrowserServicesKit",
"RemoteMessaging", // Move tests later (lots of test dependencies in BSK)
"BrowserServicesKitTestsUtils",
"SecureStorageTestsUtils",
"TestUtils",
"Subscription"
Expand Down Expand Up @@ -482,10 +504,17 @@ let package = Package(
.testTarget(
name: "RemoteMessagingTests",
dependencies: [
"BrowserServicesKitTestsUtils",
"RemoteMessaging",
"RemoteMessagingTestsUtils",
"TestUtils",
],
resources: [
.copy("Resources/remote-messaging-config-example.json"),
.copy("Resources/remote-messaging-config-malformed.json"),
.copy("Resources/remote-messaging-config-metrics.json"),
.copy("Resources/remote-messaging-config-unsupported-items.json"),
.copy("Resources/remote-messaging-config.json"),
]
),
.testTarget(
Expand Down
3 changes: 0 additions & 3 deletions Plugins/SwiftLintPlugin/SwiftLintPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct SwiftLintPlugin: BuildToolPlugin {
)
}

// swiftlint:disable function_body_length
private func createBuildCommands(
target: String,
inputFiles: [Path],
Expand Down Expand Up @@ -184,8 +183,6 @@ struct SwiftLintPlugin: BuildToolPlugin {

return result
}
// swiftlint:enable function_body_length

}

#if canImport(XcodeProjectPlugin)
Expand Down
25 changes: 25 additions & 0 deletions Sources/Bookmarks/BookmarkUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,31 @@ public struct BookmarkUtils {
return result.compactMap { $0[#keyPath(BookmarkEntity.title)] as? String }
}

public static func numberOfBookmarks(in context: NSManagedObjectContext) -> Int {
let request = BookmarkEntity.fetchRequest()
request.predicate = NSPredicate(
format: "%K == false AND %K == false AND (%K == NO OR %K == nil)",
#keyPath(BookmarkEntity.isFolder),
#keyPath(BookmarkEntity.isPendingDeletion),
#keyPath(BookmarkEntity.isStub), #keyPath(BookmarkEntity.isStub))
return (try? context.count(for: request)) ?? 0
}

public static func numberOfFavorites(for displayMode: FavoritesDisplayMode, in context: NSManagedObjectContext) -> Int {
guard let displayedFavoritesFolder = BookmarkUtils.fetchFavoritesFolder(withUUID: displayMode.displayedFolder.rawValue, in: context) else {
return 0
}

let request = BookmarkEntity.fetchRequest()
request.predicate = NSPredicate(format: "%K CONTAINS %@ AND %K == false AND %K == false AND (%K == NO OR %K == nil)",
#keyPath(BookmarkEntity.favoriteFolders),
displayedFavoritesFolder,
#keyPath(BookmarkEntity.isFolder),
#keyPath(BookmarkEntity.isPendingDeletion),
#keyPath(BookmarkEntity.isStub), #keyPath(BookmarkEntity.isStub))
return (try? context.count(for: request)) ?? 0
}

// MARK: Internal

@discardableResult
Expand Down
3 changes: 0 additions & 3 deletions Sources/BookmarksTestDBBuilder/BookmarksTestDBBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Persistence
import Bookmarks

// swiftlint:disable force_try
// swiftlint:disable function_body_length

@main
struct BookmarksTestDBBuilder {
Expand Down Expand Up @@ -255,7 +254,6 @@ public extension BookmarkEntity {
makeWithModifiedAtConstraints(with: treeNode, rootFolder: rootFolder, favoritesFolders: favoritesFolders, in: context)
}

// swiftlint:disable:next cyclomatic_complexity
@discardableResult static func makeWithModifiedAtConstraints(with treeNode: BookmarkTreeNode, rootFolder: BookmarkEntity, favoritesFolders: [BookmarkEntity], in context: NSManagedObjectContext) -> BookmarkEntity {
var entity: BookmarkEntity!

Expand Down Expand Up @@ -319,4 +317,3 @@ public extension BookmarkEntity {
}

// swiftlint:enable force_try
// swiftlint:enable function_body_length
13 changes: 9 additions & 4 deletions Sources/BookmarksTestsUtils/BookmarkTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import CoreData
import Foundation
import XCTest

// swiftlint:disable cyclomatic_complexity function_body_length
public struct ModifiedAtConstraint {
var check: (Date?) -> Void

Expand Down Expand Up @@ -261,12 +260,19 @@ public struct BookmarkTree {

public extension BookmarkEntity {
@discardableResult
static func make(with treeNode: BookmarkTreeNode, rootFolder: BookmarkEntity, favoritesFolders: [BookmarkEntity], in context: NSManagedObjectContext) -> BookmarkEntity {
static func make(with treeNode: BookmarkTreeNode,
rootFolder: BookmarkEntity,
favoritesFolders: [BookmarkEntity],
in context: NSManagedObjectContext) -> BookmarkEntity {
makeWithModifiedAtConstraints(with: treeNode, rootFolder: rootFolder, favoritesFolders: favoritesFolders, in: context).0
}

@discardableResult
static func makeWithModifiedAtConstraints(with treeNode: BookmarkTreeNode, rootFolder: BookmarkEntity, favoritesFolders: [BookmarkEntity], in context: NSManagedObjectContext) -> (BookmarkEntity, [String: ModifiedAtConstraint]) {
// swiftlint:disable:next cyclomatic_complexity
static func makeWithModifiedAtConstraints(with treeNode: BookmarkTreeNode,
rootFolder: BookmarkEntity,
favoritesFolders: [BookmarkEntity],
in context: NSManagedObjectContext) -> (BookmarkEntity, [String: ModifiedAtConstraint]) {
var entity: BookmarkEntity!

var queues: [[BookmarkTreeNode]] = [[treeNode]]
Expand Down Expand Up @@ -405,4 +411,3 @@ public extension XCTestCase {
}
}
}
// swiftlint:enable cyclomatic_complexity function_body_length
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public class AutofillUserScript: NSObject, UserScript, UserScriptMessageEncrypti
return jsonString
}()

// swiftlint:disable:next cyclomatic_complexity
public func messageHandlerFor(_ messageName: String) -> MessageHandler? {
guard let message = MessageName(rawValue: messageName) else {
os_log("Failed to parse Autofill User Script message: '%{public}s'", log: .userScripts, type: .debug, messageName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ open class ContentBlockerRulesUserScript: NSObject, UserScript {
return temporaryUnprotectedDomains
}

// swiftlint:disable:next cyclomatic_complexity function_body_length
// swiftlint:disable:next cyclomatic_complexity
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
guard let delegate = delegate else { return }
guard delegate.contentBlockerRulesUserScriptShouldProcessTrackers(self) else { return }
Expand Down
2 changes: 0 additions & 2 deletions Sources/BrowserServicesKit/Email/EmailManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public enum EmailManagerRequestDelegateError: Error {
case decodingError
}

// swiftlint:disable function_parameter_count
public protocol EmailManagerRequestDelegate: AnyObject {

var activeTask: URLSessionTask? { get set }
Expand All @@ -106,7 +105,6 @@ public protocol EmailManagerRequestDelegate: AnyObject {
error: EmailKeychainAccessError)

}
// swiftlint:enable function_parameter_count

public extension Notification.Name {
static let emailDidSignIn = Notification.Name("com.duckduckgo.browserServicesKit.EmailDidSignIn")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public struct LinkProtection {
}
}

// swiftlint:disable function_parameter_count
public func requestTrackingLinkRewrite(initiatingURL: URL?,
destinationRequest: URLRequest,
onStartExtracting: () -> Void,
Expand Down Expand Up @@ -147,7 +146,6 @@ public struct LinkProtection {
onLinkRewrite: { onLinkRewrite($0, navigationAction) },
policyDecisionHandler: { policyDecisionHandler($0 ? .allow : .cancel) })
}
// swiftlint:enable function_parameter_count

@MainActor
public func requestTrackingLinkRewrite(initiatingURL: URL?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public enum PrivacyFeature: String {
case sslCertificates
case brokenSiteReportExperiment
case toggleReports
case remoteMessaging
}

/// An abstraction to be implemented by any "subfeature" of a given `PrivacyConfiguration` feature.
Expand Down Expand Up @@ -121,4 +122,5 @@ public enum DuckPlayerSubfeature: String, PrivacySubfeature {
public var parent: PrivacyFeature { .duckPlayer }
case pip
case autoplay
case openInNewTab
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import Foundation
import GRDB
import SecureStorage

// swiftlint:disable file_length

public protocol AutofillDatabaseProvider: SecureStorageDatabaseProvider {

func accounts() throws -> [SecureVaultModels.WebsiteAccount]
Expand Down Expand Up @@ -825,7 +823,6 @@ extension DefaultAutofillDatabaseProvider {

}

// swiftlint:disable:next function_body_length
static func migrateV6(database: Database) throws {

try database.alter(table: SecureVaultModels.Identity.databaseTableName) {
Expand Down Expand Up @@ -1366,5 +1363,3 @@ extension SecureVaultModels.Identity: PersistableRecord, FetchableRecord {
public static var databaseTableName: String = "identities"

}

// swiftlint:enable file_length
Loading

0 comments on commit 4a27033

Please sign in to comment.