diff --git a/Sources/Panels/BrowserPanel.swift b/Sources/Panels/BrowserPanel.swift index 21fa45e7..d0f07d8c 100644 --- a/Sources/Panels/BrowserPanel.swift +++ b/Sources/Panels/BrowserPanel.swift @@ -4221,11 +4221,18 @@ extension BrowserPanel { func noteDeveloperToolsHostAttached() { cancelPendingDeveloperToolsVisibilityLossCheck() developerToolsLastAttachedHostAt = Date() - developerToolsLastKnownVisibleAt = isDeveloperToolsVisible() ? Date() : nil + if isDeveloperToolsVisible() { + developerToolsLastKnownVisibleAt = Date() + } } func scheduleDeveloperToolsVisibilityLossCheck() { developerToolsVisibilityLossCheckWorkItem?.cancel() + let attachedAge = developerToolsLastAttachedHostAt.map { Date().timeIntervalSince($0) } ?? 0 + let delay = max( + developerToolsTransitionSettleDelay, + developerToolsAttachedManualCloseDetectionDelay - attachedAge + ) let workItem = DispatchWorkItem { [weak self] in guard let self else { return } self.developerToolsVisibilityLossCheckWorkItem = nil @@ -4233,7 +4240,7 @@ extension BrowserPanel { } developerToolsVisibilityLossCheckWorkItem = workItem DispatchQueue.main.asyncAfter( - deadline: .now() + developerToolsTransitionSettleDelay, + deadline: .now() + max(0, delay), execute: workItem ) } diff --git a/Sources/Panels/BrowserPanelView.swift b/Sources/Panels/BrowserPanelView.swift index bc98416b..c7204076 100644 --- a/Sources/Panels/BrowserPanelView.swift +++ b/Sources/Panels/BrowserPanelView.swift @@ -542,7 +542,7 @@ struct BrowserPanelView: View { // `isVisibleInUI` never flips to false. Check for an attached-inspector // X-close when focus leaves as well so the persisted intent stays in sync. DispatchQueue.main.async { - _ = panel.consumeAttachedDeveloperToolsManualCloseIfNeeded() + panel.scheduleDeveloperToolsVisibilityLossCheck() } } syncWebViewResponderPolicyWithViewState(