Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
implement better notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
maltejur committed Jul 29, 2022
1 parent 3fa2e3f commit ef221d4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ find_package(Qt5 CONFIG REQUIRED COMPONENTS
WebEngineWidgets
)

find_package(KF5Notifications)

set(discord-screenaudio_SRC
src/main.cpp
src/mainwindow.cpp
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions assets/discord-screenaudio.notifyrc
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 18 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "mainwindow.h"
#include "virtmic.h"

#include <KNotification>
#include <QApplication>
#include <QColor>
#include <QComboBox>
Expand All @@ -11,6 +12,8 @@
#include <QSpacerItem>
#include <QThread>
#include <QUrl>
#include <QWebEngineNotification>
#include <QWebEngineProfile>
#include <QWebEngineScript>
#include <QWebEngineScriptCollection>
#include <QWebEngineSettings>
Expand All @@ -30,6 +33,21 @@ void MainWindow::setupWebView() {
m_webView = new QWebEngineView(this);
m_webView->setPage(page);

QWebEngineProfile::defaultProfile()->setNotificationPresenter(
[&](std::unique_ptr<QWebEngineNotification> 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);
}

Expand Down

0 comments on commit ef221d4

Please sign in to comment.