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 deed555..176f6b1 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/WebApp.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/WebApp.kt @@ -94,7 +94,8 @@ fun WebApp(content: String) { // An address being typed to save as a bookmark, from the start page's Add tile. var newBookmark by remember { mutableStateOf(null) } // The start page covers the WebView until something is opened. - var atStart by remember { mutableStateOf(content.isBlank()) } + // Coming back to the browser in the same drive picks up the page that was open. + var atStart by remember { mutableStateOf(content.isBlank() && BrowserMemory.lastUrl == null) } var pageUrl by remember { mutableStateOf(null) } val bookmarks by BrowserSettings.bookmarks.collectAsState() val context = LocalContext.current @@ -108,6 +109,7 @@ fun WebApp(content: String) { } val goHome: () -> Unit = { if (content.isBlank()) { + BrowserMemory.lastUrl = null atStart = true pageTitle = "" } else { @@ -115,6 +117,12 @@ fun WebApp(content: String) { } } + // Remembers the page for next time the browser opens, until Home goes back to the start page. + LaunchedEffect(pageUrl, atStart) { + val url = pageUrl + if (content.isBlank() && !atStart && url != null && url.startsWith("http")) BrowserMemory.lastUrl = url + } + // Leaving the browser ends full screen, whoever started it. DisposableEffect(Unit) { onDispose { CarFullscreen.exit() } } // The way out of full screen also ends the page's. @@ -178,7 +186,8 @@ fun WebApp(content: String) { ) } } - GsIconButton(androidx.compose.material.icons.Icons.Filled.Search, stringResource(R.string.web_search), { + // The start page has its own search bar: one is enough. + if (!atStart) GsIconButton(androidx.compose.material.icons.Icons.Filled.Search, stringResource(R.string.web_search), { fieldText = null address = "" }) @@ -245,6 +254,7 @@ fun WebApp(content: String) { "GearslipField", ) if (content.isNotBlank()) loadContent(this, content) + else BrowserMemory.lastUrl?.let { loadUrl(it) } web = this } }, @@ -506,3 +516,11 @@ private const val FOCUS_TRACKING_JS = """ }); })(); """ + +/** + * The page the browser last showed, kept while Gearslip runs. Leaving the browser for the map and + * coming back used to start over at the start page, as if its one tab had been closed. + */ +internal object BrowserMemory { + @Volatile var lastUrl: String? = null +}