Skip to content

Commit

Permalink
accept more data from UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Oct 19, 2023
1 parent c833853 commit bc1be2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Sources/PrivacyDashboard/PrivacyDashboardController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit bc1be2a

Please sign in to comment.