2018-04-19 22:16:55 +02:00
|
|
|
#include "updatemanager.hpp"
|
|
|
|
|
|
|
|
#include "util/networkrequest.hpp"
|
|
|
|
#include "version.hpp"
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace singletons {
|
|
|
|
|
|
|
|
UpdateManager::UpdateManager()
|
2018-06-01 14:20:46 +02:00
|
|
|
: currentVersion_(CHATTERINO_VERSION)
|
2018-04-19 22:16:55 +02:00
|
|
|
{
|
2018-04-26 18:10:26 +02:00
|
|
|
qDebug() << "init UpdateManager";
|
2018-04-19 22:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateManager &UpdateManager::getInstance()
|
|
|
|
{
|
2018-06-01 14:20:46 +02:00
|
|
|
// fourtf: don't add this class to the application class
|
2018-04-19 22:16:55 +02:00
|
|
|
static UpdateManager instance;
|
2018-06-01 14:20:46 +02:00
|
|
|
|
2018-04-19 22:16:55 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &UpdateManager::getCurrentVersion() const
|
|
|
|
{
|
2018-06-01 14:20:46 +02:00
|
|
|
return currentVersion_;
|
2018-04-19 22:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &UpdateManager::getOnlineVersion() const
|
|
|
|
{
|
2018-06-01 14:20:46 +02:00
|
|
|
return onlineVersion_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateManager::installUpdates()
|
|
|
|
{
|
2018-04-19 22:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateManager::checkForUpdates()
|
|
|
|
{
|
|
|
|
QString url = "https://notitia.chatterino.com/version/chatterino/" CHATTERINO_OS "/stable";
|
|
|
|
|
|
|
|
util::NetworkRequest req(url);
|
2018-06-01 14:20:46 +02:00
|
|
|
req.setTimeout(30000);
|
2018-04-20 00:15:57 +02:00
|
|
|
req.getJSON([this](QJsonObject &object) {
|
|
|
|
QJsonValue version_val = object.value("version");
|
2018-04-19 22:16:55 +02:00
|
|
|
if (!version_val.isString()) {
|
2018-06-01 14:20:46 +02:00
|
|
|
this->setStatus_(Error);
|
2018-04-19 22:16:55 +02:00
|
|
|
qDebug() << "error updating";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-01 14:20:46 +02:00
|
|
|
this->onlineVersion_ = version_val.toString();
|
|
|
|
|
|
|
|
if (this->currentVersion_ != this->onlineVersion_) {
|
|
|
|
this->setStatus_(UpdateAvailable);
|
|
|
|
} else {
|
|
|
|
this->setStatus_(NoUpdateAvailable);
|
|
|
|
}
|
2018-04-19 22:16:55 +02:00
|
|
|
});
|
2018-06-01 14:20:46 +02:00
|
|
|
this->setStatus_(Searching);
|
|
|
|
req.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateManager::UpdateStatus UpdateManager::getStatus() const
|
|
|
|
{
|
|
|
|
return this->status_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateManager::setStatus_(UpdateStatus status)
|
|
|
|
{
|
|
|
|
if (this->status_ != status) {
|
|
|
|
this->status_ = status;
|
|
|
|
this->statusUpdated.invoke(status);
|
|
|
|
}
|
2018-04-19 22:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace singletons
|
|
|
|
} // namespace chatterino
|