Skip to content

Fix macOS menu-bar icon not activating the main window#4787

Closed
bgoncal wants to merge 3 commits into
mainfrom
fix/macos-menu-bar-window-activation
Closed

Fix macOS menu-bar icon not activating the main window#4787
bgoncal wants to merge 3 commits into
mainfrom
fix/macos-menu-bar-window-activation

Conversation

@bgoncal

@bgoncal bgoncal commented Jun 19, 2026

Copy link
Copy Markdown
Member

Summary

When the macOS app is set to display in the menu bar (.accessory activation policy) and the main window has been closed, tapping the Home Assistant menu-bar icon did nothing — the WindowGroup was never activated and the UI stayed hidden.

Tapping the menu-bar item runs Current.sceneManager.activateAnyScene(for: .webView), which calls requestSceneSessionActivation with a userActivity whose targetContentIdentifier is "ha.webview". As documented in SceneActivity.swift, that identifier is what SwiftUI's handlesExternalEvents(matching:) matches against to route an activated scene to the correct WindowGroup.

The primary webView WindowGroup in HAApp was 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 a WindowGroup, 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 primary WindowGroup, consistent with the other four. Window reuse is still handled separately by existingScenes(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).

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>
Copilot AI review requested due to automatic review settings June 19, 2026 15:18

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

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 webView WindowGroup so scene activations targeting SceneActivity.webView.activityIdentifier can correctly surface the main window.
  • Keeps the event-routing behavior consistent with the existing Settings/About/Assist/Onboarding WindowGroup declarations.

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

⚠️ Unused L10n strings detected

Found 21 unused localization strings in the codebase.

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

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

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

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

Found 21 unused strings:


ACTIONSCONFIGURATOR:
  - L10n.ActionsConfigurator.Action.createAutomation
    Key: actions_configurator.action.create_automation
    Line: 132
  - L10n.ActionsConfigurator.VisualSection.sceneDefined
    Key: actions_configurator.visual_section.scene_defined
    Line: 172
  - L10n.ActionsConfigurator.VisualSection.serverDefined
    Key: actions_configurator.visual_section.server_defined
    Line: 178

APPINTENTS:
  - L10n.AppIntents.WidgetAction.actionsParameterConfiguration
    Key: app_intents.widget_action.actions_parameter_configuration
    Line: 606

CAMERA:
  - L10n.Camera.serverNotFound
    Key: camera.server_not_found
    Line: 764
  - L10n.Camera.snapshotFailed
    Key: camera.snapshot_failed
    Line: 766

CAMERALIST:
  - L10n.CameraList.noArea
    Key: camera_list.no_area
    Line: 771
  - L10n.CameraList.searchPlaceholder
    Key: camera_list.search_placeholder
    Line: 773

CAMERAS:
  - L10n.Cameras.dragToReorder
    Key: cameras.drag_to_reorder
    Line: 829

SETTINGSDETAILS:
  - L10n.SettingsDetails.Actions.ActionsSynced.footerNoActions
    Key: settings_details.actions.actions_synced.footer_no_actions
    Line: 3836
  - L10n.SettingsDetails.Actions.Scenes.customizeAction
    Key: settings_details.actions.scenes.customize_action
    Line: 3854

URLHANDLER:
  - L10n.UrlHandler.Error.actionNotFound
    Key: url_handler.error.action_not_found
    Line: 4673

WIDGETS:
  - L10n.Widgets.Controls.Automations.placeholderTitle
    Key: widgets.controls.automations.placeholder_title
    Line: 5725
  - L10n.Widgets.Controls.Button.placeholderTitle
    Key: widgets.controls.button.placeholder_title
    Line: 5733
  - L10n.Widgets.Controls.Cover.placeholderTitle
    Key: widgets.controls.cover.placeholder_title
    Line: 5743
  - L10n.Widgets.Controls.Fan.placeholderTitle
    Key: widgets.controls.fan.placeholder_title
    Line: 5753
  - L10n.Widgets.Controls.Light.placeholderTitle
    Key: widgets.controls.light.placeholder_title
    Line: 5763
  - L10n.Widgets.Controls.Scenes.placeholderTitle
    Key: widgets.controls.scenes.placeholder_title
    Line: 5917
  - L10n.Widgets.Controls.Scripts.placeholderTitle
    Key: widgets.controls.scripts.placeholder_title
    Line: 5929
  - L10n.Widgets.Controls.Switch.placeholderTitle
    Key: widgets.controls.switch.placeholder_title
    Line: 5937

ROOT:
  - L10n.noArea
    Key: no_area
    Line: 36

================================================================================
Total unused: 21
================================================================================

To clean up these strings, manually remove them from the Localizable.strings files
and regenerate Strings.swift using SwiftGen.

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

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

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.
📢 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.

@bgoncal

bgoncal commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Superseded by #4789, which combines this with #4788 and adds the actual fix for the icon not showing the window (the handlesExternalEvents matcher here was necessary for the closed-window case but not sufficient on its own).

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.

2 participants