mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
tell user they might downgrade in update popup
This commit is contained in:
parent
594c0fb255
commit
0ada53a3c1
|
@ -13,6 +13,7 @@
|
|||
#include <QDesktopServices>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
|
@ -20,6 +21,38 @@ namespace {
|
|||
{
|
||||
return getSettings()->betaUpdates ? "beta" : "stable";
|
||||
}
|
||||
|
||||
/// Checks if the online version is newer or older than the current version.
|
||||
bool isDowngradeOf(const QString &online, const QString ¤t)
|
||||
{
|
||||
static auto matchVersion =
|
||||
QRegularExpression(R"((\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?)");
|
||||
|
||||
// Versions are just strings, they don't need to follow a specific
|
||||
// format so we can only assume if one version is newer than another
|
||||
// one.
|
||||
|
||||
// We match x.x.x.x with each version level being optional.
|
||||
|
||||
auto onlineMatch = matchVersion.match(online);
|
||||
auto currentMatch = matchVersion.match(current);
|
||||
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
if (onlineMatch.captured(i).toInt() <
|
||||
currentMatch.captured(i).toInt())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (onlineMatch.captured(i).toInt() >
|
||||
currentMatch.captured(i).toInt())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Updates::Updates()
|
||||
|
@ -263,6 +296,8 @@ void Updates::checkForUpdates()
|
|||
if (this->currentVersion_ != this->onlineVersion_)
|
||||
{
|
||||
this->setStatus_(UpdateAvailable);
|
||||
this->isDowngrade_ =
|
||||
isDowngradeOf(this->onlineVersion_, this->currentVersion_);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -309,6 +344,11 @@ bool Updates::isError() const
|
|||
}
|
||||
}
|
||||
|
||||
bool Updates::isDowngrade() const
|
||||
{
|
||||
return this->isDowngrade_;
|
||||
}
|
||||
|
||||
void Updates::setStatus_(Status status)
|
||||
{
|
||||
if (this->status_ != status)
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
|
||||
bool shouldShowUpdateButton() const;
|
||||
bool isError() const;
|
||||
bool isDowngrade() const;
|
||||
|
||||
pajlada::Signals::Signal<Status> statusUpdated;
|
||||
|
||||
|
@ -39,6 +40,7 @@ private:
|
|||
QString currentVersion_;
|
||||
QString onlineVersion_;
|
||||
Status status_ = None;
|
||||
bool isDowngrade_{};
|
||||
|
||||
QString updateExe_;
|
||||
QString updatePortable_;
|
||||
|
|
|
@ -50,9 +50,17 @@ void UpdateDialog::updateStatusChanged(Updates::Status status)
|
|||
{
|
||||
case Updates::UpdateAvailable: {
|
||||
this->ui_.label->setText(
|
||||
QString("An update (%1) is available.\n\nDo you want to "
|
||||
"download and install it?")
|
||||
.arg(Updates::getInstance().getOnlineVersion()));
|
||||
(Updates::getInstance().isDowngrade()
|
||||
? QString(
|
||||
"The version online (%1) seems to be lower than the "
|
||||
"current (%2).\nEither a version was reverted or "
|
||||
"you are running a newer build.\n\nDo you want to "
|
||||
"download and install it?")
|
||||
.arg(Updates::getInstance().getOnlineVersion(),
|
||||
Updates::getInstance().getCurrentVersion())
|
||||
: QString("An update (%1) is available.\n\nDo you want to "
|
||||
"download and install it?")
|
||||
.arg(Updates::getInstance().getOnlineVersion())));
|
||||
this->updateGeometry();
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue