-
Notifications
You must be signed in to change notification settings - Fork 432
Add scope_exit cleanup to AppNotificationManager::Register #6242
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -130,7 +130,9 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation | |||||||||||||
| }) }; | ||||||||||||||
|
|
||||||||||||||
| winrt::guid registeredClsid{}; | ||||||||||||||
| if (AppModel::Identity::IsPackagedProcess()) | ||||||||||||||
| bool isUnpackaged{ !AppModel::Identity::IsPackagedProcess() }; | ||||||||||||||
|
|
||||||||||||||
| if (!isUnpackaged) | ||||||||||||||
| { | ||||||||||||||
| registeredClsid = RegisterPackagedApp(); | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -140,12 +142,23 @@ namespace winrt::Microsoft::Windows::AppNotifications::implementation | |||||||||||||
| registeredClsid = RegisterUnpackagedApp(assets); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Cleanup registration on failure of subsequent steps | ||||||||||||||
| auto registrationCleanup{ wil::scope_exit([&]() | ||||||||||||||
| { | ||||||||||||||
| if (isUnpackaged) | ||||||||||||||
| { | ||||||||||||||
| LOG_IF_FAILED(PushNotifications_UnregisterFullTrustApplication(m_appId.c_str())); | ||||||||||||||
| } | ||||||||||||||
|
||||||||||||||
| } | |
| } | |
| else if (!PushNotificationHelpers::IsPackagedAppScenario() && !WindowsAppRuntime::SelfContained::IsSelfContained()) | |
| { | |
| LOG_IF_FAILED(notificationPlatform->RemoveToastRegistrationMapping(m_appId.c_str())); | |
| } |
Copilot
AI
Feb 20, 2026
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 cleanup is incomplete. If RegisterComServer fails after RegisterUnpackagedApp succeeds, only PushNotifications_UnregisterFullTrustApplication is called. However, RegisterUnpackagedApp also creates other resources that need cleanup:
- COM server registry entries via GetOrCreateComActivatorGuid → RegisterComServer (lines 254, 260 in AppNotificationUtility.cpp)
- App identifier registry entries via RegisterAssets (line 256 in AppNotificationUtility.cpp)
- Toast registration mapping via RegisterAppNotificationSinkWithLongRunningPlatform (line 260)
Compare with UnregisterAll() (lines 333-338) which cleans up all these resources for unpackaged apps:
- Gets the COM activator GUID and calls UnRegisterComServer
- Calls UnRegisterNotificationAppIdentifierFromRegistry
- Calls PushNotifications_UnregisterFullTrustApplication
The cleanup lambda should perform all these cleanup steps, wrapped in LOG_IF_FAILED to handle cases where resources weren't created yet.
| { | |
| { | |
| // Mirror UnregisterAll() behavior for unpackaged apps: clean up COM server, | |
| // app identifier registry entries, and push notification registration. | |
| LOG_IF_FAILED(UnRegisterComServer(registeredClsid)); | |
| LOG_IF_FAILED(UnRegisterNotificationAppIdentifierFromRegistry(m_appId.c_str())); |
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 cleanup is incomplete. If RegisterComServer or m_waitHandleForArgs.create() fails after RegisterUnpackagedApp succeeds, only PushNotifications_UnregisterFullTrustApplication is called. However, RegisterUnpackagedApp also creates other resources that need cleanup:
Compare with UnregisterAll() (lines 333-338) which cleans up all these resources for unpackaged apps:
The cleanup lambda should perform all these cleanup steps, wrapped in LOG_IF_FAILED to handle cases where resources weren't created yet.