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