Skip to content

Fix "Open Home Assistant UI in browser" reopening the dashboard every few minutes on Mac#4989

Open
bgoncal with Copilot wants to merge 3 commits into
mainfrom
copilot/open-home-assistant-ui-issue
Open

Fix "Open Home Assistant UI in browser" reopening the dashboard every few minutes on Mac#4989
bgoncal with Copilot wants to merge 3 commits into
mainfrom
copilot/open-home-assistant-ui-issue

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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()) — so willConnect only needs to cover the cold launch.

Changes:

  • MacBrowserSceneLauncher (new) — gates the auto-launch: markSceneConnected() returns true only for the process's first scene connection; isBrowserLaunchEnabled checks isCatalyst && macNativeFeaturesOnly.
  • QuickActionWindowSceneDelegate — only opens the browser / destroys the empty window on the initial connection; later background reconnections are ignored.
  • Tests — cover the initial-connection-only gating and platform/preference checks.
let isInitialSceneConnection = MacBrowserSceneLauncher.markSceneConnected()
// ...
if isInitialSceneConnection, MacBrowserSceneLauncher.isBrowserLaunchEnabled,
   let url = Current.servers.all.first?.activeURLUsingLastKnownNetworkState() {
    URLOpener.shared.open(url, options: [:], completionHandler: nil)
    UIApplication.shared.requestSceneSessionDestruction(session, options: nil, errorHandler: nil)
}

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.

Copilot AI changed the title [WIP] Fix issue with Home Assistant UI opening every few minutes Fix "Open Home Assistant UI in browser" reopening the dashboard every few minutes on Mac Jul 8, 2026
Copilot AI requested a review from bgoncal July 8, 2026 15:27
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ Unused L10n strings detected

Found 2 unused localization strings in the codebase.

Click to see details
Parsing Strings.swift...
Found 1878 L10n strings

Reading all Swift source code...
Read 6338148 characters of Swift code

Checking for unused strings...
Checked 100/1878 strings...
Checked 200/1878 strings...
Checked 300/1878 strings...
Checked 400/1878 strings...
Checked 500/1878 strings...
Checked 600/1878 strings...
Checked 700/1878 strings...
Checked 800/1878 strings...
Checked 900/1878 strings...
Checked 1000/1878 strings...
Checked 1100/1878 strings...
Checked 1200/1878 strings...
Checked 1300/1878 strings...
Checked 1400/1878 strings...
Checked 1500/1878 strings...
Checked 1600/1878 strings...
Checked 1700/1878 strings...
Checked 1800/1878 strings...

================================================================================
UNUSED STRINGS REPORT
================================================================================

Found 2 unused strings:


CONNECTION:
  - L10n.Connection.Permission.InternalUrl.body1
    Key: connection.permission.internal_url.body1
    Line: 1362
  - L10n.Connection.Permission.InternalUrl.body2
    Key: connection.permission.internal_url.body2
    Line: 1364

================================================================================
Total unused: 2
================================================================================

================================================================================
Copy-paste these keys into the "Lokalise: Delete Keys" workflow (keys input):
================================================================================
connection.permission.internal_url.body1,connection.permission.internal_url.body2

To remove them, run the
Lokalise: Delete Keys
workflow — it deletes the keys from Lokalise and opens a PR removing them from
Localizable.strings and regenerating Strings.swift. Copy-paste these keys into the keys input:

connection.permission.internal_url.body1,connection.permission.internal_url.body2

@bgoncal bgoncal marked this pull request as ready for review July 8, 2026 15:33
Copilot AI review requested due to automatic review settings July 8, 2026 15:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MacBrowserSceneLauncher to gate the browser auto-launch to the process’s first "WebView" scene connection.
  • Update QuickActionWindowSceneDelegate to 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.

Comment on lines +6 to +21
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()
}
Comment on lines +14 to +24
/// 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

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@e0ee51b). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Open Home Assistant UI in browser" opens evert few minutes

3 participants