feat: remove webchallenge
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
98bbc09cd2
commit
3e7768146d
|
|
@ -51,10 +51,6 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activities.WebChallengeActivity"
|
||||
android:theme="@style/Theme.Revolt" />
|
||||
|
||||
<activity
|
||||
android:name=".activities.InviteActivity"
|
||||
android:theme="@style/Theme.Revolt"
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
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
|
||||
import chat.revolt.api.REVOLT_BASE
|
||||
import chat.revolt.api.buildUserAgent
|
||||
import chat.revolt.databinding.ActivityWebchallengeBinding
|
||||
|
||||
private class WebChallengeClient(val pageLoaded: () -> Unit) : WebViewClient() {
|
||||
@Override
|
||||
override fun onPageFinished(view: WebView, url: String) {
|
||||
super.onPageFinished(view, url)
|
||||
pageLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
class WebChallengeActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityWebchallengeBinding
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityWebchallengeBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
binding.webView.settings.apply {
|
||||
javaScriptEnabled = true
|
||||
domStorageEnabled = true
|
||||
userAgentString = buildUserAgent("WebChallenge")
|
||||
}
|
||||
|
||||
binding.webView.webViewClient = WebChallengeClient {
|
||||
binding.webView.evaluateJavascript(
|
||||
"(function() { return document.getElementById('cf-wrapper') === null; })();"
|
||||
) { result ->
|
||||
if (result == "false") {
|
||||
Log.d(
|
||||
"WebChallenge",
|
||||
"Challenge has been solved or we have been considered human."
|
||||
)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.webView.loadUrl(REVOLT_BASE)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package chat.revolt.api.internals
|
||||
|
||||
import chat.revolt.api.REVOLT_BASE
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
|
||||
object WebChallenge {
|
||||
suspend fun needsCloudflare(): Boolean {
|
||||
RevoltHttp.get(REVOLT_BASE).let {
|
||||
val text = it.bodyAsText()
|
||||
return text.contains(
|
||||
"window._cf_chl_opt"
|
||||
) // FIXME Naive, prone to captcha page changing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,13 +2,10 @@ package chat.revolt.screens
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.NetworkCapabilities
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
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.Arrangement
|
||||
|
|
@ -27,7 +24,6 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
|
|
@ -35,10 +31,8 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.navigation.NavController
|
||||
import chat.revolt.R
|
||||
import chat.revolt.activities.WebChallengeActivity
|
||||
import chat.revolt.api.RevoltAPI
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.internals.WebChallenge
|
||||
import chat.revolt.api.routes.onboard.needsOnboarding
|
||||
import chat.revolt.components.screens.splash.DisconnectedScreen
|
||||
import chat.revolt.persistence.KVStorage
|
||||
|
|
@ -99,13 +93,6 @@ class SplashScreenViewModel @Inject constructor(
|
|||
|
||||
if (!isConnected) return@launch
|
||||
|
||||
val needsCloudflare = WebChallenge.needsCloudflare()
|
||||
|
||||
if (needsCloudflare) {
|
||||
setNavigateTo("webchallenge")
|
||||
return@launch
|
||||
}
|
||||
|
||||
val token = kvStorage.get("sessionToken") ?: return@launch setNavigateTo("login")
|
||||
val id = kvStorage.get("sessionId") ?: ""
|
||||
|
||||
|
|
@ -142,16 +129,6 @@ class SplashScreenViewModel @Inject constructor(
|
|||
|
||||
@Composable
|
||||
fun SplashScreen(navController: NavController, viewModel: SplashScreenViewModel = hiltViewModel()) {
|
||||
val context = LocalContext.current
|
||||
|
||||
val webChallengeActivityResult = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (result.resultCode == 0) {
|
||||
viewModel.checkLoggedInState()
|
||||
}
|
||||
}
|
||||
|
||||
if (!viewModel.isConnected) {
|
||||
DisconnectedScreen(
|
||||
onRetry = {
|
||||
|
|
@ -197,11 +174,6 @@ fun SplashScreen(navController: NavController, viewModel: SplashScreenViewModel
|
|||
}
|
||||
}
|
||||
|
||||
"webchallenge" -> {
|
||||
val intent = Intent(context, WebChallengeActivity::class.java)
|
||||
webChallengeActivityResult.launch(intent)
|
||||
}
|
||||
|
||||
"home" -> {
|
||||
navController.navigate("chat") {
|
||||
popUpTo("splash") {
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<WebView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/webView" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Reference in New Issue