Oidc: Fallback to external browser instead of using Webview (#4808)
* Oidc: Fallback to external browser instead of using Webview * Update screenshots --------- Co-authored-by: ElementBot <android@element.io>
This commit is contained in:
@@ -26,6 +26,7 @@ import com.bumble.appyx.navmodel.backstack.operation.push
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedInject
|
||||
import io.element.android.anvilannotations.ContributesNode
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.features.securebackup.impl.reset.password.ResetIdentityPasswordNode
|
||||
import io.element.android.features.securebackup.impl.reset.root.ResetIdentityRootNode
|
||||
import io.element.android.libraries.androidutils.browser.openUrlInChromeCustomTab
|
||||
@@ -37,7 +38,6 @@ import io.element.android.libraries.designsystem.components.ProgressDialog
|
||||
import io.element.android.libraries.di.SessionScope
|
||||
import io.element.android.libraries.matrix.api.encryption.IdentityOidcResetHandle
|
||||
import io.element.android.libraries.matrix.api.encryption.IdentityPasswordResetHandle
|
||||
import io.element.android.libraries.oidc.api.OidcEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
@@ -51,7 +51,6 @@ class ResetIdentityFlowNode @AssistedInject constructor(
|
||||
@Assisted plugins: List<Plugin>,
|
||||
private val resetIdentityFlowManager: ResetIdentityFlowManager,
|
||||
private val coroutineScope: CoroutineScope,
|
||||
private val oidcEntryPoint: OidcEntryPoint,
|
||||
) : BaseFlowNode<ResetIdentityFlowNode.NavTarget>(
|
||||
backstack = BackStack(initialElement = NavTarget.Root, savedStateMap = buildContext.savedStateMap),
|
||||
buildContext = buildContext,
|
||||
@@ -67,12 +66,10 @@ class ResetIdentityFlowNode @AssistedInject constructor(
|
||||
|
||||
@Parcelize
|
||||
data object ResetPassword : NavTarget
|
||||
|
||||
@Parcelize
|
||||
data class ResetOidc(val url: String) : NavTarget
|
||||
}
|
||||
|
||||
private lateinit var activity: Activity
|
||||
private var darkTheme: Boolean = false
|
||||
private var resetJob: Job? = null
|
||||
|
||||
override fun onBuilt() {
|
||||
@@ -80,7 +77,7 @@ class ResetIdentityFlowNode @AssistedInject constructor(
|
||||
|
||||
lifecycle.addObserver(object : DefaultLifecycleObserver {
|
||||
override fun onStart(owner: LifecycleOwner) {
|
||||
// If the custom tab was opened, we need to cancel the reset job
|
||||
// If the custom tab / Web browser was opened, we need to cancel the reset job
|
||||
// when we come back to the node if the reset wasn't successful
|
||||
coroutineScope.launch {
|
||||
cancelResetJob()
|
||||
@@ -115,9 +112,6 @@ class ResetIdentityFlowNode @AssistedInject constructor(
|
||||
listOf(ResetIdentityPasswordNode.Inputs(handle))
|
||||
)
|
||||
}
|
||||
is NavTarget.ResetOidc -> {
|
||||
oidcEntryPoint.createFallbackWebViewNode(this, buildContext, navTarget.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,11 +129,7 @@ class ResetIdentityFlowNode @AssistedInject constructor(
|
||||
Timber.d("No reset handle return, the reset is done.")
|
||||
}
|
||||
is IdentityOidcResetHandle -> {
|
||||
if (oidcEntryPoint.canUseCustomTab()) {
|
||||
activity.openUrlInChromeCustomTab(null, false, handle.url)
|
||||
} else {
|
||||
backstack.push(NavTarget.ResetOidc(handle.url))
|
||||
}
|
||||
activity.openUrlInChromeCustomTab(null, darkTheme, handle.url)
|
||||
resetJob = launch { handle.resetOidc() }
|
||||
}
|
||||
is IdentityPasswordResetHandle -> backstack.push(NavTarget.ResetPassword)
|
||||
@@ -162,7 +152,7 @@ class ResetIdentityFlowNode @AssistedInject constructor(
|
||||
if (!this::activity.isInitialized) {
|
||||
activity = requireNotNull(LocalActivity.current)
|
||||
}
|
||||
|
||||
darkTheme = !ElementTheme.isLightTheme
|
||||
val startResetState by resetIdentityFlowManager.currentHandleFlow.collectAsState()
|
||||
if (startResetState.isLoading()) {
|
||||
ProgressDialog(
|
||||
|
||||
Reference in New Issue
Block a user