Skip to content

Commit 1eca7dc

Browse files
committed
fix: improve tab state synchronization and navigation
Prevent redundant intent handling, ensure active tab state reflects current webview updates, and clean up initial load logic in WebViewContainer.
1 parent 5cbd618 commit 1eca7dc

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

app/src/main/java/com/example/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class MainActivity : ComponentActivity() {
113113
val data = intent?.dataString
114114
if (action == Intent.ACTION_VIEW && !data.isNullOrBlank()) {
115115
viewModel.navigateTo(data)
116+
intent.data = null
116117
}
117118
}
118119
}

app/src/main/java/com/example/browser/BrowserViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ class BrowserViewModel(application: Application) : AndroidViewModel(application)
754754
val tabId = _activeTabId.value
755755
_activeTabState.update { it?.copy(url = "", title = "New Tab", progress = 0, isLoading = false) }
756756
viewModelScope.launch {
757+
_webViewActionEvent.emit(WebViewAction.StopLoading(targetTabId = tabId))
757758
_webViewActionEvent.emit(WebViewAction.LoadUrl("about:blank", targetTabId = tabId))
758759
val cur = currentTabs.value.find { it.id == tabId }
759760
if (cur != null) {

app/src/main/java/com/example/ui/BrowserScreen.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,20 @@ fun BrowserScreen(
268268
val activeTabIsDesktop = activeTabState?.isDesktopMode
269269
val activeTabIsPrivate = activeTabState?.isPrivate
270270

271-
val openTabs = remember(currentTabs, activeTabId) {
271+
val openTabs = remember(currentTabs, activeTabId, activeTabUrl) {
272272
val map = linkedMapOf<String, BrowserTab>()
273-
currentTabs.forEach { map[it.id] = it }
273+
currentTabs.forEach { tab ->
274+
if (tab.id == activeTabId && activeTabUrl != null) {
275+
map[tab.id] = tab.copy(
276+
url = activeTabUrl,
277+
title = activeTabTitle ?: tab.title,
278+
isDesktopMode = activeTabIsDesktop ?: tab.isDesktopMode,
279+
isPrivate = activeTabIsPrivate ?: tab.isPrivate
280+
)
281+
} else {
282+
map[tab.id] = tab
283+
}
284+
}
274285
if (activeTabId.isNotBlank() && !map.containsKey(activeTabId)) {
275286
map[activeTabId] = BrowserTab(
276287
id = activeTabId,

app/src/main/java/com/example/ui/components/WebViewContainer.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,13 +1003,6 @@ fun WebViewContainer(
10031003
val themeScript = FingerprintScriptGenerator.generateThemeScript(effectiveDark)
10041004
webView.evaluateJavascript(themeScript, null)
10051005
} catch (e: Exception) { }
1006-
1007-
if (initialUrl.isNotBlank() && initialUrl != "about:blank") {
1008-
val cur = webView.url ?: ""
1009-
if (cur.isEmpty() || cur == "about:blank") {
1010-
webView.loadUrl(initialUrl)
1011-
}
1012-
}
10131006
},
10141007
modifier = Modifier.fillMaxSize()
10151008
)

0 commit comments

Comments
 (0)