Fix macOS menu-bar icon not activating the main window#4787
Conversation
The primary webView WindowGroup was the only scene missing handlesExternalEvents(matching:), so a scene activation request carrying targetContentIdentifier "ha.webview" (issued when tapping the menu-bar item with no open window) had no WindowGroup to bind to and no window appeared. Match the identifier here, consistent with the other groups. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a macOS Catalyst edge case where clicking the Home Assistant menu-bar icon (when running with .accessory activation policy and the main window closed) failed to bring the main UI back because the requested scene activation couldn’t be routed to any WindowGroup.
Changes:
- Adds
handlesExternalEvents(matching:)to the primary webViewWindowGroupso scene activations targetingSceneActivity.webView.activityIdentifiercan correctly surface the main window. - Keeps the event-routing behavior consistent with the existing Settings/About/Assist/Onboarding
WindowGroupdeclarations.
|
Found 21 unused localization strings in the codebase. Click to see detailsTo clean up these strings, manually remove them from the |
Remove comment explaining scene activation for web view.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4787 +/- ##
=======================================
Coverage ? 44.69%
=======================================
Files ? 275
Lines ? 16835
Branches ? 0
=======================================
Hits ? 7524
Misses ? 9311
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
When the macOS app is set to display in the menu bar (
.accessoryactivation policy) and the main window has been closed, tapping the Home Assistant menu-bar icon did nothing — theWindowGroupwas never activated and the UI stayed hidden.Tapping the menu-bar item runs
Current.sceneManager.activateAnyScene(for: .webView), which callsrequestSceneSessionActivationwith auserActivitywhosetargetContentIdentifieris"ha.webview". As documented inSceneActivity.swift, that identifier is what SwiftUI'shandlesExternalEvents(matching:)matches against to route an activated scene to the correctWindowGroup.The primary webView
WindowGroupinHAAppwas the only scene missing that modifier — Settings, About, Assist, and Onboarding all declare it (which is why opening those from the menu worked). With no group advertising"ha.webview", SwiftUI couldn't bind the newly-requested scene to aWindowGroup, so no window appeared. Plain app launch worked because that scene carries no identifier and falls through to the default group; only the identifier-tagged re-activation hit the gap.The fix adds
.handlesExternalEvents(matching: [SceneActivity.webView.activityIdentifier])to the primaryWindowGroup, consistent with the other four. Window reuse is still handled separately byexistingScenes(for:)passing the existing session, so this won't spawn duplicate windows.Screenshots
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes
Regression introduced in the SwiftUI app-lifecycle migration (#4748).