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

1 call of showToast() does not fire a Toast Notification, 2 calls of showToast() fires 2 Toast Notifications... #79

Open
rnewendyke opened this issue Aug 10, 2022 · 0 comments

Comments

@rnewendyke
Copy link

I am working with this library for the first time (am also new to c++) and am running into an issue where the recommended code for usage will not send a toast notification, but including a second line of

WinToast::instance()->showToast(templ, handler)

causes 2 toast notifications to fire. Trying to understand what the root cause of this is so that I can resolve the issue I am experiencing here...

Code I have been using and experiencing the issue with is below and my compiler is set for c++20:

int main() {
    if (!WinToast::isCompatible())
    {
        std::wcout << L"Error, your system in not supported!" << std::endl;
    }

    WinToast::instance()->setAppName(L"WinToastExample");
    const auto aumi = WinToast::configureAUMI(L"mohabouje", L"wintoast", L"wintoastexample", L"20161006");
    WinToast::instance()->setAppUserModelId(aumi);

    if (!WinToast::instance()->initialize())
    {
        std::wcout << L"Error, could not initialize the lib!" << std::endl;
    }

    CustomHandler* handler = new CustomHandler;
    WinToastTemplate templ = WinToastTemplate(WinToastTemplate::Text02);
    templ.setTextField(L"title", WinToastTemplate::FirstLine);
    templ.setTextField(L"subtitle", WinToastTemplate::SecondLine);

    WinToast::instance()->showToast(templ, handler) // when this line is commented out, 0 toast notifications fire when compiled exe is run, when this line is included, 2 toast notifications fire when compiled exe is run

    if (!WinToast::instance()->showToast(templ, handler))
    {
        std::wcout << L"Error: Could not launch your toast notification!" << std::endl;
    }
}

definition of customHandler for reference (copy/paste from WinToast/example/qt-gui-example/WinToastExample/mainwindow.cpp):

class CustomHandler : public IWinToastHandler {
public:
    void toastActivated() const {
        std::wcout << L"The user clicked in this toast" << std::endl;
    }

    void toastActivated(int actionIndex) const {
        std::wcout << L"The user clicked on button #" << actionIndex << L" in this toast" << std::endl;
    }

    void toastFailed() const {
        std::wcout << L"Error showing current toast" << std::endl;
    }
    void toastDismissed(WinToastDismissalReason state) const {
        switch (state) {
        case UserCanceled:
            std::wcout << L"The user dismissed this toast" << std::endl;
            break;
        case ApplicationHidden:
            std::wcout << L"The application hid the toast using ToastNotifier.hide()" << std::endl;
            break;
        case TimedOut:
            std::wcout << L"The toast has timed out" << std::endl;
            break;
        default:
            std::wcout << L"Toast not activated" << std::endl;
            break;
        }
    }
};

Any help that anyone can offer is greatly appreciated.

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

1 participant