WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

ToastNotificationManagerCompat.OnActivated not triggered if MAUI app not running

Open chrfin opened this issue 2 years ago • 7 comments

Describe the bug

Using .NET MAUI (preview 11) the ToastNotificationManagerCompat.OnActivated event is not triggered if a toast is clicked when the app is not running. The app is started and ToastNotificationManagerCompat.WasCurrentProcessToastActivated() returns true, but the event does not trigger. If the app is already running everything works fine.

Regression

No response

Reproducible in sample app?

  • [ ] This bug can be reproduced in the sample app.

Steps to reproduce

Create a .NET MAUI app and add toast-notifications like described in the docs:
https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast?tabs=desktop-msix

Then open a toast notification and leave it in the action center, close the app and then click the toast:
The app opens but no event is triggered.

Expected behavior

The app opens and the ToastNotificationManagerCompat.OnActivated event is triggered.

Screenshots

No response

Windows Build Number

  • [ ] Windows 10 1809 (Build 17763)
  • [ ] Windows 10 1903 (Build 18362)
  • [ ] Windows 10 1909 (Build 18363)
  • [ ] Windows 10 2004 (Build 19041)
  • [ ] Windows 10 20H2 (Build 19042)
  • [ ] Windows 10 21H1 (Build 19043)
  • [ ] Windows 11 21H2 (Build 22000)
  • [X] Other (specify)

Other Windows Build number

Windows 10 21H2 (Build 19044)

App minimum and target SDK version

  • [ ] Windows 10, version 1809 (Build 17763)
  • [X] Windows 10, version 1903 (Build 18362)
  • [ ] Windows 10, version 1909 (Build 18363)
  • [X] Windows 10, version 2004 (Build 19041)
  • [ ] Other (specify)

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

Version 17.1.0 Preview 2.0

Device form factor

Desktop

Nuget packages

Additional context

The app is also registered to a WNS notifications channel via Azure Notification Hub and they also only work if the app is already running, as there is no background activation available in WinUI 3 1.0 afaik (see also my question here: https://github.com/microsoft/WindowsAppSDK/discussions/1956)

Help us help you

Yes, but only if others can assist.

chrfin avatar Jan 09 '22 18:01 chrfin

Hello chrfin, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Jan 09 '22 18:01 ghost

Looping in .NET MAUI, for awareness: @jsuarezruiz

XAML-Knight avatar Jan 10 '22 22:01 XAML-Knight

Adding @andrewleader for notifications, FYI @brminnick too

michael-hawker avatar Jan 13 '22 18:01 michael-hawker

@VladislavAntonyuk FYI

brminnick avatar Jan 13 '22 20:01 brminnick

I am getting the same issue, but it is not a MAUI app.

Mine is a .Net desktop app targetting .Net 4.8. The issue occurs when the app is deployed using click once app. But in all other respects my behaviour is identical.

Sorry looks like mine is the same as this one https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4359. But maybe they are both the same issue?

gwynjudd avatar Dec 01 '22 23:12 gwynjudd

For .NET 5+ apps (like MAUI apps), The Windows App SDK team has added (toast) app notifications to the Windows App SDK, and using that would be the recommended approach going forward: https://learn.microsoft.com/windows/apps/windows-app-sdk/notifications/app-notifications/app-notifications-quickstart?tabs=cs

Over time, the Community Toolkit's ToastNotificationManagerCompat will likely be deprecated in favor of WinAppSDK's AppNotificationManager.

As for .NET 4.8, unfortunately I'm not sure the teams are going to be able to investigate this for ToastNotificationManagerCompat. But the code is open source in this repository, so if someone does figure out a fix and submit a pull request, that could be reviewed and accepted.

andrewleader avatar Dec 05 '22 17:12 andrewleader

I could not install the nuget package to my .NET 4.8 WPF project.

Could not install package 'Microsoft.Toolkit.Uwp.UI 7.1.3'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.8', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

seejessicacode avatar Mar 27 '23 17:03 seejessicacode