From 969dda72388e196a7592f026841e6a659269ac5e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Dec 2025 01:27:59 +0000 Subject: [PATCH 1/2] Initial plan From b91a19a8dc8df6f72c9f17ae8b481e880d2e3c6b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Dec 2025 01:35:37 +0000 Subject: [PATCH 2/2] Fix menu bar text not updating after connection loss When the Home Assistant connection is lost and re-established, the menu bar text subscription was not being refreshed, causing the text to become stale. Changes: - Added observer for HomeAssistantAPI.didConnectNotification in AppDelegate - Added shouldRefreshTitleSubscription flag to force subscription recreation - Cancel old subscription before creating new one in MenuManager - Trigger menu rebuild when API reconnects to refresh subscription This ensures that the menu bar text subscription is recreated after server restarts or network reconnections, keeping the displayed text up to date. Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com> --- Sources/App/AppDelegate.swift | 20 +++++++++++++++++++- Sources/App/Utilities/MenuManager.swift | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Sources/App/AppDelegate.swift b/Sources/App/AppDelegate.swift index e1d3292c8..c9c503044 100644 --- a/Sources/App/AppDelegate.swift +++ b/Sources/App/AppDelegate.swift @@ -50,6 +50,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } } + private var shouldRefreshTitleSubscription = false + private var watchCommunicatorService: WatchCommunicatorService? func application( @@ -133,9 +135,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { #if targetEnvironment(macCatalyst) titleSubscription = manager.subscribeStatusItemTitle( - existing: titleSubscription, + existing: shouldRefreshTitleSubscription ? nil : titleSubscription, update: Current.macBridge.configureStatusItem(title:) ) + shouldRefreshTitleSubscription = false #endif } } @@ -400,12 +403,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate { name: SettingsStore.menuRelatedSettingDidChange, object: nil ) + NotificationCenter.default.addObserver( + self, + selector: #selector(apiDidConnect(_:)), + name: HomeAssistantAPI.didConnectNotification, + object: nil + ) } @objc private func menuRelatedSettingDidChange(_ note: Notification) { UIMenuSystem.main.setNeedsRebuild() } + @objc private func apiDidConnect(_ note: Notification) { + // When API reconnects, rebuild the menu to refresh the status item title subscription + // Force refresh by setting the flag that will cause the subscription to be recreated + #if targetEnvironment(macCatalyst) + shouldRefreshTitleSubscription = true + #endif + UIMenuSystem.main.setNeedsRebuild() + } + private func setupUIApplicationShortcutItems() { if Current.isCatalyst { UIApplication.shared.shortcutItems = [.init( diff --git a/Sources/App/Utilities/MenuManager.swift b/Sources/App/Utilities/MenuManager.swift index 15da6b6fd..4ec39925e 100644 --- a/Sources/App/Utilities/MenuManager.swift +++ b/Sources/App/Utilities/MenuManager.swift @@ -81,6 +81,9 @@ class MenuManager { return existing } + // Cancel the old subscription before creating a new one + existing?.cancel() + // if we know it's going to change, reset it for now so it doesn't show the old value update("")