Skip to content

Commit

Permalink
[DuckPlayer] 6 - Init updates and Watch on YouTube (#3066)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1201141132935289/1207777888338886/f
Description:

Updates DuckPlayer initialization requirements
Renames Youtubplayernavhandler to DuckPlayernavhandler
Adds DuckPlayer logging
Opens video on Youtube when you tap "Watch in Youtube" button
Opens video on Youtube player when you tap the "Youtube" logo in the player itself
  • Loading branch information
afterxleep authored Jul 19, 2024
1 parent 6b7dc14 commit 01a1c38
Show file tree
Hide file tree
Showing 17 changed files with 324 additions and 221 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 @@ -830,7 +830,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 @@ -2512,7 +2512,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 @@ -4730,7 +4730,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 @@ -6972,7 +6972,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
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
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
55 changes: 45 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 @@ -67,7 +87,9 @@ protocol DuckPlayerProtocol {
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 initialSetupPlayer(params: Any, message: WKScriptMessage) async -> Encodable?
func initialSetupOverlay(params: Any, message: WKScriptMessage) async -> Encodable?
}

final class DuckPlayer: DuckPlayerProtocol {
Expand Down Expand Up @@ -103,9 +125,15 @@ 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.encodedSettings(with: webView)
return await self.encodedPlayerSettings(with: webView)
}

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

private func encodeUserValues() -> UserValues {
Expand All @@ -116,14 +144,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 01a1c38

Please sign in to comment.