fix: race condition due to asynchronous execution
This commit is contained in:
parent
4d3754ef0f
commit
a64486d67d
|
|
@ -2,6 +2,7 @@ package chat.revolt.activities
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
|
@ -36,7 +37,11 @@ class WebChallengeActivity : AppCompatActivity() {
|
|||
binding.webView.evaluateJavascript(
|
||||
"(function() { return document.getElementById('cf-wrapper') != null; })();"
|
||||
) { result ->
|
||||
if (result == "false") { // No challenge
|
||||
if (result == "false") {
|
||||
Log.d(
|
||||
"WebChallenge",
|
||||
"Challenge has been solved or we have been considered human."
|
||||
)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import android.content.Intent
|
|||
import android.net.ConnectivityManager
|
||||
import android.net.NetworkCapabilities
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
|
|
@ -122,6 +124,14 @@ fun SplashScreen(
|
|||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
val webChallengeActivityResult = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (result.resultCode == 0) {
|
||||
viewModel.checkLoggedInState()
|
||||
}
|
||||
}
|
||||
|
||||
if (!viewModel.isConnected) {
|
||||
DisconnectedScreen(
|
||||
onRetry = {
|
||||
|
|
@ -160,13 +170,8 @@ fun SplashScreen(
|
|||
}
|
||||
|
||||
"webchallenge" -> {
|
||||
context.startActivity(
|
||||
Intent(
|
||||
context,
|
||||
WebChallengeActivity::class.java
|
||||
)
|
||||
)
|
||||
viewModel.checkLoggedInState()
|
||||
val intent = Intent(context, WebChallengeActivity::class.java)
|
||||
webChallengeActivityResult.launch(intent)
|
||||
}
|
||||
|
||||
"home" -> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue