Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DuckPlayer] 6 - Init updates and Watch on YouTube #3066

Merged
merged 37 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
471a5eb
First batch of pixels
afterxleep Jul 4, 2024
b4f5626
Watch From SERP pixel
afterxleep Jul 9, 2024
3494df7
Merge branch 'main' into daniel/duckplayer/5.pixels
afterxleep Jul 9, 2024
70c739e
Update package
afterxleep Jul 9, 2024
5dbb45a
Test fix
afterxleep Jul 9, 2024
593d755
Fix lint issue
afterxleep Jul 9, 2024
a8141ce
Add first launch pixel
afterxleep Jul 10, 2024
29d5d3a
Add Settings Pixels
afterxleep Jul 10, 2024
16d3f98
Settings Pixels
afterxleep Jul 10, 2024
e462866
DuckPlayer from non-SERP
afterxleep Jul 10, 2024
239c8c0
duckPlayerViewFromYoutubeAutomatic
afterxleep Jul 10, 2024
f41a482
Initial Setup Updates
afterxleep Jul 10, 2024
310be79
Settings
afterxleep Jul 10, 2024
d21ce8b
Split Overlay and Player Settings
afterxleep Jul 10, 2024
7c59947
Remove PiP Settings
afterxleep Jul 10, 2024
3c4eee0
Merge branch 'main' into daniel/duckplayer/6.init.updates
afterxleep Jul 10, 2024
a47c7be
Packages
afterxleep Jul 10, 2024
ff9e04f
Handle Watch in Youtube Action
afterxleep Jul 16, 2024
24441f5
Handle DuckPlayer internal links
afterxleep Jul 16, 2024
169d60d
Reset DuckPlayer on launch
afterxleep Jul 17, 2024
81e29d4
Merge branch 'main' into daniel/duckplayer/6.init.updates
afterxleep Jul 17, 2024
c20c430
Fix Watch in DP button
afterxleep Jul 17, 2024
a3748bf
Remove uneeded code
afterxleep Jul 17, 2024
69c5276
Pass tabID to navigation handler
afterxleep Jul 17, 2024
1fccdac
Move DuckPlayer one level up to TabManager
afterxleep Jul 17, 2024
62671f5
Fix Watch in Youtube Action
afterxleep Jul 18, 2024
5e48897
Move completion handlers out of navigation
afterxleep Jul 18, 2024
b06cdff
Updated DuckHandler Tests
afterxleep Jul 19, 2024
5ae8fd2
MOAR tests
afterxleep Jul 19, 2024
a88c7da
Removed unused vars
afterxleep Jul 19, 2024
bee6056
Update comment
afterxleep Jul 19, 2024
181ab0f
Fixed double if
afterxleep Jul 19, 2024
8cf99c6
Cleanup
afterxleep Jul 19, 2024
58c00de
Merge branch 'main' into daniel/duckplayer/6.init.updates
afterxleep Jul 19, 2024
b837c2b
Fix incorrect merge
afterxleep Jul 19, 2024
011d6c2
Tests are now passing
afterxleep Jul 19, 2024
872138e
Remove / from path
afterxleep Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading