Fix "Open Home Assistant UI in browser" reopening the dashboard every few minutes on Mac#4989
Conversation
|
Found 2 unused localization strings in the codebase. Click to see detailsTo remove them, run the |
There was a problem hiding this comment.
Pull request overview
Fixes an issue on Mac Catalyst where enabling “Open Home Assistant UI in browser” would repeatedly reopen the dashboard due to background "WebView" scene reconnections. The change introduces a small, process-lifetime gate so only the cold-launch scene connection triggers the browser open + scene destruction.
Changes:
- Add
MacBrowserSceneLauncherto gate the browser auto-launch to the process’s first"WebView"scene connection. - Update
QuickActionWindowSceneDelegateto only open the browser (and destroy the empty scene) on that initial connection. - Add unit tests covering initial-connection gating and the Catalyst + preference enablement logic.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Tests/App/Scenes/MacBrowserSceneLauncher.test.swift | Adds unit tests for initial-connection gating and preference/platform checks. |
| Sources/App/Scenes/QuickActionWindowSceneDelegate.swift | Uses the new gate to avoid reopening the browser on background scene reconnections. |
| Sources/App/Scenes/MacBrowserSceneLauncher.swift | Introduces a process-lifetime “first connection only” gate and enablement predicate. |
| HomeAssistant.xcodeproj/project.pbxproj | Registers the new source + test files in the Xcode project. |
| private var originalIsCatalyst: Bool! | ||
| private var originalMacNativeFeaturesOnly: Bool! | ||
|
|
||
| override func setUpWithError() throws { | ||
| try super.setUpWithError() | ||
| originalIsCatalyst = Current.isCatalyst | ||
| originalMacNativeFeaturesOnly = Current.settingsStore.macNativeFeaturesOnly | ||
| MacBrowserSceneLauncher.didHandleInitialSceneConnection = false | ||
| } | ||
|
|
||
| override func tearDownWithError() throws { | ||
| Current.isCatalyst = originalIsCatalyst | ||
| Current.settingsStore.macNativeFeaturesOnly = originalMacNativeFeaturesOnly | ||
| MacBrowserSceneLauncher.didHandleInitialSceneConnection = false | ||
| try super.tearDownWithError() | ||
| } |
| /// Whether the initial (cold-launch) `"WebView"` scene connection has already been observed this process. | ||
| /// Reset only implicitly, by the process being relaunched. | ||
| static var didHandleInitialSceneConnection = false | ||
|
|
||
| /// Records that a `"WebView"` scene has connected and reports whether this was the first connection of the | ||
| /// process (i.e. the user's cold launch). Subsequent calls return `false`. | ||
| @discardableResult | ||
| static func markSceneConnected() -> Bool { | ||
| let isInitialConnection = !didHandleInitialSceneConnection | ||
| didHandleInitialSceneConnection = true | ||
| return isInitialConnection |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4989 +/- ##
=======================================
Coverage ? 52.23%
=======================================
Files ? 298
Lines ? 19620
Branches ? 0
=======================================
Hits ? 10249
Misses ? 9371
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
On Mac Catalyst with "Open Home Assistant UI in browser" (
macNativeFeaturesOnly) enabled, the dashboard reopened in the browser every few minutes.Root cause:
QuickActionWindowSceneDelegate.scene(_:willConnectTo:)opened the browser on every"WebView"scene connection. macOS reconnects that scene in the background throughout the app's lifetime, so each reconnection re-triggered the launch. Genuine user re-opens while running never use this path — they go through the Dock reopen handler and status-item menu (StatusItemPrimaryAction.openInBrowserIfNeeded()) — sowillConnectonly needs to cover the cold launch.Changes:
MacBrowserSceneLauncher(new) — gates the auto-launch:markSceneConnected()returnstrueonly for the process's first scene connection;isBrowserLaunchEnabledchecksisCatalyst && macNativeFeaturesOnly.QuickActionWindowSceneDelegate— only opens the browser / destroys the empty window on the initial connection; later background reconnections are ignored.Screenshots
N/A — behavioral fix, no UI change.
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes
Subsequent user-initiated opens while the app is already running continue to be handled by the Dock reopen handler and status-item menu. If the periodic scene reconnection also surfaces a window when the option is disabled, that is a separate scene-activation concern not addressed here.