From 5a7a82b4e968e28b83414d858efda8856201a40b Mon Sep 17 00:00:00 2001 From: Dave Page Date: Mon, 27 Feb 2017 10:49:47 +0000 Subject: [PATCH] Simplify runtime startup polling, and increase retries to 30. Ensure the splash screen is hidden before showing errors. --- runtime/BrowserWindow.cpp | 41 --------------------------------------- runtime/BrowserWindow.h | 3 --- runtime/pgAdmin4.cpp | 11 ++++++----- 3 files changed, 6 insertions(+), 49 deletions(-) diff --git a/runtime/BrowserWindow.cpp b/runtime/BrowserWindow.cpp index 98a1dc59b..12dabd4f1 100644 --- a/runtime/BrowserWindow.cpp +++ b/runtime/BrowserWindow.cpp @@ -101,8 +101,6 @@ BrowserWindow::BrowserWindow(QString url) setCentralWidget(m_tabWidget); - connect(m_mainWebView, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool))); - #ifdef PGADMIN4_USE_WEBENGINE // Register the slot when click on the URL link for QWebEnginePage connect(m_mainWebView->page(), SIGNAL(createTabWindow(QWebEnginePage * &)),SLOT(createNewTabWindow(QWebEnginePage * &))); @@ -149,8 +147,6 @@ BrowserWindow::BrowserWindow(QString url) m_last_open_folder_path = settings.value("Browser/LastSaveLocation", QDir::homePath()).toString(); // Display the app - m_initialLoad = true; - m_loadAttempt = 1; m_mainWebView->setUrl(m_appServerUrl); } @@ -267,43 +263,6 @@ void BrowserWindow::onMacPaste() #endif #endif -// Process loading finished signals from the web view. -void BrowserWindow::finishLoading(bool ok) -{ - if (m_initialLoad && !ok) - { - // The load attempt failed. Try again up to 4 times with an - // incremental backoff. - if (m_loadAttempt < 5) - { - if (m_loadAttempt > 1) - { - qDebug() << "Initial connection failed. Retrying in" << m_loadAttempt << "seconds."; - m_mainWebView->setHtml(QString(tr("

Failed to connect to the pgAdmin application server. Retrying in %1 seconds, ") + - tr("or click here to try again now.

")).arg(m_loadAttempt).arg(m_appServerUrl)); - } - else - { - m_mainWebView->setHtml(QString(tr("

Connecting to the application server...

"))); - } - - pause(m_loadAttempt); - m_mainWebView->setUrl(m_appServerUrl); - m_loadAttempt++; - - return; - } - else - { - qDebug() << "Initial connection failed after multiple attempts. Aborting."; - m_mainWebView->setHtml(QString(tr("

Failed to connect to the pgAdmin application server. ") + - tr("Click here to try again.

")).arg(m_appServerUrl)); - } - } - - m_initialLoad = false; -} - // Check if Tab is already open with given URL name int BrowserWindow::findURLTab(const QUrl &name) { diff --git a/runtime/BrowserWindow.h b/runtime/BrowserWindow.h index f0b0eacd3..25d6beb2b 100644 --- a/runtime/BrowserWindow.h +++ b/runtime/BrowserWindow.h @@ -48,7 +48,6 @@ protected: void closeEvent(QCloseEvent *event); protected slots: - void finishLoading(bool); void urlLinkClicked(const QUrl &); void closetabs(); void tabTitleChanged(const QString &); @@ -110,8 +109,6 @@ private: QToolButton *m_toolBtnBack; QToolButton *m_toolBtnForward; - bool m_initialLoad; - int m_loadAttempt; QString m_downloadFilename; int m_downloadStarted; int m_downloadCancelled; diff --git a/runtime/pgAdmin4.cpp b/runtime/pgAdmin4.cpp index b8d5fb230..a16420bc0 100644 --- a/runtime/pgAdmin4.cpp +++ b/runtime/pgAdmin4.cpp @@ -81,6 +81,8 @@ int main(int argc, char * argv[]) if (!server->Init()) { + splash->finish(NULL); + qDebug() << server->getError(); QString error = QString(QWidget::tr("An error occurred initialising the application server:\n\n%1")).arg(server->getError()); @@ -141,11 +143,9 @@ int main(int argc, char * argv[]) QString appServerUrl = QString("http://localhost:%1/").arg(port); // Now the server should be up, we'll attempt to connect and get a response. - // We'll retry in a loop a few time before aborting if necessary. The browser - // will also retry - that shouldn't (in theory) be necessary, but it won't - // hurt. + // We'll retry in a loop a few time before aborting if necessary. int attempt = 0; - while (attempt++ < 10) + while (attempt++ < 30) { bool alive = PingServer(QUrl(appServerUrl)); @@ -154,8 +154,9 @@ int main(int argc, char * argv[]) break; } - if (attempt == 10) + if (attempt == 30) { + splash->finish(NULL); QString error(QWidget::tr("The application server could not be contacted.")); QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error);