Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Sources/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

private var shouldRefreshTitleSubscription = false

private var watchCommunicatorService: WatchCommunicatorService?

func application(
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions Sources/App/Utilities/MenuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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("")

Expand Down
Loading