Skip to content

feat(notifications): show notifications in a menu - #1194

Open
amnweb wants to merge 8 commits into
mainfrom
feat/notifications-menu
Open

amnweb wants to merge 8 commits into
mainfrom
feat/notifications-menu

Conversation

@amnweb

@amnweb amnweb commented Oct 23, 2026

Copy link
Copy Markdown
Owner

This replaces #1070 with a smaller version built on the same idea, so the notifications widget can show what Windows holds instead of only a count. A lot of it is based on @esershnr's work in #1070, so he is credited as co-author.

The widget opens a menu with the notifications Windows holds, grouped
by app, instead of only showing a count. Based on #1070 by Eser Şahiner.

- The list comes from UserNotificationListener. Launch, activation type,
  pictures, attribution and displayTimestamp come from each app's toast
  history, matched to the list by text since the history has no ids.
- Pictures follow the toast schema: appLogoOverride (48 px, round with
  hint-crop="circle"), hero (364:180) and inline. The image of the
  Windows 8 ToastImageAndText templates is the logo. Only local files
  are read (file:///, ms-appx, ms-appdata local), nothing is downloaded.
- A click opens protocol links, hands other toasts to the app's toast
  activator (registry CustomActivator or the Start menu shortcut's
  ToastActivatorCLSID) out of process, or brings the app forward.
- Clear uses ToastNotificationHistory.Clear(appId) per app, then removes
  what is left with RemoveNotification. Clear(appId) is documented only
  for apps in the caller's own package but works across apps, and
  ClearNotifications() fails without package identity.
- {count} shows 9+ above nine: Windows counts 21 notifications per app
  but hands other apps 20, so an exact count can exceed the menu.
- App icons fall back to the IconUri an AUMID registers, for senders
  shell:AppsFolder doesn't list (Firefox, Windows system toasts).
- callbacks.on_left now defaults to toggle_menu.

Known limitation: while Firefox runs, it ignores an activator call for a
notification from its own session and only reacts to the click Windows
raises inside its process, so those clicks open nothing.

Co-authored-by: Eser Şahiner <7672024+esershnr@users.noreply.github.com>
@esershnr

Copy link
Copy Markdown

Thanks for this, I've been running it on Windows 11 25H2 and it works well. Two things I noticed with WhatsApp:

Order. A WhatsApp message arrived after a Snipping Tool screenshot notification. The Notification Center shows the WhatsApp one at the top, but the YASB menu puts the WhatsApp group below the Snipping Tool group (screenshot below). My branch (#1070) does the same, so it isn't specific to this PR. I haven't found the cause yet.

Clicking. Clicking the WhatsApp notification only brings up the WhatsApp home screen, it doesn't open the sender's chat. WhatsApp (the Store/MSIX app) declares its toast activator in its AppxManifest.xml (ToastNotificationActivation / ToastActivatorCLSID), while _find_activator only looks at the registry and the Start menu shortcut. So no activator is found and it falls back to showing the app. In my branch I also read the package manifest, and there clicking the notification opens the chat. I can send a patch for that if you want it.

3

@amnweb

amnweb commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

The order should be fixed now. return _read_items(reversed(list(notifications))) is wrong. We need to sort by creation_time.

As for WhatsApp, I don't have it installed, so I can't test it. But if you have a solution, please send a PR for this branch.

…ivator

fix(notifications): open WhatsApp chats and show sender photos
@amnweb

amnweb commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Okay, PR #1194 is merged, so we've now fixed the issue with apps like WhatsApp, and the notification order is also working correctly. As far as I know, Firefox is the only issue left ?

@esershnr

Copy link
Copy Markdown

Yes, as far as I can tell Firefox is the only one left. I tested it with https://www.bennish.net/web-notifications.html: with Firefox running, clicking in the YASB menu doesn't reach the page (no click or close event on the site), while clicking the same notification in the Notification Center does.

One more Firefox thing: Firefox writes the notification image to %TEMP%\notificationimages\<guid>.png and deletes it when it exits, while the toast stays and still points at that file. So after closing Firefox the image disappears from the menu. Copying the image while it exists would fix it, but that means keeping a small cache, so I'm not sure it's worth it here.

@amnweb

amnweb commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

No, we really don't need to copy Firefox images. This browser is basically dead. There are so many bugs with the Media API, and now this... so it's fine.

There's one thing I missed when I merged it. _manifest_activator takes the first ToastNotificationActivation it finds anywhere in the manifest. A package can hold several apps, though, and each <Application> declares its own activator. The part of the AUMID after ! says which <Application> to use.

Spotify shows the problem: …!SpotifyLauncher declares 18A68F64… but gets Spotify's 5F86DC52…. SpotifyCli and Widget declare no activator at all, and they get Spotify's too, instead of just opening the app. WhatsApp has only one app probably, so it isn't affected.

I'll push a small fix that matches the Application Id.

Look up the app of each notification once instead of on every refresh.
@esershnr

Copy link
Copy Markdown

I looked into the Firefox click issue with AI, reading Firefox's source, so take this as a summary rather than something I verified line by line.

Short version: it can't really be fixed on our side.

  • When you click in the Notification Center, Windows tells the running Firefox directly, and Firefox handles the click from that.
  • When we click from YASB, we can only go through Firefox's COM activator. It passes the click to the running Firefox, but Firefox sees that it knows this notification and skips it, expecting Windows' direct signal to handle it. That signal never comes, because only Windows can send it.
  • When Firefox is closed, the new instance doesn't know the notification, so it takes the fallback path and the click works.

The image is similar: Firefox deletes the temp image file when it closes or drops the notification, by design.

So both would need a change in Firefox itself. Fine to leave it as is.

A package can hold several apps, each with its own activator in the
manifest. Use the one under the matching Application Id instead of the
first one in the file.
@amnweb

amnweb commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

I looked into the Firefox click issue with AI, reading Firefox's source, so take this as a summary rather than something I verified line by line.

https://searchfox.org/firefox-main/source/toolkit/mozapps/notificationserver/docs/index.md It' a Firefox always does things differently and makes them worse instead of following standards. It's still my default browser, but it's bad, and that's a fact.
The only thing you can do is reverse-engineer it to find some unstable COM interfaces that could handle Firefox specifically, and I'm not sure that's something we need here.

By the way, when you have time, test all of this again with WhatsApp. I've added some notification ID caching, which saves a lot of time when there are many notifications and makes everything much faster. I've also fixed the AUMID names.

@esershnr

Copy link
Copy Markdown

Tested the latest commits with WhatsApp, everything works:

  • Sender photos show up, and clicking a notification opens the right chat.
  • Order is correct with a lot of notifications (9+), and the menu stays fast.
  • Grouping with "N more", dismissing single notifications and "Clear all" all work.

One small thing, not important: when one person sends several messages, the Notification Center shows "7 unread messages" under the last one. That line isn't shown in the menu, I think because WhatsApp puts it in a separate group in the toast rather than in the main text. Fine to leave it.

YASB menu and the Notification Center:

10 11

@amnweb

amnweb commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

It’s almost certainly part of WhatsApp’s own toast XML, https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-group

<binding template="ToastGeneric">
  <text>Sender</text>
  <text>Last message</text>
  <group>
    <subgroup>
      <text>10 unread messages</text>
    </subgroup>
  </group>
</binding>

we only read the <text> elements directly under <binding>. Text inside a <group> is never read, so that line never reaches the menu.

But what I need to know is, does Windows group these into a single notification item, or does it just show the text? Or is this something WhatsApp handles internally, where the app automatically replaces the notification items?

@amnweb

amnweb commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

We also missed this https://learn.microsoft.com/en-us/windows/win32/api/notificationactivationcallback/nf-notificationactivationcallback-inotificationactivationcallback-activate, which lets you reply to chats directly from notification items. But let's leave that for now, and I'll implement it later because we'll probably switch to QtQuick very soon, and everything we've built here won't work anymore. Once we switch, we'll move all of this over, and we should be able to handle it better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants