mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-12-01 07:40:31 +01:00
The car browser opens plain http pages, such as a home server, with a warning that can be turned off per site
This commit is contained in:
1 parent
91bb654b74
commit
e62a6503cc
5 files changed
+80
-1
No files matched your search
@@ -130,8 +130,13 @@
|
|||||||
</intent>
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Plain http is allowed so the car browser can open a home server on its local address, such as
|
||||||
|
Jellyfin (issue #121). The browser warns on those pages; Gearslip's own requests use https.
|
||||||
|
-->
|
||||||
<application
|
<application
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
|
android:usesCleartextTraffic="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:roundIcon="@mipmap/ic_launcher"
|
android:roundIcon="@mipmap/ic_launcher"
|
||||||
android:label="${appLabel}"
|
android:label="${appLabel}"
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ object BrowserSettings {
|
|||||||
private const val KEY_LISTS_OFF = "adblock_lists_off"
|
private const val KEY_LISTS_OFF = "adblock_lists_off"
|
||||||
private const val KEY_CUSTOM_LISTS = "adblock_custom_lists"
|
private const val KEY_CUSTOM_LISTS = "adblock_custom_lists"
|
||||||
private const val KEY_LAST_CHECK = "adblock_last_check"
|
private const val KEY_LAST_CHECK = "adblock_last_check"
|
||||||
|
private const val KEY_PLAIN_HTTP_OK = "plain_http_ok"
|
||||||
|
|
||||||
/** The lists Gearslip ships a snapshot of, on unless turned off. */
|
/** The lists Gearslip ships a snapshot of, on unless turned off. */
|
||||||
val BUILT_IN_LISTS = listOf(
|
val BUILT_IN_LISTS = listOf(
|
||||||
@@ -66,6 +67,7 @@ object BrowserSettings {
|
|||||||
private val adBlockFlow = MutableStateFlow(true)
|
private val adBlockFlow = MutableStateFlow(true)
|
||||||
private val youTubeFlow = MutableStateFlow(true)
|
private val youTubeFlow = MutableStateFlow(true)
|
||||||
private val listsFlow = MutableStateFlow(BUILT_IN_LISTS)
|
private val listsFlow = MutableStateFlow(BUILT_IN_LISTS)
|
||||||
|
private val plainHttpOkFlow = MutableStateFlow<Set<String>>(emptySet())
|
||||||
|
|
||||||
val bookmarks: StateFlow<List<Bookmark>> = bookmarksFlow
|
val bookmarks: StateFlow<List<Bookmark>> = bookmarksFlow
|
||||||
val searchEngine: StateFlow<SearchEngine> = searchFlow
|
val searchEngine: StateFlow<SearchEngine> = searchFlow
|
||||||
@@ -73,6 +75,9 @@ object BrowserSettings {
|
|||||||
val youTubeAdBlock: StateFlow<Boolean> = youTubeFlow
|
val youTubeAdBlock: StateFlow<Boolean> = youTubeFlow
|
||||||
val filterLists: StateFlow<List<FilterList>> = listsFlow
|
val filterLists: StateFlow<List<FilterList>> = listsFlow
|
||||||
|
|
||||||
|
/** Sites the driver opened over plain http and asked not to be warned about again. */
|
||||||
|
val plainHttpOk: StateFlow<Set<String>> = plainHttpOkFlow
|
||||||
|
|
||||||
@Volatile private var prefs: SharedPreferences? = null
|
@Volatile private var prefs: SharedPreferences? = null
|
||||||
|
|
||||||
/** Loads everything once per process. Safe to call from anywhere that has a context. */
|
/** Loads everything once per process. Safe to call from anywhere that has a context. */
|
||||||
@@ -86,6 +91,7 @@ object BrowserSettings {
|
|||||||
adBlockFlow.value = p.getBoolean(KEY_ADBLOCK, true)
|
adBlockFlow.value = p.getBoolean(KEY_ADBLOCK, true)
|
||||||
youTubeFlow.value = p.getBoolean(KEY_YOUTUBE, true)
|
youTubeFlow.value = p.getBoolean(KEY_YOUTUBE, true)
|
||||||
listsFlow.value = readLists(p)
|
listsFlow.value = readLists(p)
|
||||||
|
plainHttpOkFlow.value = p.getStringSet(KEY_PLAIN_HTTP_OK, emptySet()).orEmpty().toSet()
|
||||||
prefs = p
|
prefs = p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,6 +140,25 @@ object BrowserSettings {
|
|||||||
.filter { it.url.isNotEmpty() }
|
.filter { it.url.isNotEmpty() }
|
||||||
}.getOrDefault(emptyList())
|
}.getOrDefault(emptyList())
|
||||||
|
|
||||||
|
// Plain http
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The site a plain http page belongs to, as the warning remembers it: host and port, since a
|
||||||
|
* home server often runs several apps on one address. Null for anything not plain http.
|
||||||
|
*/
|
||||||
|
fun plainHttpSite(url: String?): String? {
|
||||||
|
if (url == null || !url.startsWith("http://")) return null
|
||||||
|
val uri = runCatching { android.net.Uri.parse(url) }.getOrNull() ?: return null
|
||||||
|
val host = uri.host?.lowercase()?.takeIf { it.isNotEmpty() } ?: return null
|
||||||
|
return if (uri.port > 0) "$host:${uri.port}" else host
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopPlainHttpWarning(site: String) {
|
||||||
|
val set = plainHttpOkFlow.value + site
|
||||||
|
plainHttpOkFlow.value = set
|
||||||
|
prefs?.edit()?.putStringSet(KEY_PLAIN_HTTP_OK, set)?.apply()
|
||||||
|
}
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
|
|
||||||
fun setSearchEngine(engine: SearchEngine) {
|
fun setSearchEngine(engine: SearchEngine) {
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ import androidx.compose.material.icons.filled.Search
|
|||||||
import androidx.compose.material.icons.filled.Refresh
|
import androidx.compose.material.icons.filled.Refresh
|
||||||
import androidx.compose.material.icons.filled.Home
|
import androidx.compose.material.icons.filled.Home
|
||||||
import androidx.compose.material.icons.automirrored.filled.ArrowForward
|
import androidx.compose.material.icons.automirrored.filled.ArrowForward
|
||||||
|
import androidx.compose.material.icons.filled.Close
|
||||||
|
import androidx.compose.material.icons.filled.Warning
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import app.seb3thehacker.gearslip.car.theme.GsButton
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A browser inside the car UI. [content] is a URL, or raw HTML when it does not look like one;
|
* A browser inside the car UI. [content] is a URL, or raw HTML when it does not look like one;
|
||||||
@@ -178,6 +182,7 @@ fun WebApp(content: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!fullscreen && !atStart) PlainHttpBanner(pageUrl)
|
||||||
Box(Modifier.weight(1f).fillMaxSize()) {
|
Box(Modifier.weight(1f).fillMaxSize()) {
|
||||||
AndroidView(
|
AndroidView(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
@@ -313,6 +318,47 @@ fun WebApp(content: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sites whose warning was hidden since Gearslip started, so it doesn't return on every page of them. */
|
||||||
|
private val hiddenForNow = mutableStateOf(emptySet<String>())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A strip under the header while the page came over plain http, which Gearslip opens so a home
|
||||||
|
* server like Jellyfin works on its local address (issue #121). Close hides it for that site until
|
||||||
|
* Gearslip next starts; the other button stops it for that site for good.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun PlainHttpBanner(url: String?) {
|
||||||
|
val site = BrowserSettings.plainHttpSite(url) ?: return
|
||||||
|
val ok by BrowserSettings.plainHttpOk.collectAsState()
|
||||||
|
var hidden by hiddenForNow
|
||||||
|
if (site in ok || site in hidden) return
|
||||||
|
// The same yellow as the debug build's header, which reads as "careful" in both themes.
|
||||||
|
val ink = app.seb3thehacker.gearslip.ui.OnDebugYellow
|
||||||
|
val buttons = app.seb3thehacker.gearslip.car.theme.GsColors(ink.copy(alpha = 0.12f), ink)
|
||||||
|
androidx.compose.material3.Surface(
|
||||||
|
color = app.seb3thehacker.gearslip.ui.DebugYellow,
|
||||||
|
contentColor = ink,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
androidx.compose.foundation.layout.Row(
|
||||||
|
Modifier.padding(start = 16.dp, end = 8.dp, top = 6.dp, bottom = 6.dp),
|
||||||
|
verticalAlignment = androidx.compose.ui.Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
androidx.compose.material3.Icon(androidx.compose.material.icons.Icons.Filled.Warning, null, Modifier.size(24.dp))
|
||||||
|
androidx.compose.material3.Text(
|
||||||
|
stringResource(R.string.web_plain_http),
|
||||||
|
Modifier.weight(1f),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
)
|
||||||
|
GsButton({ BrowserSettings.stopPlainHttpWarning(site) }, colors = buttons) {
|
||||||
|
androidx.compose.material3.Text(stringResource(R.string.web_plain_http_stop))
|
||||||
|
}
|
||||||
|
GsIconButton(androidx.compose.material.icons.Icons.Filled.Close, stringResource(R.string.web_plain_http_hide), { hidden = hidden + site }, colors = buttons)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** The start page: a web address, or a page of HTML Gearslip made itself. */
|
/** The start page: a web address, or a page of HTML Gearslip made itself. */
|
||||||
private fun loadContent(view: WebView, content: String) {
|
private fun loadContent(view: WebView, content: String) {
|
||||||
if (content.startsWith("http://") || content.startsWith("https://")) {
|
if (content.startsWith("http://") || content.startsWith("https://")) {
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ fun HomeScreen(
|
|||||||
|
|
||||||
/** Debug builds wear a yellow header, behind the status bar too, so they're never mistaken for a release install. */
|
/** Debug builds wear a yellow header, behind the status bar too, so they're never mistaken for a release install. */
|
||||||
internal val DebugYellow = Color(0xFFF5C518)
|
internal val DebugYellow = Color(0xFFF5C518)
|
||||||
private val OnDebugYellow = Color(0xFF2A2200)
|
internal val OnDebugYellow = Color(0xFF2A2200)
|
||||||
|
|
||||||
/** The app's name, version and Settings, fixed above Home's scrolling cards. */
|
/** The app's name, version and Settings, fixed above Home's scrolling cards. */
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -733,6 +733,9 @@
|
|||||||
<string name="web_search">Search or type an address</string>
|
<string name="web_search">Search or type an address</string>
|
||||||
<string name="web_forward">Forward</string>
|
<string name="web_forward">Forward</string>
|
||||||
<string name="web_reload">Reload</string>
|
<string name="web_reload">Reload</string>
|
||||||
|
<string name="web_plain_http">This page isn\'t encrypted. Anyone on the same network can see what you send it.</string>
|
||||||
|
<string name="web_plain_http_stop">Don\'t warn for this site</string>
|
||||||
|
<string name="web_plain_http_hide">Hide warning</string>
|
||||||
<string name="web_start_page">Start page</string>
|
<string name="web_start_page">Start page</string>
|
||||||
<string name="web_fullscreen">Full screen</string>
|
<string name="web_fullscreen">Full screen</string>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user