dotMorten / WinUIEx

WinUI Extensions
https://dotmorten.github.io/WinUIEx
MIT License
572 stars 36 forks source link

Bug: When using WindowsEx class, closed application crashes on launch when activated from notification. #115

Closed nik9play closed 1 year ago

nik9play commented 1 year ago

If there is a WindowEx window in the project, the application that is not running crashes when the notification is clicked and also when the application is started with the argument ----AppNotificationActivated:.

When Native Code Debugging is enabled it gets me there: изображение

Seems like m_activatedEventArgs and m_waitHandleForArgs are null.

Looks like the window object does not even have to be created for the bug to happen. This happens in packaged in unpackaged modes.

I'm also created issue in WinAppSDK repo (https://github.com/microsoft/WindowsAppSDK/issues/3535) before I knew about the WindowEx bug.

nik9play commented 1 year ago

I think I've found the problem. When WebAuthenticator is initialized, it gets activated arguments:

изображение

However, as stated in the Microsoft docs (https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/notifications/app-notifications/app-notifications-quickstart?tabs=cs#step-3-register-to-handle-an-app-notification), you cannot call GetActivatedEventArgs() before the AppNotificationManager is registered. If OnAppCreation is commented out in the Init method, everything works fine.

Maybe we should make WebAuthenticator initialization optional or manual?

dotMorten commented 1 year ago

You cannot call GetActivatedEventArgs() before the AppNotificationManager is registered.

According to https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.appinstance.getactivatedeventargs?view=winrt-22621 you can call it before even App.xaml gets called and samples shows it called in the main method:

image

I think the above statement only applies if you use app notifications.