From 1e0ee56159ce0c11138c3dfd8c011ad33a86e8a8 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 25 Oct 2021 13:51:12 +0200 Subject: Webview: Use keyboard & mouse input to track inactivity Using page loads to track inactivity breaks on SPA websites. Use user input instead. --- src/webview.cpp | 28 ++++++++++++++++++++++++++++ src/webview.h | 8 +++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/webview.cpp b/src/webview.cpp index 17a5261..802a5f8 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -29,6 +29,7 @@ WebView::WebView(QWidget* parent) : QWebView(parent), _timerAbortMessage(new QTimer(this)), _abortedDownload(false), + _inErrorState(false), _timerReset(new QTimer(this)) { this->setPage(new UaWebPage); @@ -63,6 +64,31 @@ QWebView* WebView::createWindow(QWebPage::WebWindowType) return this; } +void WebView::mousePressEvent(QMouseEvent* ev) +{ + QWebView::mousePressEvent(ev); + resetTimeout(); +} + +void WebView::keyPressEvent(QKeyEvent* ev) +{ + QWebView::keyPressEvent(ev); + resetTimeout(); +} + +void WebView::wheelEvent(QWheelEvent* ev) +{ + QWebView::wheelEvent(ev); + resetTimeout(); +} + +void WebView::resetTimeout() +{ + if (!_inErrorState) { + _timerReset->start(60000); + } +} + void WebView::unsupportedContent(QNetworkReply* rep) { _abortedDownload = true; @@ -87,9 +113,11 @@ void WebView::onLoadFinished(bool ok) { if (_abortedDownload || !ok) { _abortedDownload = false; + _inErrorState = true; _timerReset->start(10000); return; } + _inErrorState = false; auto user = this->page()->mainFrame()->documentElement().findFirst("#bwlp-username"); auto pass = this->page()->mainFrame()->documentElement().findFirst("#bwlp-password"); auto err = this->page()->mainFrame()->documentElement().findFirst("#bwlp-error"); diff --git a/src/webview.h b/src/webview.h index 79b4a64..a03d517 100644 --- a/src/webview.h +++ b/src/webview.h @@ -20,7 +20,12 @@ public: void reset(const QString baseUrl); protected: - QWebView *createWindow(QWebPage::WebWindowType); + QWebView *createWindow(QWebPage::WebWindowType) override; + void mousePressEvent(QMouseEvent*) override; + void keyPressEvent(QKeyEvent*) override; + void wheelEvent(QWheelEvent*) override; + + void resetTimeout(); signals: void triggerReset(const QString &message); @@ -37,6 +42,7 @@ private: QStack _urls; QTimer *_timerAbortMessage; bool _abortedDownload; + bool _inErrorState; QString _token; QTimer *_timerReset; }; -- cgit v1.2.3-55-g7522