added basic version fetching

This commit is contained in:
fourtf 2018-04-19 22:16:55 +02:00
parent fc78fa23a2
commit 683c4aed2d
4 changed files with 96 additions and 2 deletions

View file

@ -179,7 +179,8 @@ SOURCES += \
src/util/rapidjson-helpers.cpp \ src/util/rapidjson-helpers.cpp \
src/singletons/helper/pubsubhelpers.cpp \ src/singletons/helper/pubsubhelpers.cpp \
src/singletons/helper/pubsubactions.cpp \ src/singletons/helper/pubsubactions.cpp \
src/widgets/selectchanneldialog.cpp src/widgets/selectchanneldialog.cpp \
src/singletons/updatemanager.cpp
HEADERS += \ HEADERS += \
src/precompiled_header.hpp \ src/precompiled_header.hpp \
@ -301,7 +302,8 @@ HEADERS += \
src/util/rapidjson-helpers.hpp \ src/util/rapidjson-helpers.hpp \
src/singletons/helper/pubsubhelpers.hpp \ src/singletons/helper/pubsubhelpers.hpp \
src/singletons/helper/pubsubactions.hpp \ src/singletons/helper/pubsubactions.hpp \
src/widgets/selectchanneldialog.hpp src/widgets/selectchanneldialog.hpp \
src/singletons/updatemanager.hpp
RESOURCES += \ RESOURCES += \
resources/resources.qrc resources/resources.qrc

View file

@ -0,0 +1,54 @@
#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);
req.getJSON([this](QJsonDocument &document) {
if (document.isEmpty()) {
qDebug() << "error updating";
return;
}
QJsonValue version_val = document.object().value("version");
if (!version_val.isString()) {
qDebug() << "error updating";
return;
}
this->onlineVersion = version_val.toString();
this->onlineVersionUpdated.invoke();
});
}
} // namespace singletons
} // namespace chatterino

View file

@ -0,0 +1,28 @@
#pragma once
#include <QString>;
#include <pajlada/signals/signal.hpp>
namespace chatterino {
namespace singletons {
class UpdateManager
{
UpdateManager();
public:
static UpdateManager &getInstance();
void checkForUpdates();
const QString &getCurrentVersion() const;
const QString &getOnlineVersion() const;
pajlada::Signals::Signal onlineVersionUpdated;
private:
QString currentVersion;
QString onlineVersion;
};
} // namespace singletons
} // namespace chatterino

View file

@ -1,3 +1,13 @@
#pragma once #pragma once
#include <QtGlobal>
#define CHATTERINO_VERSION "2.0.0" #define CHATTERINO_VERSION "2.0.0"
#if defined(Q_OS_WIN)
#define CHATTERINO_OS "win"
#elif defined(Q_OS_MACOS)
#define CHATTERINO_OS "macos"
#elif defined(Q_OS_LINUX)
#define CHATTERINO_OS "linux"
#endif