mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 17:37:36 +03:00
UpdateCheck: Clean up Application class and move most to updater.
Add the update timer also to the update class and remove all the proxy slots from the Application class.
This commit is contained in:
parent
681466213f
commit
adc239c9d0
5 changed files with 55 additions and 49 deletions
|
@ -178,11 +178,14 @@ Application::Application(int &argc, char **argv) :
|
||||||
QTimer::singleShot( 0, this, SLOT( slotCheckConnection() ));
|
QTimer::singleShot( 0, this, SLOT( slotCheckConnection() ));
|
||||||
|
|
||||||
// Update checks
|
// Update checks
|
||||||
_updaterTimer.setInterval(cfg.updateCheckInterval()); // check every couple of hours as defined in config
|
if (OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance())) {
|
||||||
|
connect(updater, SIGNAL(downloadStateChanged()),
|
||||||
connect(&_updaterTimer, SIGNAL(timeout()), this, SLOT(slotStartUpdateDetector()));
|
this, SLOT(slotNotifyAboutAvailableUpdate()), Qt::UniqueConnection);
|
||||||
QTimer::singleShot( 3000, this, SLOT( slotStartUpdateDetector() ));
|
connect(updater, SIGNAL(newUpdateAvailable(QString,QString)),
|
||||||
|
_gui, SLOT(slotShowTrayMessage(QString,QString)) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup at Quit.
|
||||||
connect (this, SIGNAL(aboutToQuit()), SLOT(slotCleanup()));
|
connect (this, SIGNAL(aboutToQuit()), SLOT(slotCleanup()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -249,34 +252,6 @@ void Application::slotCleanup()
|
||||||
_gui->deleteLater();
|
_gui->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::slotStartUpdateDetector()
|
|
||||||
{
|
|
||||||
ConfigFile cfg;
|
|
||||||
|
|
||||||
if( cfg.skipUpdateCheck() ) {
|
|
||||||
qDebug() << Q_FUNC_INFO << "Skipping update check because of config file";
|
|
||||||
} else {
|
|
||||||
if (OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance())) {
|
|
||||||
connect(updater, SIGNAL(downloadStateChanged()), this,
|
|
||||||
SLOT(slotNotifyAboutAvailableUpdate()), Qt::UniqueConnection);
|
|
||||||
|
|
||||||
updater->backgroundCheckForUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::slotNotifyAboutAvailableUpdate()
|
|
||||||
{
|
|
||||||
if( _gui ) {
|
|
||||||
if (OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance())) {
|
|
||||||
// Show a tray message if an Update is ready...
|
|
||||||
if( updater->downloadState() == OCUpdater::DownloadComplete ) {
|
|
||||||
_gui->slotShowTrayMessage( tr("Update Check"), updater->statusString() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::slotCheckConnection()
|
void Application::slotCheckConnection()
|
||||||
{
|
{
|
||||||
AccountState *accountState = AccountStateManager::instance()->accountState();
|
AccountState *accountState = AccountStateManager::instance()->accountState();
|
||||||
|
|
|
@ -75,7 +75,6 @@ protected slots:
|
||||||
void slotParseMessage(const QString&, QObject*);
|
void slotParseMessage(const QString&, QObject*);
|
||||||
void slotCheckConnection();
|
void slotCheckConnection();
|
||||||
void slotUpdateConnectionErrors(int accountState);
|
void slotUpdateConnectionErrors(int accountState);
|
||||||
void slotStartUpdateDetector();
|
|
||||||
void slotUseMonoIconsChanged( bool );
|
void slotUseMonoIconsChanged( bool );
|
||||||
void slotLogin();
|
void slotLogin();
|
||||||
void slotLogout();
|
void slotLogout();
|
||||||
|
@ -84,7 +83,6 @@ protected slots:
|
||||||
void slotAccountStateRemoved(AccountState *accountState);
|
void slotAccountStateRemoved(AccountState *accountState);
|
||||||
void slotAccountStateChanged(int state);
|
void slotAccountStateChanged(int state);
|
||||||
void slotCrash();
|
void slotCrash();
|
||||||
void slotNotifyAboutAvailableUpdate();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setHelp();
|
void setHelp();
|
||||||
|
@ -108,7 +106,6 @@ private:
|
||||||
ClientProxy _proxy;
|
ClientProxy _proxy;
|
||||||
|
|
||||||
QTimer _checkConnectionTimer;
|
QTimer _checkConnectionTimer;
|
||||||
QTimer _updaterTimer;
|
|
||||||
|
|
||||||
#if defined(WITH_CRASHREPORTER)
|
#if defined(WITH_CRASHREPORTER)
|
||||||
QScopedPointer<CrashReporter::Handler> _crashHandler;
|
QScopedPointer<CrashReporter::Handler> _crashHandler;
|
||||||
|
|
|
@ -42,8 +42,19 @@ OCUpdater::OCUpdater(const QUrl &url, QObject *parent) :
|
||||||
, _updateUrl(url)
|
, _updateUrl(url)
|
||||||
, _state(Unknown)
|
, _state(Unknown)
|
||||||
, _accessManager(new AccessManager(this))
|
, _accessManager(new AccessManager(this))
|
||||||
, _timer(new QTimer(this))
|
, _timeoutWatchdog(new QTimer(this))
|
||||||
|
, _updateCheckTimer(new QTimer(this))
|
||||||
{
|
{
|
||||||
|
// at startup, do a check in any case.
|
||||||
|
QTimer::singleShot( 3000, this, SLOT( backgroundCheckForUpdate()));
|
||||||
|
|
||||||
|
// connect the timer to the check slot
|
||||||
|
connect( _updateCheckTimer, SIGNAL(timeout()), this, SLOT(backgroundCheckForUpdate()));
|
||||||
|
// and set the timer regular interval which is usually large, like 10 hours.
|
||||||
|
ConfigFile cfg;
|
||||||
|
auto checkInterval = cfg.updateCheckInterval();
|
||||||
|
qDebug() << "Setting up regular update check every " << checkInterval /1000/60 << "seconds";
|
||||||
|
_updateCheckTimer->setInterval(checkInterval); // check every couple of hours as defined in config
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OCUpdater::performUpdate()
|
bool OCUpdater::performUpdate()
|
||||||
|
@ -67,14 +78,29 @@ void OCUpdater::backgroundCheckForUpdate()
|
||||||
{
|
{
|
||||||
int dlState = downloadState();
|
int dlState = downloadState();
|
||||||
|
|
||||||
if( dlState == Unknown ||
|
ConfigFile cfg;
|
||||||
dlState == UpToDate ||
|
|
||||||
/* dlState == DownloadComplete || <- are we checking if a previous download was successful already? */
|
if( cfg.skipUpdateCheck() ) {
|
||||||
dlState == DownloadFailed ||
|
qDebug() << Q_FUNC_INFO << "Skipping update check because of config file";
|
||||||
dlState == DownloadTimedOut ) {
|
return;
|
||||||
// how about UpdateOnlyAvailableThroughSystem?
|
}
|
||||||
checkForUpdate();
|
|
||||||
}
|
// do the real update check depending on the internal state of updater.
|
||||||
|
switch( dlState ) {
|
||||||
|
case Unknown:
|
||||||
|
case UpToDate:
|
||||||
|
case DownloadFailed:
|
||||||
|
case DownloadTimedOut:
|
||||||
|
qDebug() << Q_FUNC_INFO << "checking for available update";
|
||||||
|
checkForUpdate();
|
||||||
|
break;
|
||||||
|
case DownloadComplete:
|
||||||
|
qDebug() << "Update is downloaded, skip new check.";
|
||||||
|
break;
|
||||||
|
case UpdateOnlyAvailableThroughSystem:
|
||||||
|
qDebug() << "Update is only available through system, skip check.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString OCUpdater::statusString() const
|
QString OCUpdater::statusString() const
|
||||||
|
@ -112,6 +138,10 @@ void OCUpdater::setDownloadState(DownloadState state)
|
||||||
{
|
{
|
||||||
_state = state;
|
_state = state;
|
||||||
emit downloadStateChanged();
|
emit downloadStateChanged();
|
||||||
|
|
||||||
|
if( _state == OCUpdater::DownloadComplete ) {
|
||||||
|
emit newUpdateAvailable(tr("Update Check"), statusString() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OCUpdater::slotStartInstaller()
|
void OCUpdater::slotStartInstaller()
|
||||||
|
@ -128,8 +158,8 @@ void OCUpdater::slotStartInstaller()
|
||||||
void OCUpdater::checkForUpdate()
|
void OCUpdater::checkForUpdate()
|
||||||
{
|
{
|
||||||
QNetworkReply *reply = _accessManager->get(QNetworkRequest(_updateUrl));
|
QNetworkReply *reply = _accessManager->get(QNetworkRequest(_updateUrl));
|
||||||
connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimedOut()));
|
connect(_timeoutWatchdog, SIGNAL(timeout()), this, SLOT(slotTimedOut()));
|
||||||
_timer->start(30*1000);
|
_timeoutWatchdog->start(30*1000);
|
||||||
connect(reply, SIGNAL(finished()), this, SLOT(slotVersionInfoArrived()));
|
connect(reply, SIGNAL(finished()), this, SLOT(slotVersionInfoArrived()));
|
||||||
|
|
||||||
setDownloadState(CheckingServer);
|
setDownloadState(CheckingServer);
|
||||||
|
@ -152,7 +182,7 @@ bool OCUpdater::updateSucceeded() const
|
||||||
|
|
||||||
void OCUpdater::slotVersionInfoArrived()
|
void OCUpdater::slotVersionInfoArrived()
|
||||||
{
|
{
|
||||||
_timer->stop();
|
_timeoutWatchdog->stop();
|
||||||
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
||||||
if( reply->error() != QNetworkReply::NoError ) {
|
if( reply->error() != QNetworkReply::NoError ) {
|
||||||
qDebug() << "Failed to reach version check url: " << reply->errorString();
|
qDebug() << "Failed to reach version check url: " << reply->errorString();
|
||||||
|
|
|
@ -42,7 +42,6 @@ public:
|
||||||
bool performUpdate();
|
bool performUpdate();
|
||||||
|
|
||||||
void checkForUpdate() Q_DECL_OVERRIDE;
|
void checkForUpdate() Q_DECL_OVERRIDE;
|
||||||
void backgroundCheckForUpdate() Q_DECL_OVERRIDE;
|
|
||||||
|
|
||||||
QString statusString() const;
|
QString statusString() const;
|
||||||
int downloadState() const;
|
int downloadState() const;
|
||||||
|
@ -50,11 +49,14 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void downloadStateChanged();
|
void downloadStateChanged();
|
||||||
|
void newUpdateAvailable(const QString& header, const QString& message);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slotStartInstaller();
|
void slotStartInstaller();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void backgroundCheckForUpdate() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void slotOpenUpdateUrl();
|
void slotOpenUpdateUrl();
|
||||||
void slotVersionInfoArrived();
|
void slotVersionInfoArrived();
|
||||||
void slotTimedOut();
|
void slotTimedOut();
|
||||||
|
@ -68,7 +70,8 @@ private:
|
||||||
QUrl _updateUrl;
|
QUrl _updateUrl;
|
||||||
int _state;
|
int _state;
|
||||||
QNetworkAccessManager *_accessManager;
|
QNetworkAccessManager *_accessManager;
|
||||||
QTimer *_timer;
|
QTimer *_timeoutWatchdog; /** Timer to guard the timeout of an individual network request */
|
||||||
|
QTimer *_updateCheckTimer; /** Timer for the regular update check. */
|
||||||
UpdateInfo _updateInfo;
|
UpdateInfo _updateInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@ Updater *Updater::create()
|
||||||
#else
|
#else
|
||||||
return new PassiveUpdateNotifier(QUrl(updateBaseUrl));
|
return new PassiveUpdateNotifier(QUrl(updateBaseUrl));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue