Skip to content

Commit

Permalink
Switch YoutubeOverlayUserScript to calling initialSetup (#2947)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1207727405694383/f
Tech Design URL:
CC: @shakyShane @Bunn 

**Description**:

Updates YoutubeOverlayUserScript to call initialSetup on C-S-S rather
than getUserValues. This will allow extending the data currently passed
on init beyond userValues

The getUserValues method will not be deprecated as it can still be used
to fetch only userValues if needed.


**Steps to test this PR**:
1. Run a local build
2. Set Duck Player Settings to “Show Option to Use Duck Player..."
3. Access a YouTube video (e.g.
https://www.youtube.com/watch?v=USLZJ5FTr-Y)
4. Check that the Duck Player overlay appears on top of the video
5. Set Duck Player Settings to another setting (i.e. “Always open…”
6. Load video again
7. Check that overlay does not appear and video playback follows the
setting on step 5

<!—
Tagging instructions
If this PR isn't ready to be merged for whatever reason it should be
marked with the `DO NOT MERGE` label (particularly if it's a draft)
If it's pending Product Review/PFR, please add the `Pending Product
Review` label.

If at any point it isn't actively being worked on/ready for
review/otherwise moving forward (besides the above PR/PFR exception)
strongly consider closing it (or not opening it in the first place). If
you decide not to close it, make sure it's labelled to make it clear the
PRs state and comment with more information.
—>

**Definition of Done**:

* [ ] Does this PR satisfy our [Definition of
Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)?

—
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
  • Loading branch information
mgurgel authored Jul 8, 2024
1 parent 9bcbf83 commit ed078c5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13228,7 +13228,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 167.0.1;
version = 168.0.0;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "0746af01b77d39a1e037bea93b46591534a13b5c",
"version" : "167.0.1"
"revision" : "0d59b3af262534d782c74516da8d766d1b721939",
"version" : "168.0.0"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "7ac68ae3bc052fa59adbc1ba8fd5cb5849a6bc99",
"version" : "5.25.0"
"revision" : "9c65477457126ab7ad963a32b7f85ce08e6bd1a7",
"version" : "6.0.0"
}
},
{
Expand Down Expand Up @@ -75,7 +75,7 @@
{
"identity" : "lottie-spm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/airbnb/lottie-spm",
"location" : "https://github.com/airbnb/lottie-spm.git",
"state" : {
"revision" : "1d29eccc24cc8b75bff9f6804155112c0ffc9605",
"version" : "4.4.3"
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/YoutubePlayer/DuckPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ struct InitialSetupSettings: Codable {
let settings: PlayerSettings
}

// Values that the YouTube Overlays can use to determine the current state
struct OverlaysInitialSettings: Codable {
let userValues: UserValues
}

/// Values that the Frontend can use to determine user settings
public struct UserValues: Codable {
enum CodingKeys: String, CodingKey {
Expand Down
18 changes: 18 additions & 0 deletions DuckDuckGo/YoutubePlayer/YoutubeOverlayUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ final class YoutubeOverlayUserScript: NSObject, Subfeature {
// MARK: - MessageNames

enum MessageNames: String, CaseIterable {
case initialSetup
case setUserValues
case getUserValues
case openDuckPlayer
Expand All @@ -82,6 +83,8 @@ final class YoutubeOverlayUserScript: NSObject, Subfeature {
return DuckPlayer.shared.handleSetUserValuesMessage(from: origin)
case .getUserValues:
return DuckPlayer.shared.handleGetUserValues
case .initialSetup:
return handleInitialSetup
case .openDuckPlayer:
return handleOpenDuckPlayer
case .sendDuckPlayerPixel:
Expand Down Expand Up @@ -116,6 +119,21 @@ final class YoutubeOverlayUserScript: NSObject, Subfeature {
return nil
}

private func handleInitialSetup(params: Any, message: UserScriptMessage) -> Encodable? {
encodeInitialSetup()
}

private func encodeInitialSetup() -> OverlaysInitialSettings {
let userValues = UserValues(
duckPlayerMode: duckPlayerPreferences.duckPlayerMode,
overlayInteracted: duckPlayerPreferences.youtubeOverlayInteracted
)

return OverlaysInitialSettings(
userValues: userValues
)
}

// MARK: - UserValuesNotification

struct UserValuesNotification: Encodable {
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
targets: ["DataBrokerProtection"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "167.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "168.0.0"),
.package(path: "../SwiftUIExtensions"),
.package(path: "../XPCHelper"),
],
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let package = Package(
.library(name: "VPNAppLauncher", targets: ["VPNAppLauncher"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "167.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "168.0.0"),
.package(url: "https://github.com/airbnb/lottie-spm", exact: "4.4.3"),
.package(path: "../AppLauncher"),
.package(path: "../UDSHelper"),
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SubscriptionUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
targets: ["SubscriptionUI"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "167.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "168.0.0"),
.package(path: "../SwiftUIExtensions")
],
targets: [
Expand Down

0 comments on commit ed078c5

Please sign in to comment.