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

Fix DuckPlayer overlay bug #3348

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions DuckDuckGo/Tab/TabExtensions/DuckPlayerTabExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ extension DuckPlayerTabExtension: NavigationResponder {
// “Watch in YouTube” selected
// when currently displayed content is the Duck Player and loading a YouTube URL, don‘t override it
if didUserSelectWatchInYoutubeFromDuckPlayer(navigationAction, preferences: preferences, videoID: videoID) {
duckPlayer.setNextVideoToOpenOnYoutube()
PixelKit.fire(GeneralPixel.duckPlayerWatchOnYoutube)
return .next

Expand Down
18 changes: 16 additions & 2 deletions DuckDuckGo/YoutubePlayer/DuckPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ public struct UserValues: Codable {
public struct UIUserValues: Codable {
/// If this value is true, we force the FE layer to play in duck player even if the settings is off
let playInDuckPlayer: Bool
let allowFirstVideo: Bool

init(onboardingDecider: DuckPlayerOnboardingDecider) {
init(onboardingDecider: DuckPlayerOnboardingDecider, allowFirstVideo: Bool = false) {
self.playInDuckPlayer = onboardingDecider.shouldOpenFirstVideoOnDuckPlayer
self.allowFirstVideo = allowFirstVideo
}
}

Expand Down Expand Up @@ -308,7 +310,18 @@ final class DuckPlayer {
private func encodedOverlaySettings(with webView: WKWebView?) async -> InitialOverlaySettings {
let userValues = encodeUserValues()

return InitialOverlaySettings(userValues: userValues, ui: UIUserValues(onboardingDecider: onboardingDecider))
/// If the user clicked on "Watch on Youtube" the next vide should open directly on youtube instead of displaying the overlay
var allowFirstVideo = shouldOpenNextVideoOnYoutube

/// Reset the flag for subsequent videos
shouldOpenNextVideoOnYoutube = false
return InitialOverlaySettings(userValues: userValues,
ui: UIUserValues(onboardingDecider: onboardingDecider,
allowFirstVideo: allowFirstVideo))
}

public func setNextVideoToOpenOnYoutube() {
self.shouldOpenNextVideoOnYoutube = true
}

// MARK: - Private
Expand All @@ -326,6 +339,7 @@ final class DuckPlayer {
private var isPiPFeatureEnabled: Bool
private var isAutoplayFeatureEnabled: Bool
private let onboardingDecider: DuckPlayerOnboardingDecider
private var shouldOpenNextVideoOnYoutube: Bool = false

private func bindDuckPlayerModeIfNeeded() {
if isFeatureEnabled {
Expand Down
Loading