Skip to content

Commit

Permalink
[DuckPlayer] 20. OverlayInteracted (#3234)
Browse files Browse the repository at this point in the history
**Description**:
- Implement/Fix `overlayInteracted` mode.

<!--
  • Loading branch information
afterxleep authored Aug 16, 2024
1 parent 880013d commit 7641316
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 24 deletions.
2 changes: 2 additions & 0 deletions DuckDuckGo/AppUserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ public class AppUserDefaults: AppSettings {
}
set {
userDefaults?.set(newValue.stringValue, forKey: Keys.duckPlayerMode)
// Reset Hidden overlay setting when changing Mode
userDefaults?.set(false, forKey: Keys.duckPlayerAskModeOverlayHidden)
NotificationCenter.default.post(name: AppUserDefaults.Notifications.duckPlayerSettingsUpdated,
object: duckPlayerMode)
}
Expand Down
15 changes: 2 additions & 13 deletions DuckDuckGo/DuckPlayer/DuckPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ struct InitialPlayerSettings: Codable {
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 Down Expand Up @@ -148,7 +143,7 @@ final class DuckPlayer: DuckPlayerProtocol {

private func updateSettings(userValues: UserValues) async {
settings.setMode(userValues.duckPlayerMode)
settings.setOverlayHidden(userValues.askModeOverlayHidden)
settings.setAskModeOverlayHidden(userValues.askModeOverlayHidden)
}

public func getUserValues(params: Any, message: WKScriptMessage) -> Encodable? {
Expand Down Expand Up @@ -210,13 +205,7 @@ final class DuckPlayer: DuckPlayerProtocol {
let userValues = encodeUserValues()
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)
}


// Accessing WKMessage needs main thread
@MainActor
private func firePixels(message: WKScriptMessage, userValues: UserValues) {
Expand Down
9 changes: 3 additions & 6 deletions DuckDuckGo/DuckPlayer/DuckPlayerSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protocol DuckPlayerSettingsProtocol: AnyObject {
init(appSettings: AppSettings, privacyConfigManager: PrivacyConfigurationManaging)

func setMode(_ mode: DuckPlayerMode)
func setOverlayHidden(_ overlayHidden: Bool)
func setAskModeOverlayHidden(_ overlayHidden: Bool)
func triggerNotification()
}

Expand Down Expand Up @@ -125,17 +125,14 @@ final class DuckPlayerSettings: DuckPlayerSettingsProtocol {
}
}

var overlayHidden: Bool {
var askModeOverlayHidden: Bool {
if isFeatureEnabled {
return appSettings.duckPlayerAskModeOverlayHidden
} else {
return false
}
}

@UserDefaultsWrapper(key: .duckPlayerAskModeOverlayHidden, defaultValue: false)
var askModeOverlayHidden: Bool

private func registerConfigPublisher() {
isFeatureEnabledCancellable = privacyConfigManager.updatesPublisher
.map { [weak privacyConfigManager] in
Expand All @@ -161,7 +158,7 @@ final class DuckPlayerSettings: DuckPlayerSettingsProtocol {
}
}

func setOverlayHidden(_ overlayHidden: Bool) {
func setAskModeOverlayHidden(_ overlayHidden: Bool) {
if overlayHidden != appSettings.duckPlayerAskModeOverlayHidden {
appSettings.duckPlayerAskModeOverlayHidden = overlayHidden
triggerNotification()
Expand Down
5 changes: 1 addition & 4 deletions DuckDuckGo/DuckPlayer/YoutubeOverlayUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ extension YoutubeOverlayUserScript {
case "play.use":
Pixel.fire(pixel: Pixel.Event.duckPlayerViewFromYoutubeViaMainOverlay, debounce: 2)
duckPlayerStorage.userInteractedWithDuckPlayer = true

case "play.use.thumbnail":
Pixel.fire(pixel: Pixel.Event.duckPlayerViewFromYoutubeViaHoverButton, debounce: 2)


case "play.do_not_use":
Pixel.fire(pixel: Pixel.Event.duckPlayerOverlayYoutubeWatchHere, debounce: 2)
duckPlayerStorage.userInteractedWithDuckPlayer = true
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGoTests/DuckPlayerMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ final class MockDuckPlayerSettings: DuckPlayerSettingsProtocol {
self.mode = mode
}

func setOverlayHidden(_ overlayHidden: Bool) {
func setAskModeOverlayHidden(_ overlayHidden: Bool) {
self.askModeOverlayHidden = overlayHidden
}

Expand Down

0 comments on commit 7641316

Please sign in to comment.