add --notify-send
option
This commit is contained in:
parent
a0a2924796
commit
150fd4364e
@ -30,6 +30,9 @@ int main(int argc, char *argv[]) {
|
|||||||
QCommandLineOption degubOption("remote-debugging",
|
QCommandLineOption degubOption("remote-debugging",
|
||||||
"Open Chromium Remote Debugging on port 9222");
|
"Open Chromium Remote Debugging on port 9222");
|
||||||
parser.addOption(degubOption);
|
parser.addOption(degubOption);
|
||||||
|
QCommandLineOption notifySendOption(
|
||||||
|
"notify-send", "Use notify-send instead of QT/KF5 notifications");
|
||||||
|
parser.addOption(notifySendOption);
|
||||||
|
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
|
|
||||||
@ -46,7 +49,7 @@ int main(int argc, char *argv[]) {
|
|||||||
"--remote-debugging-port=9222 " +
|
"--remote-debugging-port=9222 " +
|
||||||
qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"));
|
qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"));
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w(parser.isSet(notifySendOption));
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
@ -24,9 +24,11 @@
|
|||||||
|
|
||||||
MainWindow *MainWindow::m_instance = nullptr;
|
MainWindow *MainWindow::m_instance = nullptr;
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
MainWindow::MainWindow(bool useNotifySend, QWidget *parent)
|
||||||
|
: QMainWindow(parent) {
|
||||||
assert(MainWindow::m_instance == nullptr);
|
assert(MainWindow::m_instance == nullptr);
|
||||||
MainWindow::m_instance = this;
|
MainWindow::m_instance = this;
|
||||||
|
m_useNotifySend = useNotifySend;
|
||||||
setupWebView();
|
setupWebView();
|
||||||
resize(1000, 700);
|
resize(1000, 700);
|
||||||
showMaximized();
|
showMaximized();
|
||||||
@ -40,13 +42,25 @@ void MainWindow::setupWebView() {
|
|||||||
m_webView = new QWebEngineView(this);
|
m_webView = new QWebEngineView(this);
|
||||||
m_webView->setPage(page);
|
m_webView->setPage(page);
|
||||||
|
|
||||||
#ifdef KNOTIFICATIONS
|
if (m_useKF5Notifications || m_useNotifySend)
|
||||||
QWebEngineProfile::defaultProfile()->setNotificationPresenter(
|
QWebEngineProfile::defaultProfile()->setNotificationPresenter(
|
||||||
[&](std::unique_ptr<QWebEngineNotification> notificationInfo) {
|
[&](std::unique_ptr<QWebEngineNotification> notificationInfo) {
|
||||||
KNotification *notification = new KNotification("discordNotification");
|
if (m_useNotifySend) {
|
||||||
|
auto title = notificationInfo->title();
|
||||||
|
auto message = notificationInfo->message();
|
||||||
|
auto image_path =
|
||||||
|
QString("/tmp/discord-screenaudio-%1.png").arg(title);
|
||||||
|
notificationInfo->icon().save(image_path);
|
||||||
|
QProcess::execute("notify-send",
|
||||||
|
{"--icon", image_path, "--app-name",
|
||||||
|
"discord-screenaudio", title, message});
|
||||||
|
} else if (m_useKF5Notifications) {
|
||||||
|
KNotification *notification =
|
||||||
|
new KNotification("discordNotification");
|
||||||
notification->setTitle(notificationInfo->title());
|
notification->setTitle(notificationInfo->title());
|
||||||
notification->setText(notificationInfo->message());
|
notification->setText(notificationInfo->message());
|
||||||
notification->setPixmap(QPixmap::fromImage(notificationInfo->icon()));
|
notification->setPixmap(
|
||||||
|
QPixmap::fromImage(notificationInfo->icon()));
|
||||||
notification->setDefaultAction("View");
|
notification->setDefaultAction("View");
|
||||||
connect(notification, &KNotification::defaultActivated,
|
connect(notification, &KNotification::defaultActivated,
|
||||||
[&, notificationInfo = std::move(notificationInfo)]() {
|
[&, notificationInfo = std::move(notificationInfo)]() {
|
||||||
@ -54,8 +68,8 @@ void MainWindow::setupWebView() {
|
|||||||
activateWindow();
|
activateWindow();
|
||||||
});
|
});
|
||||||
notification->sendEvent();
|
notification->sendEvent();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
#endif
|
|
||||||
|
|
||||||
setCentralWidget(m_webView);
|
setCentralWidget(m_webView);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class MainWindow : public QMainWindow {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(bool useNotifySend = false, QWidget *parent = nullptr);
|
||||||
static MainWindow *instance();
|
static MainWindow *instance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -25,6 +25,12 @@ private:
|
|||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
bool m_wasMaximized;
|
bool m_wasMaximized;
|
||||||
static MainWindow *m_instance;
|
static MainWindow *m_instance;
|
||||||
|
bool m_useNotifySend;
|
||||||
|
#ifdef KNOTIFICATIONS
|
||||||
|
bool m_useKF5Notifications = true;
|
||||||
|
#else
|
||||||
|
bool m_useKF5Notifications = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
|
void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user