Tweak Cloudflare help message in WebView screen

Catches pages like what Shinigami is currently showing.
Also adjusts the banner to make it look more like part of the top AppBar so it
looks less like part of the webpage.
This commit is contained in:
arkon 2023-10-12 22:56:19 -04:00
parent 540fb1bb7c
commit c386d375de
2 changed files with 91 additions and 80 deletions

View File

@ -7,6 +7,7 @@ import android.webkit.WebView
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
@ -14,6 +15,8 @@ import androidx.compose.material.icons.outlined.ArrowBack
import androidx.compose.material.icons.outlined.ArrowForward import androidx.compose.material.icons.outlined.ArrowForward
import androidx.compose.material.icons.outlined.Close import androidx.compose.material.icons.outlined.Close
import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -22,8 +25,10 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.google.accompanist.web.AccompanistWebViewClient import com.google.accompanist.web.AccompanistWebViewClient
import com.google.accompanist.web.LoadingState import com.google.accompanist.web.LoadingState
import com.google.accompanist.web.WebView import com.google.accompanist.web.WebView
@ -72,7 +77,7 @@ fun WebViewScreenContent(
super.onPageFinished(view, url) super.onPageFinished(view, url)
scope.launch { scope.launch {
val html = view.getHtml() val html = view.getHtml()
showCloudflareHelp = "window._cf_chl_opt" in html showCloudflareHelp = "window._cf_chl_opt" in html || "Ray ID is" in html
} }
} }
@ -103,6 +108,7 @@ fun WebViewScreenContent(
Scaffold( Scaffold(
topBar = { topBar = {
Box { Box {
Column {
AppBar( AppBar(
title = state.pageTitle ?: initialTitle, title = state.pageTitle ?: initialTitle,
subtitle = currentUrl, subtitle = currentUrl,
@ -151,6 +157,22 @@ fun WebViewScreenContent(
) )
}, },
) )
if (showCloudflareHelp) {
Surface(
modifier = Modifier.padding(8.dp),
) {
WarningBanner(
textRes = R.string.information_cloudflare_help,
modifier = Modifier
.clip(MaterialTheme.shapes.small)
.clickable {
uriHandler.openUri("https://tachiyomi.org/docs/guides/troubleshooting/#cloudflare")
},
)
}
}
}
when (val loadingState = state.loadingState) { when (val loadingState = state.loadingState) {
is LoadingState.Initializing -> LinearProgressIndicator( is LoadingState.Initializing -> LinearProgressIndicator(
modifier = Modifier modifier = Modifier
@ -168,21 +190,11 @@ fun WebViewScreenContent(
} }
}, },
) { contentPadding -> ) { contentPadding ->
Column(
modifier = Modifier.padding(contentPadding),
) {
if (showCloudflareHelp) {
WarningBanner(
textRes = R.string.information_cloudflare_help,
modifier = Modifier.clickable {
uriHandler.openUri("https://tachiyomi.org/docs/guides/troubleshooting/#cloudflare")
},
)
}
WebView( WebView(
state = state, state = state,
modifier = Modifier.weight(1f), modifier = Modifier
.fillMaxSize()
.padding(contentPadding),
navigator = navigator, navigator = navigator,
onCreated = { webView -> onCreated = { webView ->
webView.setDefaultSettings() webView.setDefaultSettings()
@ -201,5 +213,4 @@ fun WebViewScreenContent(
client = webClient, client = webClient,
) )
} }
}
} }