implement better notifications
This commit is contained in:
parent
3fa2e3fa3c
commit
ef221d4574
5 changed files with 33 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
8
assets/discord-screenaudio.notifyrc
Normal file
8
assets/discord-screenaudio.notifyrc
Normal file
|
@ -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
|
|
@ -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(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "mainwindow.h"
|
||||
#include "virtmic.h"
|
||||
|
||||
#include <KNotification>
|
||||
#include <QApplication>
|
||||
#include <QColor>
|
||||
#include <QComboBox>
|
||||
|
@ -11,6 +12,8 @@
|
|||
#include <QSpacerItem>
|
||||
#include <QThread>
|
||||
#include <QUrl>
|
||||
#include <QWebEngineNotification>
|
||||
#include <QWebEngineProfile>
|
||||
#include <QWebEngineScript>
|
||||
#include <QWebEngineScriptCollection>
|
||||
#include <QWebEngineSettings>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue