Flow2: Poll for re-auth result upon WebFlowCredentialsDialog window activation
authorMichael Schuster <michael@schuster.ms>
Sat, 21 Dec 2019 02:52:51 +0000 (03:52 +0100)
committerMichael Schuster <48932272+misch7@users.noreply.github.com>
Tue, 24 Dec 2019 06:46:57 +0000 (07:46 +0100)
Since the default remote poll interval has been re-raised recently to 30 seconds,
the delay between clicking "Grant access" in the browser and fetch and showing success
in the dialog may seem erroneous to the users and tempt them to click "Re-open browser"
again, causing the whole login process to restart.

This commit implements an event handler to pass the dialog's window activation
event down to the Login Flow v2 widget, in order to allow it to poll earlier.

See previous commits for dependent implementation details.

Signed-off-by: Michael Schuster <michael@schuster.ms>
src/gui/creds/webflowcredentialsdialog.cpp
src/gui/creds/webflowcredentialsdialog.h
src/gui/wizard/flow2authwidget.cpp
src/gui/wizard/flow2authwidget.h

index 7a1485bd150d6505224152400eaf03f655972bb1..6d8b9473fc36e2bfa5618eb30f86fb26c99a7e14 100644 (file)
@@ -32,6 +32,9 @@ WebFlowCredentialsDialog::WebFlowCredentialsDialog(Account *account, bool useFlo
         _layout->addWidget(_flow2AuthWidget);
 
         connect(_flow2AuthWidget, &Flow2AuthWidget::urlCatched, this, &WebFlowCredentialsDialog::urlCatched);
+
+        // allow Flow2 page to poll on window activation
+        connect(this, &WebFlowCredentialsDialog::onActivate, _flow2AuthWidget, &Flow2AuthWidget::slotPollNow);
     } else {
         _webView = new WebView();
         _layout->addWidget(_webView);
@@ -87,6 +90,20 @@ void WebFlowCredentialsDialog::setError(const QString &error) {
     }
 }
 
+void WebFlowCredentialsDialog::changeEvent(QEvent *e)
+{
+    switch (e->type()) {
+    case QEvent::ActivationChange:
+        if(isActiveWindow())
+            emit onActivate();
+        break;
+    default:
+        break;
+    }
+
+    QDialog::changeEvent(e);
+}
+
 void WebFlowCredentialsDialog::slotShowSettingsDialog()
 {
     // bring window to top but slightly delay, to avoid being hidden behind the SettingsDialog
index 9885eef297e653085ca83bf2ba288fc8d69423b9..67775ff7b208580fc7b3d01c94d172b5db252e3a 100644 (file)
@@ -30,12 +30,14 @@ public:
 
 protected:
     void closeEvent(QCloseEvent * e) override;
+    void changeEvent(QEvent *) override;
 
 public slots:
     void slotShowSettingsDialog();
 
 signals:
     void urlCatched(const QString user, const QString pass, const QString host);
+    void onActivate();
 
 private:
     bool _useFlow2;
index c050a54d03a56ffc1ae25acd339cfb270674a94c..c26def167d38773ed9cf5b6b56e807f94a2d75f7 100644 (file)
@@ -55,6 +55,7 @@ Flow2AuthWidget::Flow2AuthWidget(Account *account, QWidget *parent)
 
     _asyncAuth.reset(new Flow2Auth(_account, this));
     connect(_asyncAuth.data(), &Flow2Auth::result, this, &Flow2AuthWidget::asyncAuthResult, Qt::QueuedConnection);
+    connect(this, &Flow2AuthWidget::pollNow, _asyncAuth.data(), &Flow2Auth::slotPollNow);
     _asyncAuth->start();
 }
 
@@ -112,4 +113,9 @@ void Flow2AuthWidget::slotCopyLinkToClipboard()
         QApplication::clipboard()->setText(_asyncAuth->authorisationLink().toString(QUrl::FullyEncoded));
 }
 
+void Flow2AuthWidget::slotPollNow()
+{
+    emit pollNow();
+}
+
 } // namespace OCC
index 7fe1844c1744298af4eae52746b1f8eae10e2793..c07805e605caec9fafb7bfa99e354381569cd9b7 100644 (file)
@@ -35,9 +35,11 @@ public:
 
 public Q_SLOTS:
     void asyncAuthResult(Flow2Auth::Result, const QString &user, const QString &appPassword);
+    void slotPollNow();
 
 signals:
     void urlCatched(const QString user, const QString pass, const QString host);
+    void pollNow();
 
 private:
     Account *_account;