refactor: Remove Outcome from network requests (#4959)

This commit is contained in:
nerix
2023-11-12 14:51:51 +01:00
committed by GitHub
parent 95620e6e10
commit 6faf63c5c4
22 changed files with 122 additions and 228 deletions
+11 -16
View File
@@ -3,7 +3,6 @@
#include "common/Modes.hpp"
#include "common/NetworkRequest.hpp"
#include "common/NetworkResult.hpp"
#include "common/Outcome.hpp"
#include "common/QLogging.hpp"
#include "common/Version.hpp"
#include "Settings.hpp"
@@ -122,7 +121,7 @@ void Updates::installUpdates()
box->raise();
});
})
.onSuccess([this](auto result) -> Outcome {
.onSuccess([this](auto result) {
if (result.status() != 200)
{
auto *box = new QMessageBox(
@@ -132,7 +131,7 @@ void Updates::installUpdates()
.arg(result.formatError()));
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
return Failure;
return;
}
QByteArray object = result.getData();
@@ -145,7 +144,7 @@ void Updates::installUpdates()
if (file.write(object) == -1)
{
this->setStatus_(WriteFileFailed);
return Failure;
return;
}
file.flush();
file.close();
@@ -156,7 +155,6 @@ void Updates::installUpdates()
{filename, "restart"});
QApplication::exit(0);
return Success;
})
.execute();
this->setStatus_(Downloading);
@@ -183,7 +181,7 @@ void Updates::installUpdates()
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
})
.onSuccess([this](auto result) -> Outcome {
.onSuccess([this](auto result) {
if (result.status() != 200)
{
auto *box = new QMessageBox(
@@ -193,7 +191,7 @@ void Updates::installUpdates()
.arg(result.formatError()));
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
return Failure;
return;
}
QByteArray object = result.getData();
@@ -216,7 +214,7 @@ void Updates::installUpdates()
box->exec();
QDesktopServices::openUrl(this->updateExe_);
return Failure;
return;
}
file.flush();
file.close();
@@ -239,8 +237,6 @@ void Updates::installUpdates()
QDesktopServices::openUrl(this->updateExe_);
}
return Success;
})
.execute();
this->setStatus_(Downloading);
@@ -279,7 +275,7 @@ void Updates::checkForUpdates()
NetworkRequest(url)
.timeout(60000)
.onSuccess([this](auto result) -> Outcome {
.onSuccess([this](auto result) {
const auto object = result.parseJson();
/// Version available on every platform
auto version = object["version"];
@@ -289,7 +285,7 @@ void Updates::checkForUpdates()
this->setStatus_(SearchFailed);
qCDebug(chatterinoUpdate)
<< "error checking version - missing 'version'" << object;
return Failure;
return;
}
# if defined Q_OS_WIN || defined Q_OS_MACOS
@@ -300,7 +296,7 @@ void Updates::checkForUpdates()
this->setStatus_(SearchFailed);
qCDebug(chatterinoUpdate)
<< "error checking version - missing 'updateexe'" << object;
return Failure;
return;
}
this->updateExe_ = updateExeUrl.toString();
@@ -313,7 +309,7 @@ void Updates::checkForUpdates()
qCDebug(chatterinoUpdate)
<< "error checking version - missing 'portable_download'"
<< object;
return Failure;
return;
}
this->updatePortable_ = portableUrl.toString();
# endif
@@ -325,7 +321,7 @@ void Updates::checkForUpdates()
this->updateGuideLink_ = updateGuide.toString();
}
# else
return Failure;
return;
# endif
/// Current version
@@ -342,7 +338,6 @@ void Updates::checkForUpdates()
{
this->setStatus_(NoUpdateAvailable);
}
return Failure;
})
.execute();
this->setStatus_(Searching);