From 6b8b31ebf69061f2f4d83f47e603b3b7804e256b Mon Sep 17 00:00:00 2001 From: zty199 <46324746+zty199@users.noreply.github.com> Date: Mon, 19 Dec 2022 09:40:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20UOS=20=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 网页通知获取依赖 QWebEngineNotification 类,在 Qt 5.13 引入 Log: 添加宏定义,判断 Qt 版本 >= 5.13 启用网页通知功能 --- spark-webapp-runtime/webengineview.cpp | 4 ++++ spark-webapp-runtime/webengineview.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/spark-webapp-runtime/webengineview.cpp b/spark-webapp-runtime/webengineview.cpp index b402ed5..f85e4ac 100644 --- a/spark-webapp-runtime/webengineview.cpp +++ b/spark-webapp-runtime/webengineview.cpp @@ -21,9 +21,11 @@ WebEngineView::WebEngineView(QWidget *parent) // page()->setUrlRequestInterceptor(interceptor); // page()->settings()->setAttribute(QWebEngineSettings::WebAttribute::LocalContentCanAccessRemoteUrls, true); page()->profile()->setHttpAcceptLanguage(QLocale::system().name()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)) page()->profile()->setNotificationPresenter([&](std::unique_ptr<QWebEngineNotification> notification) { WebEngineView::present(notification); }); +#endif }); } @@ -59,6 +61,7 @@ void WebEngineView::handleChromiumFlags() qDebug() << Q_FUNC_INFO << "QTWEBENGINE_CHROMIUM_FLAGS=" + qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"); } +#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)) void WebEngineView::present(std::unique_ptr<QWebEngineNotification> &newNotification) { qDebug() << Q_FUNC_INFO << "New notification received:" << newNotification->title() << newNotification->message(); @@ -93,3 +96,4 @@ void WebEngineView::present(std::unique_ptr<QWebEngineNotification> &newNotifica .hints(hints) .call(); } +#endif diff --git a/spark-webapp-runtime/webengineview.h b/spark-webapp-runtime/webengineview.h index bd075ff..46a7125 100644 --- a/spark-webapp-runtime/webengineview.h +++ b/spark-webapp-runtime/webengineview.h @@ -2,7 +2,9 @@ #define WEBENGINEVIEW_H #include <QWebEngineView> +#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)) #include <QWebEngineNotification> +#endif // class WebEngineUrlRequestInterceptor; class WebEngineView : public QWebEngineView @@ -13,7 +15,9 @@ public: explicit WebEngineView(QWidget *parent = nullptr); static void handleChromiumFlags(); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)) static void present(std::unique_ptr<QWebEngineNotification> &newNotification); +#endif private: // WebEngineUrlRequestInterceptor *interceptor = nullptr;