Allow clicking notifications on Windows

This commit is contained in:
Nicolas Werner 2023-12-12 03:30:25 +01:00
parent 68114427a8
commit d116deedd7
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
4 changed files with 30 additions and 9 deletions

View file

@ -16,6 +16,7 @@ build-windows:
variables: variables:
APPVEYOR_REPO_BRANCH: "${CI_COMMIT_REF_NAME}" APPVEYOR_REPO_BRANCH: "${CI_COMMIT_REF_NAME}"
APPVEYOR_REPO_COMMIT: "${CI_COMMIT_SHORT_SHA}" APPVEYOR_REPO_COMMIT: "${CI_COMMIT_SHORT_SHA}"
CMAKE_BUILD_PARALLEL_LEVEL: 8
before_script: before_script:
- mkdir -p hunter - mkdir -p hunter
- Move-Item -Path hunter -Destination C:/hunter - Move-Item -Path hunter -Destination C:/hunter

View file

@ -26,7 +26,7 @@
uap10:RuntimeBehavior="packagedClassicApp" uap10:RuntimeBehavior="packagedClassicApp"
uap10:TrustLevel="mediumIL"> uap10:TrustLevel="mediumIL">
<uap:VisualElements DisplayName="Nheko" Description="Matrix client written in Qt" Square150x150Logo="nheko.png" <uap:VisualElements DisplayName="Nheko" Description="Matrix client written in Qt" Square150x150Logo="nheko.png"
Square44x44Logo="nheko.png" BackgroundColor="#ffffff00" /> Square44x44Logo="nheko.png" BackgroundColor="transparent" />
<Extensions> <Extensions>
<uap:Extension Category="windows.protocol"> <uap:Extension Category="windows.protocol">
<uap:Protocol Name="matrix"> <uap:Protocol Name="matrix">

View file

@ -93,7 +93,9 @@ public:
#if defined(Q_OS_WINDOWS) #if defined(Q_OS_WINDOWS)
private: private:
void systemPostNotification(const QString &line1, void systemPostNotification(const QString &roomid,
const QString &eventid,
const QString &line1,
const QString &line2, const QString &line2,
const QString &iconPath, const QString &iconPath,
const QString &bodyImagePath); const QString &bodyImagePath);

View file

@ -21,10 +21,21 @@ using namespace WinToastLib;
class CustomHandler : public IWinToastHandler class CustomHandler : public IWinToastHandler
{ {
public: public:
void toastActivated() const {} CustomHandler(NotificationsManager *manager_, const QString &roomid_, const QString &eventid_)
: manager(manager_)
, roomid(roomid_)
, eventid(eventid_)
{
}
void toastActivated() const { manager->notificationClicked(roomid, eventid); }
void toastActivated(int) const {} void toastActivated(int) const {}
void toastFailed() const { std::wcout << L"Error showing current toast" << std::endl; } void toastFailed() const { std::wcout << L"Error showing current toast" << std::endl; }
void toastDismissed(WinToastDismissalReason) const {} void toastDismissed(WinToastDismissalReason) const {}
NotificationsManager *manager;
QString roomid;
QString eventid;
}; };
namespace { namespace {
@ -53,6 +64,8 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif
const QImage &icon) const QImage &icon)
{ {
const auto room_name = QString::fromStdString(cache::singleRoomInfo(notification.room_id).name); const auto room_name = QString::fromStdString(cache::singleRoomInfo(notification.room_id).name);
auto roomid = QString::fromStdString(notification.room_id);
auto eventid = QString::fromStdString(mtx::accessors::event_id(notification.event));
auto formatNotification = [this, notification] { auto formatNotification = [this, notification] {
const auto template_ = getMessageTemplate(notification); const auto template_ = getMessageTemplate(notification);
@ -75,19 +88,24 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif
QString::fromStdString(mtx::accessors::url(notification.event)) QString::fromStdString(mtx::accessors::url(notification.event))
.remove(QStringLiteral("mxc://")), .remove(QStringLiteral("mxc://")),
QSize(200, 80), QSize(200, 80),
[this, room_name, formatNotification, iconPath](QString, QSize, QImage, QString imgPath) { [this, roomid, eventid, room_name, formatNotification, iconPath](
QString, QSize, QImage, QString imgPath) {
if (imgPath.isEmpty()) if (imgPath.isEmpty())
systemPostNotification(room_name, formatNotification, iconPath, ""); systemPostNotification(
roomid, eventid, room_name, formatNotification, iconPath, "");
else else
systemPostNotification(room_name, formatNotification, iconPath, imgPath); systemPostNotification(
roomid, eventid, room_name, formatNotification, iconPath, imgPath);
}); });
} else { } else {
systemPostNotification(room_name, formatNotification, iconPath, ""); systemPostNotification(roomid, eventid, room_name, formatNotification, iconPath, "");
} }
} }
void void
NotificationsManager::systemPostNotification(const QString &line1, NotificationsManager::systemPostNotification(const QString &roomid,
const QString &eventid,
const QString &line1,
const QString &line2, const QString &line2,
const QString &iconPath, const QString &iconPath,
const QString &bodyImagePath) const QString &bodyImagePath)
@ -106,7 +124,7 @@ NotificationsManager::systemPostNotification(const QString &line1,
templ.setAudioPath(WinToastTemplate::IM); templ.setAudioPath(WinToastTemplate::IM);
WinToast::instance()->showToast(templ, new CustomHandler()); WinToast::instance()->showToast(templ, new CustomHandler(this, roomid, eventid));
} }
// clang-format off // clang-format off