update 2.1.0
This commit is contained in:
+79
-49
@@ -8,6 +8,7 @@
|
||||
#include "util/PostToThread.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
|
||||
@@ -15,6 +16,7 @@ namespace chatterino {
|
||||
|
||||
Updates::Updates()
|
||||
: currentVersion_(CHATTERINO_VERSION)
|
||||
, updateGuideLink_("https://chatterino.com")
|
||||
{
|
||||
qDebug() << "init UpdateManager";
|
||||
}
|
||||
@@ -45,7 +47,22 @@ void Updates::installUpdates()
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#ifdef Q_OS_MACOS
|
||||
QMessageBox *box = new QMessageBox(
|
||||
QMessageBox::Information, "Chatterino Update",
|
||||
"A link will open in your browser. Download and install to update.");
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->exec();
|
||||
QDesktopServices::openUrl(this->updateExe_);
|
||||
#elif defined Q_OS_LINUX
|
||||
QMessageBox *box =
|
||||
new QMessageBox(QMessageBox::Information, "Chatterino Update",
|
||||
"Automatic updates are currently not available on "
|
||||
"linux. Please redownload the app to update.");
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->exec();
|
||||
QDesktopServices::openUrl(this->updateGuideLink_);
|
||||
#elif defined Q_OS_WIN
|
||||
QMessageBox *box =
|
||||
new QMessageBox(QMessageBox::Information, "Chatterino Update",
|
||||
"Chatterino is downloading the update "
|
||||
@@ -54,26 +71,23 @@ void Updates::installUpdates()
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->show();
|
||||
|
||||
NetworkRequest req(this->updateUrl_);
|
||||
NetworkRequest req(this->updateExe_);
|
||||
req.setTimeout(600000);
|
||||
req.onError([this](int) -> bool {
|
||||
this->setStatus_(DownloadFailed);
|
||||
|
||||
postToThread([] {
|
||||
QMessageBox *box =
|
||||
new QMessageBox(QMessageBox::Information, "Chatterino Update",
|
||||
"Failed while trying to download the update.");
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->show();
|
||||
box->raise();
|
||||
});
|
||||
|
||||
QMessageBox *box =
|
||||
new QMessageBox(QMessageBox::Information, "Chatterino Update",
|
||||
"Failed to download the update. \n\nTry manually "
|
||||
"downloading the update.");
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->exec();
|
||||
return true;
|
||||
});
|
||||
|
||||
req.onSuccess([this](auto result) -> Outcome {
|
||||
QByteArray object = result.getData();
|
||||
auto filename = combinePath(getPaths()->miscDirectory, "update.zip");
|
||||
auto filename = combinePath(getPaths()->miscDirectory, "Update.exe");
|
||||
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
||||
@@ -81,15 +95,36 @@ void Updates::installUpdates()
|
||||
if (file.write(object) == -1)
|
||||
{
|
||||
this->setStatus_(WriteFileFailed);
|
||||
QMessageBox *box = new QMessageBox(
|
||||
QMessageBox::Information, "Chatterino Update",
|
||||
"Failed to save the update file. This could be due to "
|
||||
"window settings or antivirus software.\n\nTry manually "
|
||||
"downloading the update.");
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->exec();
|
||||
|
||||
QDesktopServices::openUrl(this->updateExe_);
|
||||
return Failure;
|
||||
}
|
||||
file.close();
|
||||
|
||||
QProcess::startDetached(
|
||||
combinePath(QCoreApplication::applicationDirPath(),
|
||||
"updater.1/ChatterinoUpdater.exe"),
|
||||
{filename, "restart"});
|
||||
if (QProcess::startDetached(filename))
|
||||
{
|
||||
QApplication::exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox *box = new QMessageBox(
|
||||
QMessageBox::Information, "Chatterino Update",
|
||||
"Failed to execute update binary. This could be due to window "
|
||||
"settings or antivirus software.\n\nTry manually downloading "
|
||||
"the update.");
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->exec();
|
||||
|
||||
QDesktopServices::openUrl(this->updateExe_);
|
||||
}
|
||||
|
||||
QApplication::exit(0);
|
||||
return Success;
|
||||
});
|
||||
this->setStatus_(Downloading);
|
||||
@@ -99,56 +134,52 @@ void Updates::installUpdates()
|
||||
|
||||
void Updates::checkForUpdates()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
QString url =
|
||||
"https://notitia.chatterino.com/version/chatterino/" CHATTERINO_OS
|
||||
"/stable";
|
||||
|
||||
NetworkRequest req(url);
|
||||
req.setTimeout(30000);
|
||||
req.setTimeout(60000);
|
||||
req.onSuccess([this](auto result) -> Outcome {
|
||||
auto object = result.parseJson();
|
||||
/// Version available on every platform
|
||||
QJsonValue version_val = object.value("version");
|
||||
QJsonValue update_val = object.value("update");
|
||||
|
||||
if (!version_val.isString() || !update_val.isString())
|
||||
if (!version_val.isString())
|
||||
{
|
||||
this->setStatus_(SearchFailed);
|
||||
qDebug() << "error updating";
|
||||
|
||||
postToThread([] {
|
||||
QMessageBox *box = new QMessageBox(
|
||||
QMessageBox::Information, "Chatterino Update",
|
||||
"Error while searching for updates.\n\nEither the service "
|
||||
"is down "
|
||||
"temporarily or everything is broken.");
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->show();
|
||||
box->raise();
|
||||
});
|
||||
return Failure;
|
||||
}
|
||||
|
||||
this->onlineVersion_ = version_val.toString();
|
||||
this->updateUrl_ = update_val.toString();
|
||||
#if defined Q_OS_WIN || defined Q_OS_MACOS
|
||||
/// Windows downloads an installer for the new version
|
||||
QJsonValue updateExe_val = object.value("updateexe");
|
||||
if (!updateExe_val.isString())
|
||||
{
|
||||
this->setStatus_(SearchFailed);
|
||||
qDebug() << "error updating";
|
||||
return Failure;
|
||||
}
|
||||
this->updateExe_ = updateExe_val.toString();
|
||||
|
||||
#elif defined Q_OS_LINUX
|
||||
QJsonValue updateGuide_val = object.value("updateguide");
|
||||
if (updateGuide_val.isString())
|
||||
{
|
||||
this->updateGuideLink_ = updateGuide_val.toString();
|
||||
}
|
||||
#else
|
||||
return Failure;
|
||||
#endif
|
||||
|
||||
/// Current version
|
||||
this->onlineVersion_ = version_val.toString();
|
||||
|
||||
/// Update available :)
|
||||
if (this->currentVersion_ != this->onlineVersion_)
|
||||
{
|
||||
this->setStatus_(UpdateAvailable);
|
||||
postToThread([this] {
|
||||
QMessageBox *box = new QMessageBox(
|
||||
QMessageBox::Information, "Chatterino Update",
|
||||
"An update for chatterino is available.\n\nDo you "
|
||||
"want to download and install it?",
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->show();
|
||||
box->raise();
|
||||
if (box->exec() == QMessageBox::Yes)
|
||||
{
|
||||
this->installUpdates();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -158,7 +189,6 @@ void Updates::checkForUpdates()
|
||||
});
|
||||
this->setStatus_(Searching);
|
||||
req.execute();
|
||||
#endif
|
||||
}
|
||||
|
||||
Updates::Status Updates::getStatus() const
|
||||
|
||||
Reference in New Issue
Block a user