mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-30 23:30:32 +01:00
The browser picks up where it left off when you come back to it, and its start page shows one search bar
This commit is contained in:
1 parent
8a4804a1f7
commit
623a8dc438
1 file changed
+20
-2
@@ -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<String?>(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<String?>(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
|
||||
}
|
||||
Reference in new issue
Block a user