web: leave the tab switcher when a deep link opens its tab
- Commit
6287be958cb931ec6d9cbc9a151db4cbe0a63af7- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 15:02 UTC (18 days ago)
- Parents
159c670
Opening the app from a URL link (VIEW intent / app link, or a share target) goes through MainActivity.handleIntentUrl into WebViewModel.externalIntentUrl, which always opens a new active tab. But newTab never dismissed the tab switcher, so on a warm start where the user had left the app sitting on the tab-selection screen, the link's tab was created and activated behind the switcher and the app appeared stuck on that screen. The tab switcher is an overlay on the Browser route, not a route of its own, so the fix stays inside the existing Route/Navigation architecture: externalIntentUrl now clears showTabSwitcher (and omniboxFocused) after opening the tab, the same dismissal switchToTab already performed when picking a tab by hand. No navigation state machine is added and no route changes. Behaviour for the link itself is unchanged: external links still always open a new tab, including when the URL is already open in a tab. Only the stuck-on-selector case changes. New WebViewModel tests cover a cold start via link, a warm start via link while the tab switcher is up, and a link for an already-open URL (still a second tab, and the switcher is dismissed). Verified with :web:testDevUnitTest and :web:lintDev (356 tests, 0 failures).
Diff
web/src/main/java/com/vayunmathur/web/platform/WebViewModelTabs.kt
diff --git a/web/src/main/java/com/vayunmathur/web/platform/WebViewModelTabs.kt b/web/src/main/java/com/vayunmathur/web/platform/WebViewModelTabs.ktindex 7250caefa6..d3b182d5ac 100644--- a/web/src/main/java/com/vayunmathur/web/platform/WebViewModelTabs.kt+++ b/web/src/main/java/com/vayunmathur/web/platform/WebViewModelTabs.kt@@ -200,6 +200,15 @@ fun WebViewModel.allowExternalRedirect(tabId: String, userGesture: Boolean): Boo fun WebViewModel.externalIntentUrl(url: String) { // Per product requirement: external links from other apps always open a new tab. newTab(url = url, makeActive = true)+ // A deep link must land the user on the tab it just opened. The tab+ // switcher is an overlay on the Browser route (not a route of its+ // own), and newTab alone leaves it up: on a warm start where the+ // user had left the switcher open, the new tab was created and made+ // active behind it and the app appeared stuck on the tab-selection+ // screen. Dismiss the switcher so the switch to the link's tab is+ // visible. This is the same dismissal switchToTab performs.+ showTabSwitcher = false+ omniboxFocused = false } // ---- Local network permission ----
web/src/test/java/com/vayunmathur/web/platform/WebViewModelTest.kt
diff --git a/web/src/test/java/com/vayunmathur/web/platform/WebViewModelTest.kt b/web/src/test/java/com/vayunmathur/web/platform/WebViewModelTest.ktindex e72ffca9e5..bd76a7cfe1 100644--- a/web/src/test/java/com/vayunmathur/web/platform/WebViewModelTest.kt+++ b/web/src/test/java/com/vayunmathur/web/platform/WebViewModelTest.kt@@ -141,6 +141,45 @@ class WebViewModelTest { assertEquals("https://ext.example", v.activeTab?.url) } + @Test fun externalIntentOnColdStartOpensLinkTab() {+ val v = vm()+ // No prior browsing: the link is the first real tab content.+ v.externalIntentUrl("https://cold.example/start")+ assertEquals("https://cold.example/start", v.activeTab?.url)+ assertFalse(v.showTabSwitcher)+ assertFalse(v.omniboxFocused)+ }++ @Test fun externalIntentWhileOnTabSwitcherSwitchesToLinkTab() {+ val v = vm()+ v.newTab(url = "https://a.example")+ v.newTab(url = "https://b.example")+ // The user left the app sitting on the tab-selection screen.+ v.showTabSwitcher = true+ v.externalIntentUrl("https://link.example/deep")+ // The link's tab is active and the selector is gone, so the+ // browser shows that tab instead of staying on the selector.+ assertEquals("https://link.example/deep", v.activeTab?.url)+ assertFalse(v.showTabSwitcher)+ }++ @Test fun externalIntentForAlreadyOpenUrlStillOpensNewTabAndLeavesSwitcher() {+ val v = vm()+ v.newTab(url = "https://dup.example/page")+ val existingId = v.activeTabId+ val before = v.tabs.size+ v.showTabSwitcher = true+ v.externalIntentUrl("https://dup.example/page")+ // Existing behaviour preserved: external links always open a+ // new tab, even when the URL is already open; only the+ // stuck-on-selector part changes.+ assertEquals(before + 1, v.tabs.size)+ assertEquals("https://dup.example/page", v.activeTab?.url)+ assertTrue(v.activeTabId != existingId)+ assertEquals(2, v.tabs.count { it.url == "https://dup.example/page" })+ assertFalse(v.showTabSwitcher)+ }+ @Test fun settingsUpdatesApply() { val v = vm() v.updateCacheMode(CacheMode.NO_CACHE); assertEquals(CacheMode.NO_CACHE, v.cacheMode)