Skip to content

Commit

Permalink
Disable PiP if subfeature is off (#2873)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1204099484721401/1207539151557253/f

**Description**:
- Adds PiP subfeature to DuckPlayer remote config
  • Loading branch information
afterxleep authored Jun 20, 2024
1 parent 373c6b4 commit 806fcb2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
17 changes: 13 additions & 4 deletions DuckDuckGo/YoutubePlayer/DuckPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ struct InitialSetupSettings: Codable {
}

struct PIP: Codable {
let status: Status
let state: State
}

enum Status: String, Codable {
enum State: String, Codable {
case enabled
case disabled
}
Expand Down Expand Up @@ -115,6 +115,7 @@ final class DuckPlayer {
) {
self.preferences = preferences
isFeatureEnabled = privacyConfigurationManager.privacyConfig.isEnabled(featureKey: .duckPlayer)
isPiPFeatureEnabled = privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(DuckPlayerSubfeature.pip)
mode = preferences.duckPlayerMode
bindDuckPlayerModeIfNeeded()

Expand Down Expand Up @@ -202,8 +203,15 @@ final class DuckPlayer {

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

// Disable WebView PiP if if the subFeature is off
if !isPiPFeatureEnabled {
webView?.configuration.allowsPictureInPictureMediaPlayback = false
isPiPEnabled = false
}

let pip = InitialSetupSettings.PIP(state: isPiPEnabled ? .enabled : .disabled)

let playerSettings = InitialSetupSettings.PlayerSettings(pip: pip)
let userValues = encodeUserValues()
Expand All @@ -223,6 +231,7 @@ final class DuckPlayer {
}
private var modeCancellable: AnyCancellable?
private var isFeatureEnabledCancellable: AnyCancellable?
private var isPiPFeatureEnabled: Bool

private func bindDuckPlayerModeIfNeeded() {
if isFeatureEnabled {
Expand Down

0 comments on commit 806fcb2

Please sign in to comment.