xan105 / node-powertoast

Windows toast notification and toastXml string builder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove a notification via code

3att3 opened this issue · comments

First of all thanks for this project, it is the best I could find with the buttons still working after the notification hides.

I want to know if there is a way to remove a notification from code?

I'm sending notifications from my phone to my computer and show the there. I want to remove a notification if the user removes the notification from the mobile phone. That means I can't use the callback option since it uses timer.

Sorry if this is a stupid question, I couldn't find anything in my search results.

The callback uses timer to be safe and it's poorly explained in my readme but if you have something else maintaining the event loop you can still have callback from notification that spawned way longer than the keep-a-live time frame (from my experience) ^^ but callback wouldn't help anyway since what you are trying to do is delete a toast on your computer via your phone.

What you need is a way to programmatically remove/delete a toast notification.
I never had the need to do that and I didn't see it mentioned in the Microsoft docs however a quick search on the subject lead me to ToastNotificationHistory Class

[Windows.UI.Notifications.ToastNotificationManager]::History.Clear('')

I'll have to play with this a bit and see what I can do with this (if can at all)

I've added named export to remove and list notification from the Action Center (readme was updated).
Here is a simple example:

import toast, { remove } from "powertoast";

const appID = "Microsoft.XboxApp_8wekyb3d8bbwe!Microsoft.XboxApp"; //Xbox app
await toast({appID: appID, uniqueID: "id0", title: "Hello", message: "World"});
await remove(appID,"id0");

NB: I don't know when I will upload next version to npm tbh (I'm planning a migration of my modules to ESM).
If you need it now you can install the "github" version by doing npm install https://github.com/xan105/node-powertoast.
Please note that's an ESM only module. Sorry for the inconvenience.

Wow, I wasn't expecting something that fast. Thanks for the solution!