summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2021-10-25 13:51:12 +0200
committerSimon Rettberg2021-10-25 13:59:43 +0200
commit1e0ee56159ce0c11138c3dfd8c011ad33a86e8a8 (patch)
tree63b2f4490aeecad3d3b575611e06011797ef065f
parentAdd "Mobile" to User-Agent header for embedded browser (diff)
downloadslxgreeter-1e0ee56159ce0c11138c3dfd8c011ad33a86e8a8.tar.gz
slxgreeter-1e0ee56159ce0c11138c3dfd8c011ad33a86e8a8.tar.xz
slxgreeter-1e0ee56159ce0c11138c3dfd8c011ad33a86e8a8.zip
Webview: Use keyboard & mouse input to track inactivity
Using page loads to track inactivity breaks on SPA websites. Use user input instead.
-rw-r--r--src/webview.cpp28
-rw-r--r--src/webview.h8
2 files changed, 35 insertions, 1 deletions
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<QUrl> _urls;
QTimer *_timerAbortMessage;
bool _abortedDownload;
+ bool _inErrorState;
QString _token;
QTimer *_timerReset;
};