From dd595d952e0076a7a01d086ed2424838dcd985af Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Mon, 23 Oct 2023 12:09:22 +0100 Subject: [PATCH] feat(dashboard): updating feedback form (#533) * new privacy dashboard * exact * lint * released dashboard version --------- Co-authored-by: Shane Osbourne --- Package.resolved | 4 ++-- Package.swift | 2 +- .../PrivacyDashboardController.swift | 6 ++--- .../PrivacyDashboardUserScript.swift | 24 +++++++++++++++---- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Package.resolved b/Package.resolved index faa809b51..f8e42a9d9 100644 --- a/Package.resolved +++ b/Package.resolved @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/privacy-dashboard", "state" : { - "revision" : "51e2b46f413bf3ef18afefad631ca70f2c25ef70", - "version" : "1.4.0" + "revision" : "b4ac92a444e79d5651930482623b9f6dc9265667", + "version" : "2.0.0" } }, { diff --git a/Package.swift b/Package.swift index c9154ad9e..ccc29c9c9 100644 --- a/Package.swift +++ b/Package.swift @@ -37,7 +37,7 @@ let package = Package( .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: "4.40.0"), - .package(url: "https://github.com/duckduckgo/privacy-dashboard", exact: "1.4.0"), + .package(url: "https://github.com/duckduckgo/privacy-dashboard", exact: "2.0.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"), .package(url: "https://github.com/duckduckgo/wireguard-apple", exact: "1.1.1") diff --git a/Sources/PrivacyDashboard/PrivacyDashboardController.swift b/Sources/PrivacyDashboard/PrivacyDashboardController.swift index aefd7452d..41cb6e3eb 100644 --- a/Sources/PrivacyDashboard/PrivacyDashboardController.swift +++ b/Sources/PrivacyDashboard/PrivacyDashboardController.swift @@ -27,7 +27,7 @@ public enum PrivacyDashboardOpenSettingsTarget: String { } public protocol PrivacyDashboardControllerDelegate: AnyObject { - func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didChangeProtectionSwitch isEnabled: Bool) + func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didChangeProtectionSwitch protectionState: ProtectionState) func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didRequestOpenUrlInNewTab url: URL) func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didRequestOpenSettings target: PrivacyDashboardOpenSettingsTarget) @@ -239,8 +239,8 @@ extension PrivacyDashboardController: PrivacyDashboardUserScriptDelegate { delegate?.privacyDashboardController(self, didRequestOpenSettings: settingsTarget) } - func userScript(_ userScript: PrivacyDashboardUserScript, didChangeProtectionStateTo isProtected: Bool) { - delegate?.privacyDashboardController(self, didChangeProtectionSwitch: isProtected) + func userScript(_ userScript: PrivacyDashboardUserScript, didChangeProtectionState protectionState: ProtectionState) { + delegate?.privacyDashboardController(self, didChangeProtectionSwitch: protectionState) } func userScript(_ userScript: PrivacyDashboardUserScript, didRequestOpenUrlInNewTab url: URL) { diff --git a/Sources/PrivacyDashboard/UserScript/PrivacyDashboardUserScript.swift b/Sources/PrivacyDashboard/UserScript/PrivacyDashboardUserScript.swift index d062bf373..77b9c5c5e 100644 --- a/Sources/PrivacyDashboard/UserScript/PrivacyDashboardUserScript.swift +++ b/Sources/PrivacyDashboard/UserScript/PrivacyDashboardUserScript.swift @@ -20,9 +20,10 @@ import Foundation import WebKit import TrackerRadarKit import UserScript +import Common protocol PrivacyDashboardUserScriptDelegate: AnyObject { - func userScript(_ userScript: PrivacyDashboardUserScript, didChangeProtectionStateTo protectionState: Bool) + func userScript(_ userScript: PrivacyDashboardUserScript, didChangeProtectionState protectionState: ProtectionState) func userScript(_ userScript: PrivacyDashboardUserScript, setHeight height: Int) func userScriptDidRequestClosing(_ userScript: PrivacyDashboardUserScript) func userScriptDidRequestShowReportBrokenSite(_ userScript: PrivacyDashboardUserScript) @@ -38,6 +39,20 @@ public enum PrivacyDashboardTheme: String, Encodable { case dark } +public struct ProtectionState: Decodable { + public let isProtected: Bool + public let eventOrigin: EventOrigin + + public struct EventOrigin: Decodable { + public let screen: EventOriginScreen + } + + public enum EventOriginScreen: String, Decodable { + case primaryScreen + case breakageForm + } +} + final class PrivacyDashboardUserScript: NSObject, StaticUserScript { enum MessageNames: String, CaseIterable { @@ -91,12 +106,13 @@ final class PrivacyDashboardUserScript: NSObject, StaticUserScript { // MARK: - JS message handlers private func handleSetProtection(message: WKScriptMessage) { - guard let isProtected = message.body as? Bool else { - assertionFailure("privacyDashboardSetProtection: expected Bool") + + guard let protectionState: ProtectionState = DecodableHelper.decode(from: message.messageBody) else { + assertionFailure("privacyDashboardSetProtection: expected ProtectionState") return } - delegate?.userScript(self, didChangeProtectionStateTo: isProtected) + delegate?.userScript(self, didChangeProtectionState: protectionState) } private func handleSetSize(message: WKScriptMessage) {