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] 7- Open Settings #3110

Merged
merged 49 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 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
fa616f4
Open Settings and OpenInfo Mesasges
afterxleep Jul 17, 2024
489fd5e
Open DuckPlayer Settings
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
a14d59c
Merge branch 'daniel/duckplayer/6.init.updates' into daniel/duckplaye…
afterxleep Jul 19, 2024
5ae8fd2
MOAR tests
afterxleep Jul 19, 2024
368972f
Merge branch 'daniel/duckplayer/6.init.updates' into daniel/duckplaye…
afterxleep Jul 19, 2024
c06830e
Enable Info Button
afterxleep Jul 19, 2024
a88c7da
Removed unused vars
afterxleep Jul 19, 2024
bee6056
Update comment
afterxleep Jul 19, 2024
ffa5fa2
Merge branch 'daniel/duckplayer/6.init.updates' into daniel/duckplaye…
afterxleep Jul 19, 2024
181ab0f
Fixed double if
afterxleep Jul 19, 2024
8cf99c6
Cleanup
afterxleep Jul 19, 2024
ca17840
Merge branch 'daniel/duckplayer/6.init.updates' into daniel/duckplaye…
afterxleep Jul 19, 2024
58c00de
Merge branch 'main' into daniel/duckplayer/6.init.updates
afterxleep Jul 19, 2024
9197f2e
Merge branch 'daniel/duckplayer/6.init.updates' into daniel/duckplaye…
afterxleep Jul 19, 2024
b837c2b
Fix incorrect merge
afterxleep Jul 19, 2024
563f75a
Merge branch 'daniel/duckplayer/6.init.updates' into daniel/duckplaye…
afterxleep Jul 19, 2024
011d6c2
Tests are now passing
afterxleep Jul 19, 2024
872138e
Remove / from path
afterxleep Jul 19, 2024
6963279
Merge branch 'daniel/duckplayer/6.init.updates' into daniel/duckplaye…
afterxleep Jul 19, 2024
0bd9aff
Update tests
afterxleep Jul 19, 2024
8034629
Merge remote-tracking branch 'origin/main' into daniel/duckplayer/7.s…
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
32 changes: 32 additions & 0 deletions DuckDuckGo/DuckPlayer/DuckPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,20 @@ public enum DuckPlayerReferrer {
protocol DuckPlayerProtocol {

var settings: DuckPlayerSettingsProtocol { get }
var hostView: UIViewController? { get }

init(settings: DuckPlayerSettingsProtocol)

func setUserValues(params: Any, message: WKScriptMessage) -> Encodable?
func getUserValues(params: Any, message: WKScriptMessage) -> Encodable?
func openVideoInDuckPlayer(url: URL, webView: WKWebView)
func openDuckPlayerSettings(params: Any, message: WKScriptMessage) async -> Encodable?
func openDuckPlayerInfo(params: Any, message: WKScriptMessage) async -> Encodable?

func initialSetupPlayer(params: Any, message: WKScriptMessage) async -> Encodable?
func initialSetupOverlay(params: Any, message: WKScriptMessage) async -> Encodable?

func setHostViewController(_ vc: UIViewController)
}

final class DuckPlayer: DuckPlayerProtocol {
Expand All @@ -98,11 +103,18 @@ final class DuckPlayer: DuckPlayerProtocol {
static let commonName = "Duck Player"

private(set) var settings: DuckPlayerSettingsProtocol
private(set) var hostView: UIViewController?

init(settings: DuckPlayerSettingsProtocol = DuckPlayerSettings()) {
self.settings = settings
}

// Sets a presenting VC, so DuckPlayer can present the
// info sheet directly
public func setHostViewController(_ vc: UIViewController) {
hostView = vc
}

// MARK: - Common Message Handlers

public func setUserValues(params: Any, message: WKScriptMessage) -> Encodable? {
Expand Down Expand Up @@ -135,6 +147,26 @@ final class DuckPlayer: DuckPlayerProtocol {
let webView = message.webView
return await self.encodedPlayerSettings(with: webView)
}

public func openDuckPlayerSettings(params: Any, message: WKScriptMessage) async -> Encodable? {
NotificationCenter.default.post(
name: .settingsDeepLinkNotification,
object: SettingsViewModel.SettingsDeepLinkSection.duckPlayer,
userInfo: nil
)
return nil
}

@MainActor
public func presentDuckPlayerInfo() {
guard let hostView else { return }
DuckPlayerModalPresenter().presentDuckPlayerFeatureModal(on: hostView)
}

public func openDuckPlayerInfo(params: Any, message: WKScriptMessage) async -> Encodable? {
await presentDuckPlayerInfo()
return nil
}

private func encodeUserValues() -> UserValues {
UserValues(
Expand Down
6 changes: 6 additions & 0 deletions DuckDuckGo/DuckPlayer/YoutubePlayerUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ final class YoutubePlayerUserScript: NSObject, Subfeature {
static let setUserValues = "setUserValues"
static let getUserValues = "getUserValues"
static let initialSetup = "initialSetup"
static let openSettings = "openSettings"
static let openInfo = "openInfo"
}

init(duckPlayer: DuckPlayerProtocol) {
Expand Down Expand Up @@ -73,6 +75,10 @@ final class YoutubePlayerUserScript: NSObject, Subfeature {
return duckPlayer.setUserValues
case Handlers.initialSetup:
return duckPlayer.initialSetupPlayer
case Handlers.openSettings:
return duckPlayer.openDuckPlayerSettings
case Handlers.openInfo:
return duckPlayer.openDuckPlayerInfo
default:
assertionFailure("YoutubePlayerUserScript: Failed to parse User Script message: \(methodName)")
return nil
Expand Down
19 changes: 19 additions & 0 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class MainViewController: UIViewController {
private var favoritesDisplayModeCancellable: AnyCancellable?
private var emailCancellables = Set<AnyCancellable>()
private var urlInterceptorCancellables = Set<AnyCancellable>()
private var settingsDeepLinkcancellables = Set<AnyCancellable>()

#if NETWORK_PROTECTION
private let tunnelDefaults = UserDefaults.networkProtectionGroupDefaults
Expand Down Expand Up @@ -261,6 +262,7 @@ class MainViewController: UIViewController {
addLaunchTabNotificationObserver()
subscribeToEmailProtectionStatusNotifications()
subscribeToURLInterceptorNotifications()
subscribeToSettingsDeeplinkNotifications()

#if NETWORK_PROTECTION
subscribeToNetworkProtectionEvents()
Expand Down Expand Up @@ -1349,6 +1351,23 @@ class MainViewController: UIViewController {
}
.store(in: &urlInterceptorCancellables)
}

private func subscribeToSettingsDeeplinkNotifications() {
NotificationCenter.default.publisher(for: .settingsDeepLinkNotification)
.receive(on: DispatchQueue.main)
.sink { [weak self] notification in
switch notification.object as? SettingsViewModel.SettingsDeepLinkSection {

case .duckPlayer:
let deepLinkTarget: SettingsViewModel.SettingsDeepLinkSection
deepLinkTarget = .duckPlayer
self?.launchSettings(deepLinkTarget: deepLinkTarget)
default:
return
}
}
.store(in: &settingsDeepLinkcancellables)
}

#if NETWORK_PROTECTION
private func subscribeToNetworkProtectionEvents() {
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/SettingsRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ struct SettingsRootView: View {
SubscriptionContainerViewFactory.makeSubscribeFlow(origin: origin,
navigationCoordinator: subscriptionNavigationCoordinator,
subscriptionManager: AppDependencyProvider.shared.subscriptionManager)
case .duckPlayer:
SettingsDuckPlayerView().environmentObject(viewModel)
default:
EmptyView()
}
Expand Down
7 changes: 7 additions & 0 deletions DuckDuckGo/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ extension SettingsViewModel {
case dbp
case itr
case subscriptionFlow(origin: String? = nil)
case duckPlayer
// Add other cases as needed

var id: String {
Expand All @@ -642,6 +643,7 @@ extension SettingsViewModel {
case .dbp: return "dbp"
case .itr: return "itr"
case .subscriptionFlow: return "subscriptionFlow"
case .duckPlayer: return "duckPlayer"
// Ensure all cases are covered
}
}
Expand Down Expand Up @@ -791,3 +793,8 @@ extension SettingsViewModel {
}

}

// Deeplink notification handling
extension NSNotification.Name {
static let settingsDeepLinkNotification: NSNotification.Name = Notification.Name(rawValue: "com.duckduckgo.notification.settingsDeepLink")
}
12 changes: 12 additions & 0 deletions DuckDuckGoTests/DuckPlayerMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ final class MockDuckPlayerSettings: DuckPlayerSettingsProtocol {
}

final class MockDuckPlayer: DuckPlayerProtocol {
var hostView: UIViewController?

func openDuckPlayerSettings(params: Any, message: WKScriptMessage) async -> (any Encodable)? {
nil
}

func openDuckPlayerInfo(params: Any, message: WKScriptMessage) async -> (any Encodable)? {
nil
}

func setHostViewController(_ vc: UIViewController) {}

func initialSetupPlayer(params: Any, message: WKScriptMessage) async -> (any Encodable)? {
nil
}
Expand Down
Loading