mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +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() ));
|
||||
|
||||
// Update checks
|
||||
_updaterTimer.setInterval(cfg.updateCheckInterval()); // check every couple of hours as defined in config
|
||||
|
||||
connect(&_updaterTimer, SIGNAL(timeout()), this, SLOT(slotStartUpdateDetector()));
|
||||
QTimer::singleShot( 3000, this, SLOT( slotStartUpdateDetector() ));
|
||||
if (OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance())) {
|
||||
connect(updater, SIGNAL(downloadStateChanged()),
|
||||
this, SLOT(slotNotifyAboutAvailableUpdate()), Qt::UniqueConnection);
|
||||
connect(updater, SIGNAL(newUpdateAvailable(QString,QString)),
|
||||
_gui, SLOT(slotShowTrayMessage(QString,QString)) );
|
||||
}
|
||||
|
||||
// Cleanup at Quit.
|
||||
connect (this, SIGNAL(aboutToQuit()), SLOT(slotCleanup()));
|
||||
|
||||
}
|
||||
|
@ -249,34 +252,6 @@ void Application::slotCleanup()
|
|||
_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()
|
||||
{
|
||||
AccountState *accountState = AccountStateManager::instance()->accountState();
|
||||
|
|
|
@ -75,7 +75,6 @@ protected slots:
|
|||
void slotParseMessage(const QString&, QObject*);
|
||||
void slotCheckConnection();
|
||||
void slotUpdateConnectionErrors(int accountState);
|
||||
void slotStartUpdateDetector();
|
||||
void slotUseMonoIconsChanged( bool );
|
||||
void slotLogin();
|
||||
void slotLogout();
|
||||
|
@ -84,7 +83,6 @@ protected slots:
|
|||
void slotAccountStateRemoved(AccountState *accountState);
|
||||
void slotAccountStateChanged(int state);
|
||||
void slotCrash();
|
||||
void slotNotifyAboutAvailableUpdate();
|
||||
|
||||
private:
|
||||
void setHelp();
|
||||
|
@ -108,7 +106,6 @@ private:
|
|||
ClientProxy _proxy;
|
||||
|
||||
QTimer _checkConnectionTimer;
|
||||
QTimer _updaterTimer;
|
||||
|
||||
#if defined(WITH_CRASHREPORTER)
|
||||
QScopedPointer<CrashReporter::Handler> _crashHandler;
|
||||
|
|
|
@ -42,8 +42,19 @@ OCUpdater::OCUpdater(const QUrl &url, QObject *parent) :
|
|||
, _updateUrl(url)
|
||||
, _state(Unknown)
|
||||
, _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()
|
||||
|
@ -67,14 +78,29 @@ void OCUpdater::backgroundCheckForUpdate()
|
|||
{
|
||||
int dlState = downloadState();
|
||||
|
||||
if( dlState == Unknown ||
|
||||
dlState == UpToDate ||
|
||||
/* dlState == DownloadComplete || <- are we checking if a previous download was successful already? */
|
||||
dlState == DownloadFailed ||
|
||||
dlState == DownloadTimedOut ) {
|
||||
// how about UpdateOnlyAvailableThroughSystem?
|
||||
checkForUpdate();
|
||||
}
|
||||
ConfigFile cfg;
|
||||
|
||||
if( cfg.skipUpdateCheck() ) {
|
||||
qDebug() << Q_FUNC_INFO << "Skipping update check because of config file";
|
||||
return;
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -112,6 +138,10 @@ void OCUpdater::setDownloadState(DownloadState state)
|
|||
{
|
||||
_state = state;
|
||||
emit downloadStateChanged();
|
||||
|
||||
if( _state == OCUpdater::DownloadComplete ) {
|
||||
emit newUpdateAvailable(tr("Update Check"), statusString() );
|
||||
}
|
||||
}
|
||||
|
||||
void OCUpdater::slotStartInstaller()
|
||||
|
@ -128,8 +158,8 @@ void OCUpdater::slotStartInstaller()
|
|||
void OCUpdater::checkForUpdate()
|
||||
{
|
||||
QNetworkReply *reply = _accessManager->get(QNetworkRequest(_updateUrl));
|
||||
connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimedOut()));
|
||||
_timer->start(30*1000);
|
||||
connect(_timeoutWatchdog, SIGNAL(timeout()), this, SLOT(slotTimedOut()));
|
||||
_timeoutWatchdog->start(30*1000);
|
||||
connect(reply, SIGNAL(finished()), this, SLOT(slotVersionInfoArrived()));
|
||||
|
||||
setDownloadState(CheckingServer);
|
||||
|
@ -152,7 +182,7 @@ bool OCUpdater::updateSucceeded() const
|
|||
|
||||
void OCUpdater::slotVersionInfoArrived()
|
||||
{
|
||||
_timer->stop();
|
||||
_timeoutWatchdog->stop();
|
||||
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
||||
if( reply->error() != QNetworkReply::NoError ) {
|
||||
qDebug() << "Failed to reach version check url: " << reply->errorString();
|
||||
|
|
|
@ -42,7 +42,6 @@ public:
|
|||
bool performUpdate();
|
||||
|
||||
void checkForUpdate() Q_DECL_OVERRIDE;
|
||||
void backgroundCheckForUpdate() Q_DECL_OVERRIDE;
|
||||
|
||||
QString statusString() const;
|
||||
int downloadState() const;
|
||||
|
@ -50,11 +49,14 @@ public:
|
|||
|
||||
signals:
|
||||
void downloadStateChanged();
|
||||
void newUpdateAvailable(const QString& header, const QString& message);
|
||||
|
||||
public slots:
|
||||
void slotStartInstaller();
|
||||
|
||||
private slots:
|
||||
void backgroundCheckForUpdate() Q_DECL_OVERRIDE;
|
||||
|
||||
void slotOpenUpdateUrl();
|
||||
void slotVersionInfoArrived();
|
||||
void slotTimedOut();
|
||||
|
@ -68,7 +70,8 @@ private:
|
|||
QUrl _updateUrl;
|
||||
int _state;
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -96,6 +96,7 @@ Updater *Updater::create()
|
|||
#else
|
||||
return new PassiveUpdateNotifier(QUrl(updateBaseUrl));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue