web: fix search bar styling and add search engine picker
- Commit
bcf3a35488ac284dc804113e18fbafd340df5e73- Author
- Vayun Mathur <[email protected]>
- When
- 2026-08-02 21:02 UTC (4 months ago)
- Parents
e5fb904
Diff
web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt b/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.ktindex d230cc7d53..426f6c7f8d 100644--- a/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt@@ -25,6 +25,8 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.foundation.text.KeyboardActions+import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue@@ -37,6 +39,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalFocusManager+import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle@@ -45,18 +48,18 @@ import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.CardDefaults+import com.vayunmathur.library.ui.CommonSearchBar import com.vayunmathur.library.ui.DropdownMenu import com.vayunmathur.library.ui.DropdownMenuItem import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.HorizontalDivider import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.LinearProgressIndicator+import com.vayunmathur.library.ui.ListItem import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedButton import com.vayunmathur.library.ui.OutlinedTextField import com.vayunmathur.library.ui.Scaffold-import com.vayunmathur.library.ui.SearchBar-import com.vayunmathur.library.ui.SearchBarInputField import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton@@ -66,9 +69,7 @@ import com.vayunmathur.library.ui.IconAdd import com.vayunmathur.library.ui.IconArrowForward import com.vayunmathur.library.ui.IconBack import com.vayunmathur.library.ui.IconClose-import com.vayunmathur.library.ui.IconHome import com.vayunmathur.library.ui.IconMoreVert-import com.vayunmathur.library.ui.IconRefresh import com.vayunmathur.library.ui.IconSearch import com.vayunmathur.web.Route import com.vayunmathur.library.util.NavBackStack@@ -133,185 +134,148 @@ fun BrowserPage( Box(Modifier.fillMaxSize()) { if (viewModel.omniboxFocused) {- Box(- Modifier- .fillMaxSize()- .background(MaterialTheme.colorScheme.background)- ) {- SearchBar(- inputField = {- SearchBarInputField(- query = viewModel.searchDraft,- onQueryChange = { viewModel.searchDraft = it },- onSearch = { q ->- if (q.isNotBlank()) viewModel.navigateActiveTab(q)+ Scaffold(+ topBar = {+ TopAppBar(+ navigationIcon = {+ IconButton(onClick = { focusManager.clearFocus() viewModel.omniboxFocused = false- },- expanded = true,- onExpandedChange = { expanded ->- if (!expanded) {- focusManager.clearFocus()- viewModel.omniboxFocused = false- }- },- placeholder = { Text(stringResource(R.string.search_or_enter_address)) },- leadingIcon = {- IconButton(onClick = {- focusManager.clearFocus()- viewModel.omniboxFocused = false- }) { IconBack() }- },- trailingIcon = if (viewModel.searchDraft.isNotEmpty()) {- {- IconButton(onClick = { viewModel.searchDraft = "" }) { IconClose() }- }- } else null- )- },- expanded = true,- onExpandedChange = { expanded ->- if (!expanded) {- focusManager.clearFocus()- viewModel.omniboxFocused = false+ }) { IconBack() }+ },+ title = {+ OutlinedTextField(+ value = viewModel.searchDraft,+ onValueChange = { viewModel.searchDraft = it },+ modifier = Modifier.fillMaxWidth(),+ placeholder = { Text(stringResource(R.string.search_or_enter_address)) },+ leadingIcon = { IconSearch() },+ trailingIcon = if (viewModel.searchDraft.isNotEmpty()) {+ {+ IconButton(onClick = { viewModel.searchDraft = "" }) { IconClose() }+ }+ } else null,+ shape = RoundedCornerShape(28.dp),+ singleLine = true,+ keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),+ keyboardActions = KeyboardActions(onSearch = {+ if (viewModel.searchDraft.isNotBlank()) {+ viewModel.navigateActiveTab(viewModel.searchDraft)+ focusManager.clearFocus()+ viewModel.omniboxFocused = false+ }+ })+ ) }- },- modifier = Modifier.fillMaxSize()+ )+ }+ ) { paddingValues ->+ LazyColumn(+ modifier = Modifier+ .fillMaxSize()+ .padding(paddingValues),+ verticalArrangement = Arrangement.spacedBy(2.dp),+ contentPadding = PaddingValues(top = 8.dp, bottom = 24.dp) ) {- LazyColumn(- modifier = Modifier- .fillMaxSize()- .padding(horizontal = 12.dp),- verticalArrangement = Arrangement.spacedBy(4.dp),- contentPadding = PaddingValues(top = 8.dp, bottom = 24.dp)- ) {+ if (currentDraft.isNotBlank()) { item {- Card(- modifier = Modifier- .fillMaxWidth()- .padding(vertical = 8.dp),- colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.secondaryContainer),- shape = RoundedCornerShape(16.dp)- ) {- Row(- Modifier- .fillMaxWidth()- .padding(12.dp),- horizontalArrangement = Arrangement.spacedBy(8.dp)- ) {- OutlinedButton(- onClick = {- activeTab?.let { webViewPool[it.id]?.reload() }- focusManager.clearFocus()- viewModel.omniboxFocused = false- },- enabled = !isNewTabActive,- modifier = Modifier.weight(1f)- ) {- IconRefresh()- Spacer(Modifier.width(6.dp))- Text(stringResource(R.string.reload))- }- OutlinedButton(- onClick = { viewModel.searchDraft = "" },- modifier = Modifier.weight(1f)- ) {- IconClose()- Spacer(Modifier.width(6.dp))- Text(stringResource(UiR.string.clear))- }+ ListItem(+ headlineContent = { Text(currentDraft, maxLines = 1, overflow = TextOverflow.Ellipsis) },+ supportingContent = {+ Text(+ text = BrowserUtils.hostFromUrl(+ BrowserUtils.toNavigationUrl(currentDraft, viewModel.searchEngine)+ ),+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ maxLines = 1,+ overflow = TextOverflow.Ellipsis+ )+ },+ leadingContent = { IconSearch() },+ modifier = Modifier.clickable {+ viewModel.navigateActiveTab(currentDraft)+ focusManager.clearFocus()+ viewModel.omniboxFocused = false }- }+ ) }+ item { HorizontalDivider(Modifier.padding(vertical = 4.dp)) }+ } - if (currentDraft.isNotBlank()) {- item {- Card(- modifier = Modifier- .fillMaxWidth()- .clickable {- viewModel.navigateActiveTab(currentDraft)- focusManager.clearFocus()- viewModel.omniboxFocused = false- },- colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.secondaryContainer)- ) {- Row(- Modifier- .fillMaxWidth()- .padding(14.dp),- verticalAlignment = Alignment.CenterVertically- ) {- IconSearch()- Spacer(Modifier.width(12.dp))- Column {- Text(text = currentDraft, maxLines = 1, overflow = TextOverflow.Ellipsis)- Text(- text = BrowserUtils.hostFromUrl(BrowserUtils.toNavigationUrl(currentDraft)),- style = MaterialTheme.typography.bodySmall,- color = MaterialTheme.colorScheme.onSecondaryContainer.copy(alpha = 0.75f),- maxLines = 1,- overflow = TextOverflow.Ellipsis- )- }- }- }- Spacer(Modifier.height(8.dp))- }+ if (filteredBookmarks.isNotEmpty()) {+ item {+ Text(+ stringResource(R.string.bookmarks),+ style = MaterialTheme.typography.titleSmall,+ color = MaterialTheme.colorScheme.primary,+ modifier = Modifier.padding(horizontal = 16.dp, vertical = 6.dp)+ ) }-- if (filteredBookmarks.isNotEmpty()) {- item {- Text(stringResource(R.string.bookmarks), style = MaterialTheme.typography.titleSmall, modifier = Modifier.padding(vertical = 6.dp))- }- items(filteredBookmarks, key = { "bm-${it.id}" }) { bm ->- Row(- modifier = Modifier- .fillMaxWidth()- .clip(RoundedCornerShape(12.dp))- .clickable {- viewModel.navigateActiveTab(bm.url)- focusManager.clearFocus()- viewModel.omniboxFocused = false- }- .padding(12.dp),- verticalAlignment = Alignment.CenterVertically- ) {- IconSearch()- Spacer(Modifier.width(12.dp))- Column(Modifier.weight(1f)) {- Text(bm.title.ifBlank { bm.url }, maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodyMedium)- Text(BrowserUtils.prettyUrl(bm.url), maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)- }+ items(filteredBookmarks, key = { "bm-${it.id}" }) { bm ->+ ListItem(+ headlineContent = {+ Text(+ bm.title.ifBlank { bm.url },+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ style = MaterialTheme.typography.bodyMedium+ )+ },+ supportingContent = {+ Text(+ BrowserUtils.prettyUrl(bm.url),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant+ )+ },+ leadingContent = { IconSearch() },+ modifier = Modifier.clickable {+ viewModel.navigateActiveTab(bm.url)+ focusManager.clearFocus()+ viewModel.omniboxFocused = false }- }+ ) }+ } - if (filteredHistory.isNotEmpty()) {- item {- Text(stringResource(R.string.history), style = MaterialTheme.typography.titleSmall, modifier = Modifier.padding(top = 12.dp, bottom = 6.dp))- }- items(filteredHistory, key = { "h-${it.id}" }) { h ->- Row(- modifier = Modifier- .fillMaxWidth()- .clip(RoundedCornerShape(12.dp))- .clickable {- viewModel.navigateActiveTab(h.url)- focusManager.clearFocus()- viewModel.omniboxFocused = false- }- .padding(12.dp),- verticalAlignment = Alignment.CenterVertically- ) {- IconSearch()- Spacer(Modifier.width(12.dp))- Column(Modifier.weight(1f)) {- Text(h.title.ifBlank { h.url }, maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodyMedium)- Text(BrowserUtils.prettyUrl(h.url), maxLines = 1, overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)- }+ if (filteredHistory.isNotEmpty()) {+ item {+ Text(+ stringResource(R.string.history),+ style = MaterialTheme.typography.titleSmall,+ color = MaterialTheme.colorScheme.primary,+ modifier = Modifier.padding(horizontal = 16.dp, vertical = 6.dp).padding(top = if (filteredBookmarks.isNotEmpty()) 12.dp else 0.dp)+ )+ }+ items(filteredHistory, key = { "h-${it.id}" }) { h ->+ ListItem(+ headlineContent = {+ Text(+ h.title.ifBlank { h.url },+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ style = MaterialTheme.typography.bodyMedium+ )+ },+ supportingContent = {+ Text(+ BrowserUtils.prettyUrl(h.url),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant+ )+ },+ leadingContent = { IconSearch() },+ modifier = Modifier.clickable {+ viewModel.navigateActiveTab(h.url)+ focusManager.clearFocus()+ viewModel.omniboxFocused = false }- }+ ) } } }@@ -322,7 +286,6 @@ fun BrowserPage( tabCount = viewModel.tabs.size, canGoBack = canGoBack, canGoForward = canGoForward,- // A blank new tab is not loading anything, so never show the bar for one. progress = if (activeTab != null && !isNewTabActive) progress else 0f, onBack = { if (canGoBack) activeTab?.let { webViewPool[it.id]?.goBack() } }, onForward = { if (canGoForward) activeTab?.let { webViewPool[it.id]?.goForward() } },@@ -335,6 +298,16 @@ fun BrowserPage( onMenuClick = { showMenu = true }, menu = { DropdownMenu(expanded = showMenu, onDismissRequest = { showMenu = false }) {+ if (!isNewTabActive) {+ DropdownMenuItem(+ text = { Text(stringResource(R.string.reload)) },+ onClick = {+ showMenu = false+ activeTab?.let { webViewPool[it.id]?.reload() }+ }+ )+ }+ if (activeTab != null && !isNewTabActive) { val pwa = viewModel.getPwaInfo(activeTab.id) val pinSupported = PwaHelper.isPinSupported(context)@@ -533,15 +506,6 @@ fun BrowserPage( } } -/**- * The browser chrome — back/forward, the address pill, the tab counter and the overflow- * button — around whatever [content] the active tab needs. Split out of [BrowserPage] with no- * ViewModel reference so the new-tab screen can be rendered from a `@Preview`; see- * `src/screenshotTest`, which is where the store listing images come from.- *- * [menu] is a slot rather than a list of callbacks because the overflow menu has to stay- * anchored inside the app bar's `actions` row to pop up in the right place.- */ @OptIn(ExperimentalMaterial3Api::class) @Composable fun BrowserChrome(@@ -549,7 +513,6 @@ fun BrowserChrome( tabCount: Int, canGoBack: Boolean = false, canGoForward: Boolean = false,- /** Load progress of the visible page; outside 0.01..0.99 the thin bar is hidden. */ progress: Float = 0f, onBack: () -> Unit = {}, onForward: () -> Unit = {},@@ -611,25 +574,28 @@ private fun DisplayOnlyAddressPill( onClick: () -> Unit, modifier: Modifier = Modifier, ) {- Surface(- shape = RoundedCornerShape(24.dp),- color = MaterialTheme.colorScheme.secondaryContainer,- modifier = modifier.clip(RoundedCornerShape(24.dp)).clickable(onClick = onClick)- ) {- val isPlaceholder = fullUrl.isBlank()- Text(- text = if (isPlaceholder) "Search or enter address" else fullUrl,- maxLines = 1,- overflow = TextOverflow.Ellipsis,- style = MaterialTheme.typography.bodyMedium,- color = if (isPlaceholder) MaterialTheme.colorScheme.onSecondaryContainer.copy(alpha = 0.7f)- else MaterialTheme.colorScheme.onSecondaryContainer,- modifier = Modifier.padding(horizontal = 16.dp, vertical = 10.dp)+ // Now matches CommonSearchBar visually: OutlinedTextField 28dp rounded, search icon, same padding.+ Box(modifier = modifier) {+ OutlinedTextField(+ value = fullUrl,+ onValueChange = {},+ readOnly = true,+ placeholder = { Text(stringResource(R.string.search_or_enter_address)) },+ leadingIcon = { IconSearch() },+ singleLine = true,+ shape = RoundedCornerShape(28.dp),+ modifier = Modifier.fillMaxWidth()+ )+ // Overlay to handle tap without focusing the field+ Box(+ Modifier+ .matchParentSize()+ .clip(RoundedCornerShape(28.dp))+ .clickable(onClick = onClick) ) } } -/** The blank-new-tab landing page. Public so the store-listing previews can render it. */ @Composable fun QuickAccess( bookmarks: List<com.vayunmathur.web.data.Bookmark>,
web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt b/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.ktindex aa0fe6f16f..4848a0591d 100644--- a/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt@@ -45,6 +45,7 @@ import com.vayunmathur.library.ui.TopAppBar import com.vayunmathur.web.Route import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.web.util.CacheMode+import com.vayunmathur.web.util.SearchEngine import com.vayunmathur.web.util.WebViewModel @OptIn(ExperimentalMaterial3Api::class)@@ -56,6 +57,7 @@ fun SettingsPage( val context = LocalContext.current var showClearDataDialog by remember { mutableStateOf(false) } var showCacheDialog by remember { mutableStateOf(false) }+ var showSearchEngineDialog by remember { mutableStateOf(false) } val storageCount by viewModel.storageInfos.collectAsStateWithLifecycle() val permCount by viewModel.sitePermissions.collectAsStateWithLifecycle()@@ -76,7 +78,8 @@ fun SettingsPage( item { ListItem( headlineContent = { Text(stringResource(R.string.search_engine)) },- supportingContent = { Text(stringResource(R.string.duckduckgo_locked)) }+ supportingContent = { Text(viewModel.searchEngine.displayName) },+ modifier = Modifier.clickable { showSearchEngineDialog = true } ) } @@ -225,6 +228,36 @@ fun SettingsPage( ) } ++ if (showSearchEngineDialog) {+ AlertDialog(+ onDismissRequest = { showSearchEngineDialog = false },+ title = { Text(stringResource(R.string.search_engine)) },+ text = {+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {+ SearchEngine.entries.forEach { engine ->+ Row(+ modifier = Modifier.fillMaxWidth().clickable {+ viewModel.updateSearchEngine(engine); showSearchEngineDialog = false+ }.padding(vertical = 10.dp),+ verticalAlignment = Alignment.CenterVertically+ ) {+ RadioButton(selected = viewModel.searchEngine == engine, onClick = {+ viewModel.updateSearchEngine(engine); showSearchEngineDialog = false+ })+ Spacer(Modifier.width(12.dp))+ Column {+ Text(engine.displayName, style = MaterialTheme.typography.bodyMedium)+ Text(engine.homepage, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)+ }+ }+ }+ }+ },+ confirmButton = { TextButton(onClick = { showSearchEngineDialog = false }) { Text(stringResource(UiR.string.close)) } }+ )+ }+ if (showClearDataDialog) { AlertDialog( onDismissRequest = { showClearDataDialog = false },
web/src/main/java/com/vayunmathur/web/util/BrowserState.kt
diff --git a/web/src/main/java/com/vayunmathur/web/util/BrowserState.kt b/web/src/main/java/com/vayunmathur/web/util/BrowserState.ktindex b0f876f01e..9dbb035a2b 100644--- a/web/src/main/java/com/vayunmathur/web/util/BrowserState.kt+++ b/web/src/main/java/com/vayunmathur/web/util/BrowserState.kt@@ -15,19 +15,26 @@ data class BrowserTab( val BrowserTab.isNewTab: Boolean get() = url.isBlank() || url == "about:blank" -/** Only DuckDuckGo is used now — choice removed per design request. */ enum class SearchEngine( val displayName: String, val searchUrl: String, val homepage: String, ) {- DUCKDUCKGO("DuckDuckGo", "https://duckduckgo.com/?q=%s", "https://duckduckgo.com");+ GOOGLE("Google", "https://www.google.com/search?q=%s", "https://www.google.com"),+ DUCKDUCKGO("DuckDuckGo", "https://duckduckgo.com/?q=%s", "https://duckduckgo.com"),+ BING("Bing", "https://www.bing.com/search?q=%s", "https://www.bing.com"),+ BRAVE("Brave", "https://search.brave.com/search?q=%s", "https://search.brave.com"),+ STARTPAGE("Startpage", "https://www.startpage.com/do/search?q=%s", "https://www.startpage.com"),+ ECOSIA("Ecosia", "https://www.ecosia.org/search?q=%s", "https://www.ecosia.org"),+ QWANT("Qwant", "https://www.qwant.com/?q=%s", "https://www.qwant.com"); fun buildQueryUrl(query: String): String = searchUrl.replace("%s", Uri.encode(query)) companion object { val DEFAULT = DUCKDUCKGO+ fun fromName(name: String): SearchEngine =+ entries.find { it.name == name } ?: DEFAULT } } @@ -50,7 +57,7 @@ object BrowserUtils { "^(https?://)?([a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}|localhost|\\d{1,3}(\\.\\d{1,3}){3})(:\\d+)?(/.*)?$" ) - /** Kept as search fallback only — blank new tabs use "" not HOMEPAGE. */+ /** Kept for migration only — new tabs use "" and search uses selected engine. */ const val HOMEPAGE = "https://duckduckgo.com" /** Full address for display — no truncation. Keep prettyUrl() for subtitles. */@@ -63,20 +70,18 @@ object BrowserUtils { return URL_LIKE.matches(trimmed) } - /** Search or navigate — always uses DuckDuckGo for queries. */- fun toNavigationUrl(input: String): String {+ /** Search or navigate using the selected engine. */+ fun toNavigationUrl(input: String, searchEngine: SearchEngine): String { val trimmed = input.trim()- if (trimmed.isEmpty()) return HOMEPAGE+ if (trimmed.isEmpty()) return searchEngine.homepage if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) return trimmed if (looksLikeUrl(trimmed)) { return if (trimmed.startsWith("http")) trimmed else "https://$trimmed" }- return SearchEngine.DEFAULT.buildQueryUrl(trimmed)+ return searchEngine.buildQueryUrl(trimmed) } - // Legacy overload kept for call sites that still pass engine — always DuckDuckGo- fun toNavigationUrl(input: String, @Suppress("UNUSED_PARAMETER") searchEngine: SearchEngine): String =- toNavigationUrl(input)+ fun toNavigationUrl(input: String): String = toNavigationUrl(input, SearchEngine.DEFAULT) fun hostFromUrl(url: String): String { return try { Uri.parse(url).host ?: url } catch (_: Exception) { url }
web/src/main/java/com/vayunmathur/web/util/WebViewModel.kt
diff --git a/web/src/main/java/com/vayunmathur/web/util/WebViewModel.kt b/web/src/main/java/com/vayunmathur/web/util/WebViewModel.ktindex 0bf0727bd3..a1d1e7cedb 100644--- a/web/src/main/java/com/vayunmathur/web/util/WebViewModel.kt+++ b/web/src/main/java/com/vayunmathur/web/util/WebViewModel.kt@@ -42,6 +42,7 @@ private const val P_JS_ENABLED = "web_js_enabled" private const val P_BLOCK_THIRD_PARTY = "web_block_third_party" private const val P_DESKTOP_MODE = "web_desktop_mode" private const val P_ADBLOCK = "web_adblock"+private const val P_SEARCH_ENGINE = "web_search_engine" data class PermissionPrompt( val id: String = Uuid.random().toString(),@@ -69,9 +70,8 @@ class WebViewModel( var omniboxFocused by mutableStateOf(false) var searchDraft by mutableStateOf("") - // DuckDuckGo only — engine choice removed- val searchEngine: SearchEngine = SearchEngine.DEFAULT- val homepage: String = BrowserUtils.HOMEPAGE+ var searchEngine by mutableStateOf(SearchEngine.DEFAULT)+ val homepage: String get() = searchEngine.homepage var cacheMode by mutableStateOf(CacheMode.DEFAULT) var jsEnabled by mutableStateOf(true)@@ -130,12 +130,14 @@ class WebViewModel( val savedTabs = sp.getString(P_SAVED_TABS, null) val activeId = sp.getString(P_ACTIVE_TAB, null) val cacheModeName = sp.getString(P_CACHE_MODE, null)+ val searchEngineName = sp.getString(P_SEARCH_ENGINE, null) val js = sp.getBoolean(P_JS_ENABLED, true) val blockThird = sp.getBoolean(P_BLOCK_THIRD_PARTY, false) val desktop = sp.getBoolean(P_DESKTOP_MODE, false) val adblock = sp.getBoolean(P_ADBLOCK, false) withContext(Dispatchers.Main) { cacheModeName?.let { runCatching { CacheMode.valueOf(it) }.getOrNull()?.let { cm -> cacheMode = cm } }+ searchEngineName?.let { runCatching { SearchEngine.valueOf(it) }.getOrNull()?.let { se -> searchEngine = se } } jsEnabled = js blockThirdPartyCookies = blockThird desktopMode = desktop@@ -294,7 +296,7 @@ class WebViewModel( fun navigateActiveTab(input: String) { val active = activeTab ?: return- val dest = BrowserUtils.toNavigationUrl(input)+ val dest = BrowserUtils.toNavigationUrl(input, searchEngine) onTabUrlChange(active.id, dest) omniboxFocused = false }@@ -338,6 +340,11 @@ class WebViewModel( persistPrefs() } + fun updateSearchEngine(engine: SearchEngine) {+ searchEngine = engine+ persistPrefs()+ }+ fun updateJsEnabled(enabled: Boolean) { jsEnabled = enabled persistPrefs()@@ -624,6 +631,7 @@ class WebViewModel( val sp = context.getSharedPreferences("web_prefs", Context.MODE_PRIVATE) sp.edit() .putString(P_CACHE_MODE, cacheMode.name)+ .putString(P_SEARCH_ENGINE, searchEngine.name) .putBoolean(P_JS_ENABLED, jsEnabled) .putBoolean(P_BLOCK_THIRD_PARTY, blockThirdPartyCookies) .putBoolean(P_DESKTOP_MODE, desktopMode)