winrt-notification
winrt-notification copied to clipboard
Actions support?
I'm interested in seeing this happen, and I'm not afraid to write code for it, but I don't really know anything about the toast API.
What I'm looking to be able to do is wait for the notification to be clicked on or dismissed; I don't mind doing that in a thread and blocking it until either condition occurs.
Can you suggest roughly what changes need to be made for this?
It's all callback/handler based. I'll take a look at it this weekend and see how hard it is to do, the windows crate is a bit more ergonomic than the version of the winrt crate that was being used.
Thanks, I appreciate your time!
Looked into it more. Two main problems, making toasts appear with actionable elements and having those elements do something. Not worried about the first problem, but I think the latter problem will take some experimentation to find a working solution.
The actions part of the toast xml schema is undocumented, but there's a MIT licensed C# toast implementation that's implemented everything So plodding through their code to find the schema and adding it to the builder in some form will fix that.
Making actions do anything is more annoying.
- requires a valid app id, the powershell workaround won't do.
- I'm not quite sure how to define the method signature it needs in rust, I suspect the windows crate has everything needed to do that, but stuff is hard to find. (paths and names aren't 1 to 1 in the bindings crate)
To make actions do anything you have set up a COM server.
From what I can see how it works:
- The application defines a method with a specific signature and registers it with windows.
- You create a toast with actions.
- A person clicks on the toast at some point.
- Using the toast app id, windows will find the application, (it can start it if it's not running)
- The application, by way of windows com, runs the Activate method defined in the registered INotificationActivationCallback.
- requires a valid app id, the powershell workaround won't do.
FWIW, I found that just calling SetCurrentProcessExplicitAppUserModelID was sufficient to let me use my own ID and have toasts attributed to it.
I don't know if that is good enough for actions to work though, however, I do also configure a shortcut in my installer: https://github.com/wez/wezterm/commit/3f91e30719d5fd30d808fe3af99c4dc509546a90
So I'm slightly less concerned about that side of things for the moment, although I recognize that it would be good if this crate could magically "just work" :-)
To make actions do anything you have set up a COM server.
I think some of the steps in that C++ example you shared may not be needed if we constrain this crate to working only within an already running process, rather than making it launch a process that may not be running.
I'm hoping that it's "just" a matter of making the rust equivalent of ToastEventHandler
(which is missing from that gist!), but if
CToastActivator
is also required: https://docs.microsoft.com/en-us/windows/win32/com/registering-a-running-exe-server suggests that all we need to do is register the activation class at runtime via CoRegisterClassObject
without forcing the creation of registry entries to register the COM server process.
I think the SetCurrentProcessExplicitAppUserModelID is working because you made the shortcut.
Searching for "ToastEventHandler" led me down a rabbit hole that led me to this example.
So made a gist that is a poc that shows we can have actions do things - provided the application is running. Which is a concession I think is worth taking as this would be way easier to expose through an api compared to the com stuff. https://gist.github.com/allenbenz/a0fb225aef43df4b1be1c005fb4c2811
Unexpectedly this works with the app id workaround, was ready to document how getting an installer going to make actions work was required.
So this is all pretty doable now.
Great news! And it doesn't look all that bad either!
Hi, was wondering if there is any progress/work/plans to work on this soon, I would like to help but I have no experience working with WinRT
@allenbenz Hi, sorry to bother you again, I have been working on adding action support for toast notifications and I made good progress. However, I just found out that someone already has an open pull request for this feature. Was wondering if you are busy these days and whether you have future plans maintaining this repo.