From 41427039904815063f29c79d68ce4064cacb311e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 10 Dec 2023 04:53:44 +0100 Subject: Try to make windows notifications prettier --- src/notifications/Manager.h | 6 ++++-- src/notifications/ManagerLinux.cpp | 3 ++- src/notifications/ManagerWin.cpp | 28 ++++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/notifications/Manager.h b/src/notifications/Manager.h index fbebfcba..0efc9445 100644 --- a/src/notifications/Manager.h +++ b/src/notifications/Manager.h @@ -93,8 +93,10 @@ public: #if defined(Q_OS_WINDOWS) private: - void - systemPostNotification(const QString &line1, const QString &line2, const QString &iconPath); + void systemPostNotification(const QString &line1, + const QString &line2, + const QString &iconPath, + const QString &bodyImagePath); #endif // these slots are platform specific (D-Bus only) diff --git a/src/notifications/ManagerLinux.cpp b/src/notifications/ManagerLinux.cpp index b181fdc3..11a7c1a1 100644 --- a/src/notifications/ManagerLinux.cpp +++ b/src/notifications/ManagerLinux.cpp @@ -114,7 +114,8 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if if (hasMarkup_) { if (hasImages_ && - mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image) { + (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image || + mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image)) { MxcImageProvider::download( QString::fromStdString(mtx::accessors::url(notification.event)) .remove(QStringLiteral("mxc://")), diff --git a/src/notifications/ManagerWin.cpp b/src/notifications/ManagerWin.cpp index 8d200abc..87c49e3c 100644 --- a/src/notifications/ManagerWin.cpp +++ b/src/notifications/ManagerWin.cpp @@ -13,6 +13,7 @@ #include "Cache.h" #include "EventAccessors.h" +#include "MxcImageProvider.h" #include "Utils.h" using namespace WinToastLib; @@ -34,9 +35,9 @@ init() { isInitialized = true; - WinToast::instance()->setAppName(L"Nheko"); WinToast::instance()->setAppUserModelId( WinToast::configureAUMI(L"NhekoReborn", L"in.nheko.Nheko")); + WinToast::instance()->setAppName(L"Nheko"); if (!WinToast::instance()->initialize()) std::wcout << "Your system is not compatible with toast notifications\n"; } @@ -61,20 +62,35 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if } return template_.arg(utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body); - }; + }(); auto iconPath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + room_name + "-room-avatar.png"; if (!icon.save(iconPath)) iconPath.clear(); - systemPostNotification(room_name, formatNotification(), iconPath); + if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image || + mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image) { + MxcImageProvider::download( + QString::fromStdString(mtx::accessors::url(notification.event)) + .remove(QStringLiteral("mxc://")), + QSize(200, 80), + [this, room_name, formatNotification, iconPath](QString, QSize, QImage, QString imgPath) { + if (imgPath.isEmpty()) + systemPostNotification(room_name, formatNotification, iconPath, ""); + else + systemPostNotification(room_name, formatNotification, iconPath, imgPath); + }); + } else { + systemPostNotification(room_name, formatNotification, iconPath, ""); + } } void NotificationsManager::systemPostNotification(const QString &line1, const QString &line2, - const QString &iconPath) + const QString &iconPath, + const QString &bodyImagePath) { if (!isInitialized) init(); @@ -85,6 +101,10 @@ NotificationsManager::systemPostNotification(const QString &line1, if (!iconPath.isNull()) templ.setImagePath(iconPath.toStdWString()); + if (!bodyImagePath.isNull()) + templ.setHeroImagePath(bodyImagePath.toStdWString(), true); + + templ.setAudioPath(WinToastTemplate::IM); WinToast::instance()->showToast(templ, new CustomHandler()); } -- cgit 1.4.1 From d116deedd79379c5ae683ab653d93d75348fa85e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 12 Dec 2023 03:30:25 +0100 Subject: Allow clicking notifications on Windows --- .gitlab-ci.yml | 1 + resources/AppxManifest.xml | 2 +- src/notifications/Manager.h | 4 +++- src/notifications/ManagerWin.cpp | 32 +++++++++++++++++++++++++------- 4 files changed, 30 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c28efe23..43fd49fa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,6 +16,7 @@ build-windows: variables: APPVEYOR_REPO_BRANCH: "${CI_COMMIT_REF_NAME}" APPVEYOR_REPO_COMMIT: "${CI_COMMIT_SHORT_SHA}" + CMAKE_BUILD_PARALLEL_LEVEL: 8 before_script: - mkdir -p hunter - Move-Item -Path hunter -Destination C:/hunter diff --git a/resources/AppxManifest.xml b/resources/AppxManifest.xml index b9a090e1..6951c3b7 100644 --- a/resources/AppxManifest.xml +++ b/resources/AppxManifest.xml @@ -26,7 +26,7 @@ uap10:RuntimeBehavior="packagedClassicApp" uap10:TrustLevel="mediumIL"> + Square44x44Logo="nheko.png" BackgroundColor="transparent" /> diff --git a/src/notifications/Manager.h b/src/notifications/Manager.h index 0efc9445..707a4fb3 100644 --- a/src/notifications/Manager.h +++ b/src/notifications/Manager.h @@ -93,7 +93,9 @@ public: #if defined(Q_OS_WINDOWS) private: - void systemPostNotification(const QString &line1, + void systemPostNotification(const QString &roomid, + const QString &eventid, + const QString &line1, const QString &line2, const QString &iconPath, const QString &bodyImagePath); diff --git a/src/notifications/ManagerWin.cpp b/src/notifications/ManagerWin.cpp index 87c49e3c..f1d3797b 100644 --- a/src/notifications/ManagerWin.cpp +++ b/src/notifications/ManagerWin.cpp @@ -21,10 +21,21 @@ using namespace WinToastLib; class CustomHandler : public IWinToastHandler { 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 toastFailed() const { std::wcout << L"Error showing current toast" << std::endl; } void toastDismissed(WinToastDismissalReason) const {} + + NotificationsManager *manager; + QString roomid; + QString eventid; }; namespace { @@ -53,6 +64,8 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if const QImage &icon) { 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] { const auto template_ = getMessageTemplate(notification); @@ -75,19 +88,24 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if QString::fromStdString(mtx::accessors::url(notification.event)) .remove(QStringLiteral("mxc://")), 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()) - systemPostNotification(room_name, formatNotification, iconPath, ""); + systemPostNotification( + roomid, eventid, room_name, formatNotification, iconPath, ""); else - systemPostNotification(room_name, formatNotification, iconPath, imgPath); + systemPostNotification( + roomid, eventid, room_name, formatNotification, iconPath, imgPath); }); } else { - systemPostNotification(room_name, formatNotification, iconPath, ""); + systemPostNotification(roomid, eventid, room_name, formatNotification, iconPath, ""); } } void -NotificationsManager::systemPostNotification(const QString &line1, +NotificationsManager::systemPostNotification(const QString &roomid, + const QString &eventid, + const QString &line1, const QString &line2, const QString &iconPath, const QString &bodyImagePath) @@ -106,7 +124,7 @@ NotificationsManager::systemPostNotification(const QString &line1, templ.setAudioPath(WinToastTemplate::IM); - WinToast::instance()->showToast(templ, new CustomHandler()); + WinToast::instance()->showToast(templ, new CustomHandler(this, roomid, eventid)); } // clang-format off -- cgit 1.4.1 From c67f301f8bb4f26566c442a646fb06d22c611b28 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 13 Dec 2023 14:59:55 +0100 Subject: Work around clazy claiming we connect a lambda --- .gitlab-ci.yml | 2 +- src/encryption/SelfVerificationStatus.cpp | 3 ++- src/timeline/RoomlistModel.cpp | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index da3a4813..57c360e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,7 +46,7 @@ build-clazy: TRAVIS_OS_NAME: linux before_script: - echo -e "\e[0Ksection_start:`date +%s`:install_deps[collapsed=true]\r\e[0K\e[1m\e[95mInstalling apk dependencies" - - apk add asciidoctor cmake cmark-dev gst-plugins-bad-dev gst-plugins-base-dev gstreamer-dev lmdb-dev lmdbxx nlohmann-json olm-dev openssl-dev qt6-qtbase-dev qt6-qtdeclarative-dev qt6-qtmultimedia-dev qt6-qtsvg-dev qt6-qttools-dev samurai spdlog-dev xcb-util-wm-dev zlib-dev ccache curl-dev libevent-dev meson clazy clang16 gcc musl-dev git re2-dev libsecret-dev clang16 + - apk add asciidoctor cmake cmark-dev gst-plugins-bad-dev gst-plugins-base-dev gstreamer-dev lmdb-dev lmdbxx nlohmann-json olm-dev openssl-dev qt6-qtbase-dev qt6-qtdeclarative-dev qt6-qtmultimedia-dev qt6-qtsvg-dev qt6-qttools-dev samurai spdlog-dev xcb-util-wm-dev zlib-dev ccache curl-dev libevent-dev meson clazy clang16 gcc musl-dev git re2-dev libsecret-dev - echo -e "\e[0Ksection_end:`date +%s`:install_deps\r\e[0K" script: - export PATH="/usr/lib/ccache:${PATH}" diff --git a/src/encryption/SelfVerificationStatus.cpp b/src/encryption/SelfVerificationStatus.cpp index 32e75c4f..b5549ca1 100644 --- a/src/encryption/SelfVerificationStatus.cpp +++ b/src/encryption/SelfVerificationStatus.cpp @@ -24,11 +24,12 @@ SelfVerificationStatus::SelfVerificationStatus(QObject *o) : QObject(o) { connect(ChatPage::instance(), &ChatPage::contentLoaded, this, [this] { + // We connect INSIDE a lambda, not A lambda... connect(cache::client(), &Cache::selfVerificationStatusChanged, this, &SelfVerificationStatus::invalidate, - Qt::UniqueConnection); + Qt::UniqueConnection); // clazy:exclude=lambda-unique-connection cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()}); }); diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index cdaa02ec..da639843 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -271,11 +271,13 @@ RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification) { if (!models.contains(room_id)) { // ensure we get read status updates and are only connected once + // WORKAROUND(Nico): This is not a lambda, but clazy on alpine currently doesn't + // believe us... connect(cache::client(), &Cache::roomReadStatus, this, &RoomlistModel::updateReadStatus, - Qt::UniqueConnection); + Qt::UniqueConnection); // clazy:exclude=lambda-unique-connection QSharedPointer newRoom(new TimelineModel(manager, room_id)); newRoom->setDecryptDescription(ChatPage::instance()->userSettings()->decryptSidebar()); @@ -529,11 +531,13 @@ RoomlistModel::sync(const mtx::responses::Sync &sync_) addRoom(qroomid); const auto &room_model = models.value(qroomid); + // WORKAROUND(Nico): This is not a lambda, but clazy on alpine currently doesn't + // believe us connect(room_model.data(), &TimelineModel::newCallEvent, ChatPage::instance()->callManager(), &CallManager::syncEvent, - Qt::UniqueConnection); + Qt::UniqueConnection); // clazy:exclude=lambda-unique-connection room_model->sync(room); -- cgit 1.4.1 From d372158dde5161d1fa2ad1e8d8026f7906d369f3 Mon Sep 17 00:00:00 2001 From: q234rty Date: Sat, 16 Dec 2023 18:04:15 +0800 Subject: Trigger less QEvent::ApplicationPaletteChange The event seems to be very expensive on certain platform theme plugins. Fixes #1639 --- src/MainWindow.cpp | 5 +++++ src/MainWindow.h | 3 +++ 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index b7834cba..a4a0eff0 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -201,9 +201,14 @@ NhekoFixupPaletteEventFilter::eventFilter(QObject *obj, QEvent *event) // reason?!? if (event->type() == QEvent::ChildAdded && obj->metaObject()->className() == QStringLiteral("QQuickRootItem")) { + QSet newWindows; for (const auto window : QGuiApplication::topLevelWindows()) { + newWindows.insert(window); + if (m_postedWindows.contains(window)) + continue; QGuiApplication::postEvent(window, new QEvent(QEvent::ApplicationPaletteChange)); } + m_postedWindows.swap(newWindows); } return false; } diff --git a/src/MainWindow.h b/src/MainWindow.h index c493b5b2..928446aa 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -45,6 +45,9 @@ public: } bool eventFilter(QObject *obj, QEvent *event) override; + +private: + QSet m_postedWindows; }; class MainWindow : public QQuickView -- cgit 1.4.1