From ef221d4574bf473a2a06783a9d5af771221c8bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20J=C3=BCrgens?= Date: Fri, 29 Jul 2022 16:08:19 +0200 Subject: [PATCH] implement better notifications --- CMakeLists.txt | 5 ++++- README.md | 4 ++-- assets/discord-screenaudio.notifyrc | 8 ++++++++ src/main.cpp | 1 + src/mainwindow.cpp | 18 ++++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 assets/discord-screenaudio.notifyrc diff --git a/CMakeLists.txt b/CMakeLists.txt index 2946acd..441ae56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ find_package(Qt5 CONFIG REQUIRED COMPONENTS WebEngineWidgets ) +find_package(KF5Notifications) + set(discord-screenaudio_SRC src/main.cpp src/mainwindow.cpp @@ -50,10 +52,11 @@ add_subdirectory(submodules/rohrkabel) add_executable(discord-screenaudio ${discord-screenaudio_SRC}) -target_link_libraries(discord-screenaudio Qt5::Widgets Qt5::WebEngineWidgets rohrkabel) +target_link_libraries(discord-screenaudio Qt5::Widgets Qt5::WebEngineWidgets KF5::Notifications rohrkabel) install(TARGETS discord-screenaudio DESTINATION bin) install(FILES assets/de.shorsh.discord-screenaudio.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps) install(PROGRAMS assets/de.shorsh.discord-screenaudio.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) configure_file(assets/de.shorsh.discord-screenaudio.metainfo.xml.in de.shorsh.discord-screenaudio.metainfo.xml) install(FILES ${CMAKE_BINARY_DIR}/de.shorsh.discord-screenaudio.metainfo.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/metainfo) +install(FILES assets/discord-screenaudio.notifyrc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/knotifications5) diff --git a/README.md b/README.md index 08b199f..bbe34b2 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,12 @@ You have multiple options: - Basic building tools - CMake -- Qt5 and QtWebEngine +- Qt5, QtWebEngine and Kf5Notifications - **PipeWire** (it currently doesn't work with PulseAudio) - Git On Debian: -`apt install -y build-essential cmake qtbase5-dev qtwebengine5-dev pkg-config libpipewire-0.3-dev git` +`apt install -y build-essential cmake qtbase5-dev qtwebengine5-dev libkf5notifications-dev pkg-config libpipewire-0.3-dev git` ### Building diff --git a/assets/discord-screenaudio.notifyrc b/assets/discord-screenaudio.notifyrc new file mode 100644 index 0000000..6b1f1c1 --- /dev/null +++ b/assets/discord-screenaudio.notifyrc @@ -0,0 +1,8 @@ +[Global] +IconName=de.shorsh.discord-screenaudio +Name=discord-screenaudio +DesktopEntry=de.shorsh.discord-screenaudio.desktop + +[Event/discordNotification] +Name=Discord Notification +Action=Popup diff --git a/src/main.cpp b/src/main.cpp index 73fd86a..d666ba6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ int main(int argc, char *argv[]) { QApplication::setWindowIcon( QIcon(":assets/de.shorsh.discord-screenaudio.png")); QApplication::setApplicationVersion(DISCORD_SCEENAUDIO_VERSION_FULL); + QApplication::setDesktopFileName("de.shorsh.discord-screenaudio"); QCommandLineParser parser; parser.setApplicationDescription( diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4b34f83..ec55e18 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include "virtmic.h" +#include #include #include #include @@ -11,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -30,6 +33,21 @@ void MainWindow::setupWebView() { m_webView = new QWebEngineView(this); m_webView->setPage(page); + QWebEngineProfile::defaultProfile()->setNotificationPresenter( + [&](std::unique_ptr notificationInfo) { + KNotification *notification = new KNotification("discordNotification"); + notification->setTitle(notificationInfo->title()); + notification->setText(notificationInfo->message()); + notification->setPixmap(QPixmap::fromImage(notificationInfo->icon())); + notification->setDefaultAction("View"); + connect(notification, &KNotification::defaultActivated, + [&, notificationInfo = std::move(notificationInfo)]() { + notificationInfo->click(); + activateWindow(); + }); + notification->sendEvent(); + }); + setCentralWidget(m_webView); }