mohabouje / WinToast

WinToast is a lightly library written in C++ which brings a complete integration of the modern toast notifications of Windows 8 & Windows 10. Toast notifications allows your app to inform the users about relevant information and timely events that they should see and take action upon inside your app, such as a new instant message, a new friend request, breaking news, or a calendar event.
MIT License
687 stars 127 forks source link

WinToast Library Creates Shortcut in Start Menu #106

Closed joshorenberg closed 1 month ago

joshorenberg commented 1 month ago

Hi every time I initialize WinToast using the sample initialization code from Shao Voon Wong's codeproject.com writeup it creates a shortcut in the start menu to the program exe. In my opinion this is undesirable behavior. Is there a way around this? Thanks! Sample code below.

void Replicator::initToast()
{
    WinToast::WinToastError error;
    WinToast::instance()->setAppName(L"Program");
    const auto aumi = WinToast::configureAUMI
    (L"Program", L"Program", L"Program", L"1.5.0");
    WinToast::instance()->setAppUserModelId(aumi);

    if (!WinToast::instance()->initialize(&error))
        emit updateStatus(StatusType::error, "Failed to initialize WinToast: " + QString::number(int(error)));
}
joshorenberg commented 1 month ago

Solution is: WinToast::instance()->setShortcutPolicy(WinToast::SHORTCUT_POLICY_IGNORE);

ChristianGalla commented 1 month ago

Without a valid shortcut including a special property installed in the Start screen or in All Programs, you cannot raise a toast notification from a desktop app. This library ensures a valid shortcut exists.

However, Microsoft recommends creating the shortcut through an installer and not through application code.

https://learn.microsoft.com/en-us/windows/win32/shell/enable-desktop-toast-with-appusermodelid

mohabouje commented 1 month ago

I'm closing this issue. As @ChristianGalla said, the library will attempt to create a valid shortcut by default. If your application provides a valid shortcut, the policy can be changed to avoid this step.