update 2.1.0

This commit is contained in:
fourtf 2019-08-18 20:14:00 +02:00
parent 18fb160094
commit 23f1dd4646
13 changed files with 127 additions and 90 deletions

View file

@ -71,7 +71,7 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags)
// QTimer::this->scaleChangedEvent(this->getScale());
this->resize(300, 300);
this->resize(300, 150);
}
float BaseWindow::scale() const

Binary file not shown.

Before

Width:  |  Height:  |  Size: 344 B

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 332 B

After

Width:  |  Height:  |  Size: 267 B

View file

@ -77,21 +77,21 @@ namespace {
void showLastCrashDialog()
{
#ifndef C_DISABLE_CRASH_DIALOG
LastRunCrashDialog dialog;
//#ifndef C_DISABLE_CRASH_DIALOG
// LastRunCrashDialog dialog;
switch (dialog.exec())
{
case QDialog::Accepted:
{
};
break;
default:
{
_exit(0);
}
}
#endif
// switch (dialog.exec())
// {
// case QDialog::Accepted:
// {
// };
// break;
// default:
// {
// _exit(0);
// }
// }
//#endif
}
void createRunningFile(const QString &path)

View file

@ -2,7 +2,7 @@
#include <QtGlobal>
#define CHATTERINO_VERSION "2.0.4"
#define CHATTERINO_VERSION "2.1.0"
#if defined(Q_OS_WIN)
# define CHATTERINO_OS "win"
@ -10,4 +10,6 @@
# define CHATTERINO_OS "macos"
#elif defined(Q_OS_LINUX)
# define CHATTERINO_OS "linux"
#else
# define CHATTERINO_OS "unknown"
#endif

View file

@ -73,7 +73,7 @@ ModerationAction::ModerationAction(const QString &action)
{
this->image_ = Image::fromPixmap(getApp()->resources->buttons.ban);
}
else if (action.startsWith("/delete"))
else if (action.startsWith("/delete "))
{
this->image_ = Image::fromPixmap(getApp()->resources->buttons.trashCan);
}

View file

@ -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.");
"Failed to download the update. \n\nTry manually "
"downloading the update.");
box->setAttribute(Qt::WA_DeleteOnClose);
box->show();
box->raise();
});
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_);
}
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

View file

@ -40,7 +40,8 @@ private:
QString onlineVersion_;
Status status_ = None;
QString updateUrl_;
QString updateExe_;
QString updateGuideLink_;
void setStatus_(Status status);
};

View file

@ -44,8 +44,8 @@ void initUpdateButton(Button &button,
button.setVisible(Updates::getInstance().shouldShowUpdateButton());
auto imageUrl = Updates::getInstance().isError()
? ":/images/download_update_error.png"
: ":/images/download_update.png";
? ":/buttons/updateError.png"
: ":/buttons/update.png";
button.setPixmap(QPixmap(imageUrl));
};

View file

@ -97,7 +97,6 @@ private:
void addCustomButtons();
pajlada::Signals::SignalHolder signalHolder_;
std::shared_ptr<UpdateDialog> updateDialogHandle_;
std::vector<pajlada::Signals::ScopedConnection> connections_;
};

View file

@ -115,27 +115,27 @@ void Window::showEvent(QShowEvent *event)
{
getSettings()->startUpNotification = 1;
auto box = new QMessageBox(
QMessageBox::Information, "Chatterino 2 Beta",
"Please note that this software is not stable yet. Things are "
"rough "
"around the edges and everything is subject to change.");
box->setAttribute(Qt::WA_DeleteOnClose);
box->show();
// auto box = new QMessageBox(
// QMessageBox::Information, "Chatterino 2 Beta",
// "Please note that this software is not stable yet. Things are "
// "rough "
// "around the edges and everything is subject to change.");
// box->setAttribute(Qt::WA_DeleteOnClose);
// box->show();
}
// Show changelog
if (getSettings()->currentVersion.getValue() != "" &&
getSettings()->currentVersion.getValue() != CHATTERINO_VERSION)
{
auto box = new QMessageBox(QMessageBox::Information,
"Chatterino 2 Beta", "Show changelog?",
auto box = new QMessageBox(QMessageBox::Information, "Chatterino 2",
"Show changelog?",
QMessageBox::Yes | QMessageBox::No);
box->setAttribute(Qt::WA_DeleteOnClose);
if (box->exec() == QMessageBox::Yes)
{
QDesktopServices::openUrl(
QUrl("https://fourtf.com/chatterino-changelog/"));
QUrl("https://www.chatterino.com/changelog"));
}
}
@ -372,13 +372,13 @@ void Window::onAccountSelected()
{
auto user = getApp()->accounts->twitch.getCurrent();
#ifdef CHATTERINO_NIGHTLY_VERSION_STRING
auto windowTitleEnd =
QString("Chatterino Nightly " CHATTERINO_VERSION
" (" UGLYMACROHACK(CHATTERINO_NIGHTLY_VERSION_STRING) ")");
#else
auto windowTitleEnd = QString("Chatterino Beta " CHATTERINO_VERSION);
#endif
//#ifdef CHATTERINO_NIGHTLY_VERSION_STRING
// auto windowTitleEnd =
// QString("Chatterino Nightly " CHATTERINO_VERSION
// " (" UGLYMACROHACK(CHATTERINO_NIGHTLY_VERSION_STRING) ")");
//#else
auto windowTitleEnd = QString("Chatterino " CHATTERINO_VERSION);
//#endif
this->setWindowTitle(windowTitleEnd);

View file

@ -88,7 +88,7 @@ BasicLoginWidget::BasicLoginWidget()
this->setLayout(&this->ui_.layout);
this->ui_.loginButton.setText("Log in (Opens in browser)");
this->ui_.pasteCodeButton.setText("Paste code");
this->ui_.pasteCodeButton.setText("Paste login info");
this->ui_.horizontalLayout.addWidget(&this->ui_.loginButton);
this->ui_.horizontalLayout.addWidget(&this->ui_.pasteCodeButton);

View file

@ -26,8 +26,10 @@ UpdateDialog::UpdateDialog()
this->ui_.installButton = install;
auto dismiss = buttons->addButton("Dismiss", QDialogButtonBox::RejectRole);
QObject::connect(install, &QPushButton::clicked, this,
[this] { this->close(); });
QObject::connect(install, &QPushButton::clicked, this, [this] {
Updates::getInstance().installUpdates();
this->close();
});
QObject::connect(dismiss, &QPushButton::clicked, this, [this] {
this->buttonClicked.invoke(Dismiss);
this->close();
@ -37,6 +39,8 @@ UpdateDialog::UpdateDialog()
this->connections_.managedConnect(
Updates::getInstance().statusUpdated,
[this](auto status) { this->updateStatusChanged(status); });
this->setScaleIndependantHeight(150);
}
void UpdateDialog::updateStatusChanged(Updates::Status status)
@ -51,6 +55,7 @@ void UpdateDialog::updateStatusChanged(Updates::Status status)
QString("An update (%1) is available.\n\nDo you want to "
"download and install it?")
.arg(Updates::getInstance().getOnlineVersion()));
this->updateGeometry();
}
break;