Hide browser portal when terminal tab is active (#1130)

This commit is contained in:
Austin Wang 2026-03-09 17:24:58 -07:00 committed by GitHub
parent c24ca32614
commit 8fa1ca3a4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 5 deletions

View file

@ -1838,8 +1838,9 @@ final class BrowserPanel: Panel, ObservableObject {
return true
}
func releasePortalHostIfOwned(hostId: ObjectIdentifier, reason: String) {
guard let current = activePortalHostLease, current.hostId == hostId else { return }
@discardableResult
func releasePortalHostIfOwned(hostId: ObjectIdentifier, reason: String) -> Bool {
guard let current = activePortalHostLease, current.hostId == hostId else { return false }
activePortalHostLease = nil
#if DEBUG
dlog(
@ -1848,6 +1849,7 @@ final class BrowserPanel: Panel, ObservableObject {
"inWin=\(current.inWindow ? 1 : 0) area=\(String(format: "%.1f", current.area))"
)
#endif
return true
}
var displayIcon: String? {

View file

@ -4323,11 +4323,23 @@ struct WebViewRepresentable: NSViewRepresentable {
let activePaneDropContext = coordinator.desiredPortalVisibleInUI ? paneDropContext : nil
let activeSearchOverlay = coordinator.desiredPortalVisibleInUI ? searchOverlay : nil
let portalAnchorView = panel.portalAnchorView
let portalHideReason = !isCurrentPaneOwner ? "lostPaneOwnership" : "hidden"
let didReleasePortalHost: Bool
if !shouldAttachWebView || !isCurrentPaneOwner {
panel.releasePortalHostIfOwned(
didReleasePortalHost = panel.releasePortalHostIfOwned(
hostId: hostId,
reason: !isCurrentPaneOwner ? "lostPaneOwnership" : "hidden"
reason: portalHideReason
)
// Only the host that currently owns the portal is allowed to hide it.
// Older keep-alive hosts can still receive updates after a new owner binds.
if didReleasePortalHost {
BrowserWindowPortalRegistry.hide(
webView: webView,
source: "viewStateChanged.\(portalHideReason)"
)
}
} else {
didReleasePortalHost = false
}
let portalHostAccepted =
shouldAttachWebView &&
@ -4345,7 +4357,8 @@ struct WebViewRepresentable: NSViewRepresentable {
"browser.portal.owner.skip panel=\(panel.id.uuidString.prefix(5)) " +
"viewPane=\(paneId.id.uuidString.prefix(5)) " +
"currentPane=\(paneDropContext?.paneId.id.uuidString.prefix(5) ?? "nil") " +
"host=\(Self.objectID(host)) hostInWin=\(host.window != nil ? 1 : 0)"
"host=\(Self.objectID(host)) hostInWin=\(host.window != nil ? 1 : 0) " +
"released=\(didReleasePortalHost ? 1 : 0)"
)
}
#endif