Windows: Prevent potential "crash" in setApplicationBadge

In some circumstances our application badge code seems to throw an
exception. The issue is hard to reproduce but just catching the
exception should be enough to fall back to the "non-winrt" version of
the code.

Fixes: QTBUG-117091
Pick-to: 6.5
Change-Id: I61f4e59f7309e2bb47b50a6ca6f3099ed9cd0af1
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 6f995b5e246bd9cc56710fa9cebc6dbb7cb2b72f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Oliver Wolff 2024-04-12 11:42:43 +02:00 committed by Qt Cherry-pick Bot
parent c1b8f4aee6
commit 81395d94e9

View File

@ -625,12 +625,16 @@ void QWindowsIntegration::setApplicationBadge(qint64 number)
// We prefer the native BadgeUpdater API, that allows us to set a number directly,
// but it requires that the application has a package identity, and also doesn't
// seem to work in all cases on < Windows 11.
if (isWindows11 && qt_win_hasPackageIdentity()) {
using namespace winrt::Windows::UI::Notifications;
auto badgeXml = BadgeUpdateManager::GetTemplateContent(BadgeTemplateType::BadgeNumber);
badgeXml.SelectSingleNode(L"//badge/@value").NodeValue(winrt::box_value(winrt::to_hstring(number)));
BadgeUpdateManager::CreateBadgeUpdaterForApplication().Update(BadgeNotification(badgeXml));
return;
QT_TRY {
if (isWindows11 && qt_win_hasPackageIdentity()) {
using namespace winrt::Windows::UI::Notifications;
auto badgeXml = BadgeUpdateManager::GetTemplateContent(BadgeTemplateType::BadgeNumber);
badgeXml.SelectSingleNode(L"//badge/@value").NodeValue(winrt::box_value(winrt::to_hstring(number)));
BadgeUpdateManager::CreateBadgeUpdaterForApplication().Update(BadgeNotification(badgeXml));
return;
}
} QT_CATCH(...) {
// fall back to win32 implementation
}
#endif