Cleanest Way to Hide Toast from IWinToastHandler
Hi I'm wondering what the cleanest way to hide a toast from a IWinToastHandler derived class is. I would like to be able to hide toasts after a certain amount of time; I assume you do this with WinToastTemplate::setExpiration and then you handle the expiration with WinToastDismissalReason::TimedOut in the CustomWinToastHandler::toastDismissed overrride function. Also I would like to hide toasts after clicking buttons and clicking the toast itself and this obviously falls under the same coding technique as the first. Thanks!
As you mentioned, the default mechanism to hide a toast after some time is setting the duration. When the user clicks the notification, Activated or Dismissed will be called. Can you explain what's missing?
virtual void toastActivated() const = 0;
virtual void toastActivated(int actionIndex) const = 0;
virtual void toastDismissed(WinToastDismissalReason state) const = 0;
virtual void toastFailed() const = 0;
Thanks for the response. I'm guessing you're referring to the overrides. I understand the library a lot better now through experimentation. What I was wondering though was what the best way to link the event handlers to my other class objects was. Right now I passed a pointer to the main screen object to the handler and then used that pointer to connect the handler with the rest of my code. Is this the best way to do things? I'm not super well versed in design patterns although I studied them a while back.
//toast creation
auto customWinToastHandler = new CustomWinToastHandler();
const auto toastID = WinToast::instance()->showToast(winToastTemplate, customWinToastHandler, &error);
customWinToastHandler->setToastID(toastType,toastID,this); //toastType as in the enum below, this pointer points to main screen object where I can interface with the rest of the program
//toast handler code only relevant parts shown
enum class ToastType { autoDismiss, stayInNotificationArea, updateToast };
class CustomWinToastHandler :
public IWinToastHandler
{
public:
void setToastID(ToastType toastType, INT64 toastID, ReplicatorMainScreen* mainScreen) { this->toastType = toastType; this->toastID = toastID; this->mainScreen = mainScreen; };
}
void CustomWinToastHandler::toastActivated(int actionIndex) const {
//mainScreen->updateStatus("The user clicked on button #" + QString::number(actionIndex));
if (toastType == ToastType::updateToast)
mainScreen->downloadInstallerFromToast();
}