Skip to content

Commit

Permalink
Merge branch 'main' into anh/ppro/pixel-params
Browse files Browse the repository at this point in the history
# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
#	DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
  • Loading branch information
quanganhdo committed Jul 19, 2024
2 parents f4fffb3 + ba71738 commit 9409f36
Show file tree
Hide file tree
Showing 27 changed files with 522 additions and 304 deletions.
5 changes: 4 additions & 1 deletion Core/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public extension OSLog {
case autoconsentLog = "DDG Autoconsent"
case configurationLog = "DDG Configuration"
case syncLog = "DDG Sync"
case duckPlayerLog = "Duck Player"
}

@OSLogWrapper(.generalLog) static var generalLog
Expand All @@ -40,6 +41,7 @@ public extension OSLog {
@OSLogWrapper(.autoconsentLog) static var autoconsentLog
@OSLogWrapper(.configurationLog) static var configurationLog
@OSLogWrapper(.syncLog) static var syncLog
@OSLogWrapper(.duckPlayerLog) static var duckPlayerLog

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// To activate Logging Categories add categories here:
Expand All @@ -50,7 +52,8 @@ public extension OSLog {
.adAttributionLog,
.lifecycleLog,
.configurationLog,
.syncLog
.syncLog,
.duckPlayerLog
]
#endif

Expand Down
3 changes: 2 additions & 1 deletion Core/UserDefaultsPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ public struct UserDefaultsWrapper<T> {

case duckPlayerMode = "com.duckduckgo.ios.duckPlayerMode"
case duckPlayerAskModeOverlayHidden = "com.duckduckgo.ios.duckPlayerAskModeOverlayHidden"

case vpnRedditWorkaroundInstalled = "com.duckduckgo.ios.vpn.workaroundInstalled"


// Debug keys

case debugNewTabPageSectionsEnabledKey = "com.duckduckgo.ios.debug.newTabPageSectionsEnabled"
Expand Down
8 changes: 4 additions & 4 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@
D64648AF2B5993890033090B /* SubscriptionEmailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64648AE2B5993890033090B /* SubscriptionEmailViewModel.swift */; };
D652498E2B515A6A0056B0DE /* SubscriptionSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D652498D2B515A6A0056B0DE /* SubscriptionSettingsViewModel.swift */; };
D65625902C22D307006EF297 /* DuckPlayerURLExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63FF88B2C1B21ED006DE24D /* DuckPlayerURLExtension.swift */; };
D65625922C22D340006EF297 /* YouTubePlayerNavigationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63FF8892C1B21C2006DE24D /* YouTubePlayerNavigationHandler.swift */; };
D65625922C22D340006EF297 /* DuckPlayerNavigationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63FF8892C1B21C2006DE24D /* DuckPlayerNavigationHandler.swift */; };
D65625952C22D382006EF297 /* TabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F159BDA31F0BDB5A00B4A01D /* TabViewController.swift */; };
D65625A12C232F5E006EF297 /* SettingsDuckPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D65625A02C232F5E006EF297 /* SettingsDuckPlayerView.swift */; };
D65CEA702B6AC6C9008A759B /* Subscription.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D65CEA6F2B6AC6C9008A759B /* Subscription.xcassets */; };
Expand Down Expand Up @@ -2516,7 +2516,7 @@
D62EC3C12C248AF800FC9D04 /* DuckNavigationHandling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuckNavigationHandling.swift; sourceTree = "<group>"; };
D63657182A7BAE7C001AF19D /* EmailManagerRequestDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmailManagerRequestDelegate.swift; sourceTree = "<group>"; };
D63677F42BBDB1C300605BA5 /* DaxLogoNavbarTitle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DaxLogoNavbarTitle.swift; sourceTree = "<group>"; };
D63FF8892C1B21C2006DE24D /* YouTubePlayerNavigationHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YouTubePlayerNavigationHandler.swift; sourceTree = "<group>"; };
D63FF8892C1B21C2006DE24D /* DuckPlayerNavigationHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuckPlayerNavigationHandler.swift; sourceTree = "<group>"; };
D63FF88B2C1B21ED006DE24D /* DuckPlayerURLExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuckPlayerURLExtension.swift; sourceTree = "<group>"; };
D63FF8932C1B67E8006DE24D /* YoutubePlayerUserScript.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YoutubePlayerUserScript.swift; sourceTree = "<group>"; };
D63FF8942C1B67E8006DE24D /* YoutubeOverlayUserScript.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YoutubeOverlayUserScript.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4734,7 +4734,7 @@
D63FF8972C1B6A45006DE24D /* DuckPlayer.swift */,
D6037E682C32F2E7009AAEC0 /* DuckPlayerSettings.swift */,
D62EC3C12C248AF800FC9D04 /* DuckNavigationHandling.swift */,
D63FF8892C1B21C2006DE24D /* YouTubePlayerNavigationHandler.swift */,
D63FF8892C1B21C2006DE24D /* DuckPlayerNavigationHandler.swift */,
D63FF88B2C1B21ED006DE24D /* DuckPlayerURLExtension.swift */,
D63FF8942C1B67E8006DE24D /* YoutubeOverlayUserScript.swift */,
D63FF8932C1B67E8006DE24D /* YoutubePlayerUserScript.swift */,
Expand Down Expand Up @@ -6978,7 +6978,7 @@
1EA51376286596A000493C6A /* PrivacyIconLogic.swift in Sources */,
980891A92238504B00313A70 /* UILabelExtension.swift in Sources */,
984D035A24ACCC7D0066CFB8 /* TabViewCell.swift in Sources */,
D65625922C22D340006EF297 /* YouTubePlayerNavigationHandler.swift in Sources */,
D65625922C22D340006EF297 /* DuckPlayerNavigationHandler.swift in Sources */,
31951E8E2823003200CAF535 /* AutofillLoginDetailsHeaderView.swift in Sources */,
F194FAED1F14E2B3009B4DF8 /* UIFontExtension.swift in Sources */,
98F0FC2021FF18E700CE77AB /* AutoClearSettingsViewController.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/AppDependencyProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protocol DependencyProvider {
var networkProtectionKeychainTokenStore: NetworkProtectionKeychainTokenStore { get }
var networkProtectionTunnelController: NetworkProtectionTunnelController { get }
var connectionObserver: ConnectionStatusObserver { get }
var serverInfoObserver: ConnectionServerInfoObserver { get }
var vpnSettings: VPNSettings { get }
}

Expand Down Expand Up @@ -88,6 +89,7 @@ class AppDependencyProvider: DependencyProvider {
let subscriptionAppGroup = Bundle.main.appGroup(bundle: .subs)

let connectionObserver: ConnectionStatusObserver = ConnectionStatusObserverThroughSession()
let serverInfoObserver: ConnectionServerInfoObserver = ConnectionServerInfoObserverThroughSession()
let vpnSettings = VPNSettings(defaults: .networkProtectionGroupDefaults)

init() {
Expand Down
9 changes: 3 additions & 6 deletions DuckDuckGo/DuckPlayer/DuckNavigationHandling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ import WebKit

protocol DuckNavigationHandling {
var referrer: DuckPlayerReferrer { get set }
func handleNavigation(_ navigationAction: WKNavigationAction,
webView: WKWebView,
completion: @escaping (WKNavigationActionPolicy) -> Void)
var duckPlayer: DuckPlayerProtocol { get }
func handleNavigation(_ navigationAction: WKNavigationAction, webView: WKWebView)
func handleURLChange(url: URL?, webView: WKWebView)
func handleDecidePolicyFor(_ navigationAction: WKNavigationAction,
completion: @escaping (WKNavigationActionPolicy) -> Void,
webView: WKWebView)
func handleDecidePolicyFor(_ navigationAction: WKNavigationAction, webView: WKWebView)
func handleGoBack(webView: WKWebView)
func handleReload(webView: WKWebView)
}
Expand Down
87 changes: 77 additions & 10 deletions DuckDuckGo/DuckPlayer/DuckPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,44 @@ import UserScript
import Core

/// Values that the Frontend can use to determine the current state.
struct InitialSetupSettings: Codable {
struct InitialPlayerSettings: Codable {
struct PlayerSettings: Codable {
let pip: PIP
}

struct PIP: Codable {
let status: Status
}

struct Platform: Codable {
let name: String
}

enum Status: String, Codable {
case enabled
case disabled
}

enum Environment: String, Codable {
case development
case production
}

enum Locale: String, Codable {
case en
}

let userValues: UserValues
let settings: PlayerSettings
let platform: Platform
let locale: Locale
}

struct InitialOverlaySettings: Codable {
let userValues: UserValues
}


/// Values that the Frontend can use to determine user settings
public struct UserValues: Codable {
enum CodingKeys: String, CodingKey {
Expand All @@ -61,13 +81,20 @@ public enum DuckPlayerReferrer {
protocol DuckPlayerProtocol {

var settings: DuckPlayerSettingsProtocol { get }
var hostView: UIViewController? { get }

init(settings: DuckPlayerSettingsProtocol)

func setUserValues(params: Any, message: WKScriptMessage) -> Encodable?
func getUserValues(params: Any, message: WKScriptMessage) -> Encodable?
func openVideoInDuckPlayer(url: URL, webView: WKWebView)
func initialSetup(params: Any, message: WKScriptMessage) async -> Encodable?
func openDuckPlayerSettings(params: Any, message: WKScriptMessage) async -> Encodable?
func openDuckPlayerInfo(params: Any, message: WKScriptMessage) async -> Encodable?

func initialSetupPlayer(params: Any, message: WKScriptMessage) async -> Encodable?
func initialSetupOverlay(params: Any, message: WKScriptMessage) async -> Encodable?

func setHostViewController(_ vc: UIViewController)
}

final class DuckPlayer: DuckPlayerProtocol {
Expand All @@ -76,11 +103,18 @@ final class DuckPlayer: DuckPlayerProtocol {
static let commonName = "Duck Player"

private(set) var settings: DuckPlayerSettingsProtocol
private(set) var hostView: UIViewController?

init(settings: DuckPlayerSettingsProtocol = DuckPlayerSettings()) {
self.settings = settings
}

// Sets a presenting VC, so DuckPlayer can present the
// info sheet directly
public func setHostViewController(_ vc: UIViewController) {
hostView = vc
}

// MARK: - Common Message Handlers

public func setUserValues(params: Any, message: WKScriptMessage) -> Encodable? {
Expand All @@ -103,9 +137,35 @@ final class DuckPlayer: DuckPlayerProtocol {
}

@MainActor
public func initialSetup(params: Any, message: WKScriptMessage) async -> Encodable? {
public func initialSetupPlayer(params: Any, message: WKScriptMessage) async -> Encodable? {
let webView = message.webView
return await self.encodedPlayerSettings(with: webView)
}

@MainActor
public func initialSetupOverlay(params: Any, message: WKScriptMessage) async -> Encodable? {
let webView = message.webView
return await self.encodedSettings(with: webView)
return await self.encodedPlayerSettings(with: webView)
}

public func openDuckPlayerSettings(params: Any, message: WKScriptMessage) async -> Encodable? {
NotificationCenter.default.post(
name: .settingsDeepLinkNotification,
object: SettingsViewModel.SettingsDeepLinkSection.duckPlayer,
userInfo: nil
)
return nil
}

@MainActor
public func presentDuckPlayerInfo() {
guard let hostView else { return }
DuckPlayerModalPresenter().presentDuckPlayerFeatureModal(on: hostView)
}

public func openDuckPlayerInfo(params: Any, message: WKScriptMessage) async -> Encodable? {
await presentDuckPlayerInfo()
return nil
}

private func encodeUserValues() -> UserValues {
Expand All @@ -116,14 +176,21 @@ final class DuckPlayer: DuckPlayerProtocol {
}

@MainActor
private func encodedSettings(with webView: WKWebView?) async -> InitialSetupSettings {
private func encodedPlayerSettings(with webView: WKWebView?) async -> InitialPlayerSettings {
let isPiPEnabled = webView?.configuration.allowsPictureInPictureMediaPlayback == true
let pip = InitialSetupSettings.PIP(status: isPiPEnabled ? .enabled : .disabled)

let playerSettings = InitialSetupSettings.PlayerSettings(pip: pip)
let pip = InitialPlayerSettings.PIP(status: isPiPEnabled ? .enabled : .disabled)
let platform = InitialPlayerSettings.Platform(name: "ios")
let environment = InitialPlayerSettings.Environment.development
let locale = InitialPlayerSettings.Locale.en
let playerSettings = InitialPlayerSettings.PlayerSettings(pip: pip)
let userValues = encodeUserValues()

return InitialSetupSettings(userValues: userValues, settings: playerSettings)
return InitialPlayerSettings(userValues: userValues, settings: playerSettings, platform: platform, locale: locale)
}

@MainActor
private func encodedOverlaySettings(with webView: WKWebView?) async -> InitialOverlaySettings {
let userValues = encodeUserValues()
return InitialOverlaySettings(userValues: userValues)
}

}
Loading

0 comments on commit 9409f36

Please sign in to comment.