feat: ISSUE #I62BVT 添加网页通知功能

WebEngineView 中添加 WebEngineView::present(std::unique_ptr<QWebEngineNotification> &newNotification) 函数,通过 DNotifySender 转发系统通知

Log: 添加网页通知功能,通知图片缓存在 /tmp 下;使用 DLogManager 生成日志;修复强制使用 DTK 平台插件异常问题
This commit is contained in:
zty199
2022-12-19 02:26:07 +08:00
parent fa54612642
commit faa613d671
11 changed files with 179 additions and 26 deletions

View File

@@ -1,13 +1,17 @@
#include "webengineview.h"
//#include "webengineurlrequestinterceptor.h"
#include "application.h"
#include <DGuiApplicationHelper>
#include <DNotifySender>
#include <QWebEngineSettings>
#include <QWebEngineProfile>
#include <QLocale>
#include <QFileInfo>
DGUI_USE_NAMESPACE
DCORE_USE_NAMESPACE
WebEngineView::WebEngineView(QWidget *parent)
: QWebEngineView(parent)
@@ -17,6 +21,9 @@ WebEngineView::WebEngineView(QWidget *parent)
// page()->setUrlRequestInterceptor(interceptor);
// page()->settings()->setAttribute(QWebEngineSettings::WebAttribute::LocalContentCanAccessRemoteUrls, true);
page()->profile()->setHttpAcceptLanguage(QLocale::system().name());
page()->profile()->setNotificationPresenter([&](std::unique_ptr<QWebEngineNotification> notification) {
WebEngineView::present(notification);
});
});
}
@@ -51,3 +58,38 @@ void WebEngineView::handleChromiumFlags()
qDebug() << Q_FUNC_INFO << "QTWEBENGINE_CHROMIUM_FLAGS=" + qgetenv("QTWEBENGINE_CHROMIUM_FLAGS");
}
void WebEngineView::present(std::unique_ptr<QWebEngineNotification> &newNotification)
{
qDebug() << Q_FUNC_INFO << "New notification received:" << newNotification->title() << newNotification->message();
QImage image = newNotification->icon();
QString tmpDir = qobject_cast<Application *>(qApp)->mainWindow()->tmpDir();
QString appIcon = tmpDir + "/" + "icon.png";
if (QFileInfo::exists(appIcon)) {
QFile::remove(appIcon);
}
image.save(appIcon, "PNG");
QString summary = newNotification->title();
QString appName = qobject_cast<Application *>(qApp)->mainWindow()->title();
QString appBody = newNotification->message();
quint32 replaceId = 0;
int timeOut = 3000;
QStringList actions = QStringList() << "view" << QObject::tr("View");
QString launchCmd = qobject_cast<Application *>(qApp)->launchParams().join(",");
qDebug() << launchCmd;
QVariantMap hints;
hints.insert("x-deepin-action-view", launchCmd);
DUtil::DNotifySender(summary)
.appName(appName)
.appIcon(appIcon)
.appBody(appBody)
.replaceId(replaceId)
.timeOut(timeOut)
.actions(actions)
.hints(hints)
.call();
}