diff --git a/README.md b/README.md index 3238c11..41d11b9 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ The following Qt 5 modules are requried: core network gui widgets svg webenginew WebEngine. Currently any self-signed certificate is accepted! See: https://bugreports.qt.io/browse/QTBUG-51176 * Qt WebEngine can not be built with mingw-w64. +* QWebEngineView seems to eat `keyPressEvent`. * Qt WebEngine is more buggy in my experience. * Security issues are not a concern because no other website than the Syncthing web UI is shown. Any external links will be opened in the diff --git a/tray/gui/webviewdialog.cpp b/tray/gui/webviewdialog.cpp index ee587d5..35522e4 100644 --- a/tray/gui/webviewdialog.cpp +++ b/tray/gui/webviewdialog.cpp @@ -13,6 +13,7 @@ # include #elif defined(SYNCTHINGTRAY_USE_WEBKIT) # include +# include #endif using namespace Dialogs; @@ -50,6 +51,33 @@ void QtGui::WebViewDialog::applySettings(const Data::SyncthingConnectionSettings m_view->setZoomFactor(Settings::values().webView.zoomFactor); } +#if defined(SYNCTHINGTRAY_USE_WEBKIT) +bool WebViewDialog::isModalVisible() const +{ + if(m_view->page()->mainFrame()) { + return m_view->page()->mainFrame()->evaluateJavaScript(QStringLiteral("$('.modal-dialog').is(':visible')")).toBool(); + } + return false; +} +#endif + +void WebViewDialog::closeUnlessModalVisible() +{ +#if defined(SYNCTHINGTRAY_USE_WEBKIT) + if(!isModalVisible()) { + close(); + } +#elif defined(SYNCTHINGTRAY_USE_WEBENGINE) + m_view->page()->runJavaScript(QStringLiteral("$('.modal-dialog').is(':visible')"), [this] (const QVariant &modalVisible) { + if(!modalVisible.toBool()) { + close(); + } + }); +#else + close(); +#endif +} + void QtGui::WebViewDialog::closeEvent(QCloseEvent *event) { if(!Settings::values().webView.keepRunning) { @@ -65,6 +93,11 @@ void WebViewDialog::keyPressEvent(QKeyEvent *event) m_view->reload(); event->accept(); break; + case Qt::Key_Escape: + // FIXME: never called when using Qt WebEngine, hence close on ESC does not work yet + closeUnlessModalVisible(); + event->accept(); + break; default: QMainWindow::keyPressEvent(event); } diff --git a/tray/gui/webviewdialog.h b/tray/gui/webviewdialog.h index 8ef5db9..96df490 100644 --- a/tray/gui/webviewdialog.h +++ b/tray/gui/webviewdialog.h @@ -26,6 +26,10 @@ public: public slots: void applySettings(const Data::SyncthingConnectionSettings &connectionSettings); const Data::SyncthingConnectionSettings &settings() const; +#if defined(SYNCTHINGTRAY_USE_WEBKIT) + bool isModalVisible() const; +#endif + void closeUnlessModalVisible(); protected: void closeEvent(QCloseEvent *event);