Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanest Way to Hide Toast from IWinToastHandler #104

Open
joshorenberg opened this issue Jul 13, 2024 · 2 comments
Open

Cleanest Way to Hide Toast from IWinToastHandler #104

joshorenberg opened this issue Jul 13, 2024 · 2 comments

Comments

@joshorenberg
Copy link

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!

@mohabouje
Copy link
Owner

mohabouje commented Jul 31, 2024

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;

@joshorenberg
Copy link
Author

joshorenberg commented Jul 31, 2024

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();
}

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

No branches or pull requests

2 participants