Flow2: Poll for auth result upon account setup wizard window activation
authorMichael Schuster <michael@schuster.ms>
Fri, 20 Dec 2019 03:05:39 +0000 (04:05 +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 wizard 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 wizard's window activation
event down to the Login Flow v2 page, in order to allow it to poll earlier.

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

index 3a9db471ab0f74f04863dc323c71f26f8d606472..4a220ea22ed3215d182cd663b1eeaaf93892e306 100644 (file)
@@ -177,4 +177,11 @@ void Flow2Auth::slotPollTimerTimeout()
     });
 }
 
+void Flow2Auth::slotPollNow()
+{
+    // poll now if we're not already doing so
+    if(_pollTimer.isActive())
+        slotPollTimerTimeout();
+}
+
 } // namespace OCC
index b53834a115831d62397232ef37889569a3da65cc..f36483d48a9495c8cd43517062cc27ca03f0f495 100644 (file)
@@ -25,7 +25,6 @@ namespace OCC {
  * Job that does the authorization, grants and fetches the access token via Login Flow v2
  *
  * See: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/LoginFlow/index.html#login-flow-v2
- *
  */
 class Flow2Auth : public QObject
 {
@@ -53,6 +52,9 @@ signals:
      */
     void result(Flow2Auth::Result result, const QString &user = QString(), const QString &appPassword = QString());
 
+public slots:
+    void slotPollNow();
+
 private slots:
     void slotPollTimerTimeout();
 
index 4bc85722c7e452fc4c1a6dd98e0c01354cd3f912..09ebf42a345c0731ceebe070c5d3fa1566cdb597 100644 (file)
@@ -57,6 +57,7 @@ void Flow2AuthCredsPage::initializePage()
     ocWizard->account()->setCredentials(CredentialsFactory::create("http"));
     _asyncAuth.reset(new Flow2Auth(ocWizard->account().data(), this));
     connect(_asyncAuth.data(), &Flow2Auth::result, this, &Flow2AuthCredsPage::asyncAuthResult, Qt::QueuedConnection);
+    connect(this, &Flow2AuthCredsPage::pollNow, _asyncAuth.data(), &Flow2Auth::slotPollNow);
     _asyncAuth->start();
 
     // Don't hide the wizard (avoid user confusion)!
@@ -153,4 +154,9 @@ void Flow2AuthCredsPage::slotCopyLinkToClipboard()
         QApplication::clipboard()->setText(_asyncAuth->authorisationLink().toString(QUrl::FullyEncoded));
 }
 
+void Flow2AuthCredsPage::slotPollNow()
+{
+    emit pollNow();
+}
+
 } // namespace OCC
index f51d7d7f359c14f2a3654f3c3130996195bd5abc..ec2ca2558edced0c5bcbc89320f52fddd725410b 100644 (file)
@@ -47,9 +47,11 @@ public:
 
 public Q_SLOTS:
     void asyncAuthResult(Flow2Auth::Result, const QString &user, const QString &appPassword);
+    void slotPollNow();
 
 signals:
     void connectToOCUrl(const QString &);
+    void pollNow();
 
 public:
     QString _user;
index 8be68668d538bceba233bbedbad391c24d2b27c3..d4740acbfe82e567bcd86c3274cd7ce94215327f 100644 (file)
@@ -107,6 +107,9 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
     connect(this, &OwncloudWizard::styleChanged, _advancedSetupPage, &OwncloudAdvancedSetupPage::slotStyleChanged);
 
     customizeStyle();
+
+    // allow Flow2 page to poll on window activation
+    connect(this, &OwncloudWizard::onActivate, _flow2CredsPage, &Flow2AuthCredsPage::slotPollNow);
 }
 
 void OwncloudWizard::setAccount(AccountPtr account)
@@ -295,6 +298,10 @@ void OwncloudWizard::changeEvent(QEvent *e)
         // Notify the other widgets (Dark-/Light-Mode switching)
         emit styleChanged();
         break;
+    case QEvent::ActivationChange:
+        if(isActiveWindow())
+            emit onActivate();
+        break;
     default:
         break;
     }
index 5ea2ba349a1ef6567333dca7a17748c89285de1d..3cbf89f710704fb9aee2ea9d383d575f1e1bbc56 100644 (file)
@@ -99,6 +99,7 @@ signals:
     void skipFolderConfiguration();
     void needCertificate();
     void styleChanged();
+    void onActivate();
 
 protected:
     void changeEvent(QEvent *) override;