mirror-chatterino2/src/singletons/updatemanager.cpp

50 lines
1.1 KiB
C++
Raw Normal View History

2018-04-19 22:16:55 +02:00
#include "updatemanager.hpp"
#include "util/networkrequest.hpp"
#include "version.hpp"
namespace chatterino {
namespace singletons {
UpdateManager::UpdateManager()
: currentVersion(CHATTERINO_VERSION)
{
}
UpdateManager &UpdateManager::getInstance()
{
static UpdateManager instance;
return instance;
}
const QString &UpdateManager::getCurrentVersion() const
{
return this->getCurrentVersion();
}
const QString &UpdateManager::getOnlineVersion() const
{
return this->getOnlineVersion();
}
void UpdateManager::checkForUpdates()
{
QString url = "https://notitia.chatterino.com/version/chatterino/" CHATTERINO_OS "/stable";
util::NetworkRequest req(url);
req.setTimeout(20000);
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()) {
qDebug() << "error updating";
return;
}
this->onlineVersion = version_val.toString();
this->onlineVersionUpdated.invoke();
});
}
} // namespace singletons
} // namespace chatterino