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 ANR caused by Duck Player #5169

Merged
merged 1 commit into from
Oct 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.duckduckgo.privacy.config.api.TrackingParameters
import com.duckduckgo.subscriptions.api.Subscriptions
import java.net.URISyntaxException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import timber.log.Timber

Expand Down Expand Up @@ -92,9 +91,7 @@ class SpecialUrlDetectorImpl(

val uri = uriString.toUri()

val willNavigateToDuckPlayerDeferred = scope.async(dispatcherProvider.io()) { duckPlayer.willNavigateToDuckPlayer(uri) }

val willNavigateToDuckPlayer = runBlocking(dispatcherProvider.io()) { willNavigateToDuckPlayerDeferred.await() }
val willNavigateToDuckPlayer = runBlocking(dispatcherProvider.io()) { duckPlayer.willNavigateToDuckPlayer(uri) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


if (willNavigateToDuckPlayer) {
return UrlType.ShouldLaunchDuckPlayerLink(url = uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class DuckPlayerJSHelper @Inject constructor(
}
}

private suspend fun getInitialSetup(featureName: String, method: String, id: String): JsCallbackData {
private fun getInitialSetup(featureName: String, method: String, id: String): JsCallbackData {
val userValues = duckPlayer.getUserPreferences()
val privatePlayerMode = if (duckPlayer.getDuckPlayerState() == ENABLED) userValues.privatePlayerMode else PrivatePlayerMode.Disabled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface DuckPlayer {
*
* @return The current state of the DuckPlayer as a DuckPlayerState enum.
*/
suspend fun getDuckPlayerState(): DuckPlayerState
fun getDuckPlayerState(): DuckPlayerState

/**
* Sends a pixel with the given name and data.
Expand All @@ -65,7 +65,7 @@ interface DuckPlayer {
*
* @return The user values.
*/
suspend fun getUserPreferences(): UserPreferences
fun getUserPreferences(): UserPreferences

/**
* Checks if the DuckPlayer overlay should be hidden after navigating back from Duck Player
Expand Down Expand Up @@ -105,7 +105,7 @@ interface DuckPlayer {
* @param uri The YouTube no-cookie URI.
* @return The DuckPlayer URI.
*/
suspend fun createDuckPlayerUriFromYoutubeNoCookie(uri: Uri): String?
fun createDuckPlayerUriFromYoutubeNoCookie(uri: Uri): String?

/**
* Checks if a string is a DuckPlayer URI.
Expand All @@ -120,7 +120,7 @@ interface DuckPlayer {
* @param uri The DuckPlayer URI.
* @return The YouTube URI.
*/
suspend fun createYoutubeWatchUrlFromDuckPlayer(uri: Uri): String?
fun createYoutubeWatchUrlFromDuckPlayer(uri: Uri): String?

/**
* Checks if a URI is a simulated YouTube no-cookie URI.
Expand All @@ -136,7 +136,7 @@ interface DuckPlayer {
* @param uri The URI to check.
* @return True if the URI is a YouTube no-cookie URI, false otherwise.
*/
suspend fun isYoutubeWatchUrl(uri: Uri): Boolean
fun isYoutubeWatchUrl(uri: Uri): Boolean

/**
* Checks if a URI is a YouTube URL.
Expand Down Expand Up @@ -184,7 +184,7 @@ interface DuckPlayer {
destinationUrl: Uri,
): Boolean

suspend fun shouldOpenDuckPlayerInNewTab(): OpenDuckPlayerInNewTab
fun shouldOpenDuckPlayerInNewTab(): OpenDuckPlayerInNewTab

fun observeShouldOpenInNewTab(): Flow<OpenDuckPlayerInNewTab>

Expand Down
Loading
Loading