-
Notifications
You must be signed in to change notification settings - Fork 402
Auto-reconnect local push on app foreground #4105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: bgoncal <[email protected]>
Co-authored-by: bgoncal <[email protected]>
There was a problem hiding this comment.
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 adds automatic reconnection for local push connections when the app returns to foreground, addressing an issue where connections sometimes fail to recover automatically and require manual toggling of the local push setting.
Key changes:
- Added
forceReconnect()method toLocalPushManagerthat bypasses webhookID change detection and forces subscription recreation - Implemented
reconnectAll()protocol method across allNotificationManagerLocalPushInterfaceimplementations with platform-specific behavior - Integrated automatic reconnection into the app lifecycle by calling
reconnectAll()asynchronously when entering foreground
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
Sources/Shared/Notifications/LocalPush/LocalPushManager.swift |
Added forceReconnect() method and modified updateSubscription() to accept a force parameter that bypasses webhookID change checks |
Sources/App/Notifications/NotificationManagerLocalPushInterface.swift |
Added reconnectAll() protocol method to support automatic reconnection |
Sources/App/Notifications/NotificationManagerLocalPushInterfaceDirect.swift |
Implemented reconnectAll() for macOS by directly calling forceReconnect() on each enabled server's manager |
Sources/App/Notifications/NotificationManagerLocalPushInterfaceExtension.swift |
Implemented reconnectAll() for iOS by triggering manager reload to restart the PushProvider extension |
Sources/App/Notifications/NotificationManagerLocalPushInterfaceUnsupported.swift |
Added no-op reconnectAll() implementation for unsupported platforms |
Sources/App/LifecycleManager.swift |
Integrated automatic reconnection by calling reconnectAll() asynchronously on utility queue during foreground transitions |
Tests/Shared/LocalPushManager.test.swift |
Added comprehensive unit test verifying forced reconnection behavior without webhookID changes |
| func reconnectAll() { | ||
| Current.Log.info("Triggering reconnection for all local push managers") | ||
| // For iOS, we reload managers which will ensure they're properly configured | ||
| // and trigger the PushProvider extension to reconnect if needed | ||
| reloadManagersAfterSave() | ||
| } |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reloadManagersAfterSave method performs asynchronous NEAppPushManager operations. If reconnectAll is called multiple times rapidly (e.g., if the app enters foreground repeatedly in quick succession), multiple concurrent calls to NEAppPushManager.loadAllFromPreferences could occur, potentially leading to race conditions when updating the managers dictionary and tokens array. Consider debouncing this call or using a serial queue to ensure operations complete before new ones begin.
Summary
Local push connections sometimes fail to recover automatically, requiring users to manually toggle the setting. This adds automatic reconnection when the app returns to foreground.
Changes:
LocalPushManager: AddedforceReconnect()method that cancels and recreates subscriptions, bypassing the webhookID change checkNotificationManagerLocalPushInterface: AddedreconnectAll()protocol method with platform-specific implementations:forceReconnect()on each enabled server's managerLifecycleManager: CallsreconnectAll()asynchronously on foreground transition using utility queue to avoid blocking UItestForceReconnect()verifying subscription cancellation and recreationScreenshots
N/A - Internal functionality change with no UI impact
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes
Reconnection is queued on background thread to prevent UI blocking during foreground transitions with multiple servers.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.