summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-12-10 04:53:44 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2023-12-11 03:11:58 +0100
commit41427039904815063f29c79d68ce4064cacb311e (patch)
tree702125d1dd235c0b4c95211758e321e675347772 /src
parentFix joined spaces having no description (diff)
downloadnheko-41427039904815063f29c79d68ce4064cacb311e.tar.xz
Try to make windows notifications prettier
Diffstat (limited to 'src')
-rw-r--r--src/notifications/Manager.h6
-rw-r--r--src/notifications/ManagerLinux.cpp3
-rw-r--r--src/notifications/ManagerWin.cpp28
3 files changed, 30 insertions, 7 deletions
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 &notif
 
     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 &notif
         }
 
         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());
 }