diff --git a/gearslip/src/main/AndroidManifest.xml b/gearslip/src/main/AndroidManifest.xml index 9c6b5d6..6cd8de1 100644 --- a/gearslip/src/main/AndroidManifest.xml +++ b/gearslip/src/main/AndroidManifest.xml @@ -130,8 +130,13 @@ + >(emptySet()) val bookmarks: StateFlow> = bookmarksFlow val searchEngine: StateFlow = searchFlow @@ -73,6 +75,9 @@ object BrowserSettings { val youTubeAdBlock: StateFlow = youTubeFlow val filterLists: StateFlow> = listsFlow + /** Sites the driver opened over plain http and asked not to be warned about again. */ + val plainHttpOk: StateFlow> = plainHttpOkFlow + @Volatile private var prefs: SharedPreferences? = null /** 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) youTubeFlow.value = p.getBoolean(KEY_YOUTUBE, true) listsFlow.value = readLists(p) + plainHttpOkFlow.value = p.getStringSet(KEY_PLAIN_HTTP_OK, emptySet()).orEmpty().toSet() prefs = p } } @@ -134,6 +140,25 @@ object BrowserSettings { .filter { it.url.isNotEmpty() } }.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 fun setSearchEngine(engine: SearchEngine) { diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/WebApp.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/WebApp.kt index 1120e23..d916912 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/WebApp.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/WebApp.kt @@ -53,6 +53,10 @@ import androidx.compose.material.icons.filled.Search import androidx.compose.material.icons.filled.Refresh import androidx.compose.material.icons.filled.Home 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; @@ -178,6 +182,7 @@ fun WebApp(content: String) { } } } + if (!fullscreen && !atStart) PlainHttpBanner(pageUrl) Box(Modifier.weight(1f).fillMaxSize()) { AndroidView( 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()) + +/** + * 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. */ private fun loadContent(view: WebView, content: String) { if (content.startsWith("http://") || content.startsWith("https://")) { diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/HomeScreen.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/HomeScreen.kt index a3caa3b..44fabf8 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/HomeScreen.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/HomeScreen.kt @@ -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. */ 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. */ @Composable diff --git a/gearslip/src/main/res/values/strings.xml b/gearslip/src/main/res/values/strings.xml index 6a4225c..bd89d46 100644 --- a/gearslip/src/main/res/values/strings.xml +++ b/gearslip/src/main/res/values/strings.xml @@ -733,6 +733,9 @@ Search or type an address Forward Reload + This page isn\'t encrypted. Anyone on the same network can see what you send it. + Don\'t warn for this site + Hide warning Start page Full screen