2018-03-22 05:20:15 -06:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-03-22 05:20:15 -06:00
|
|
|
|
2018-07-06 16:40:15 -06:00
|
|
|
#include "DolphinQt/Updater.h"
|
2018-03-22 05:20:15 -06:00
|
|
|
|
2021-12-27 11:09:47 -07:00
|
|
|
#include <utility>
|
|
|
|
|
2018-03-22 05:20:15 -06:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QTextBrowser>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include "Common/Version.h"
|
2018-05-27 19:48:04 -06:00
|
|
|
|
2018-07-06 16:40:15 -06:00
|
|
|
#include "DolphinQt/QtUtils/RunOnObject.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
2018-03-22 05:20:15 -06:00
|
|
|
|
2021-03-12 18:10:53 -07:00
|
|
|
// Refer to docs/autoupdate_overview.md for a detailed overview of the autoupdate process
|
|
|
|
|
2021-12-27 11:09:47 -07:00
|
|
|
Updater::Updater(QWidget* parent, std::string update_track, std::string hash_override)
|
|
|
|
: m_parent(parent), m_update_track(std::move(update_track)),
|
|
|
|
m_hash_override(std::move(hash_override))
|
2018-03-22 05:20:15 -06:00
|
|
|
{
|
|
|
|
connect(this, &QThread::finished, this, &QObject::deleteLater);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Updater::run()
|
|
|
|
{
|
2022-11-01 00:08:35 -06:00
|
|
|
AutoUpdateChecker::CheckForUpdate(m_update_track, m_hash_override,
|
|
|
|
AutoUpdateChecker::CheckType::Automatic);
|
2018-05-24 16:19:36 -06:00
|
|
|
}
|
|
|
|
|
2022-11-01 00:08:35 -06:00
|
|
|
void Updater::CheckForUpdate()
|
2018-05-24 16:19:36 -06:00
|
|
|
{
|
2022-11-01 00:08:35 -06:00
|
|
|
AutoUpdateChecker::CheckForUpdate(m_update_track, m_hash_override,
|
|
|
|
AutoUpdateChecker::CheckType::Manual);
|
2018-03-22 05:20:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void Updater::OnUpdateAvailable(const NewVersionInformation& info)
|
|
|
|
{
|
|
|
|
bool later = false;
|
|
|
|
|
2018-05-21 16:27:12 -06:00
|
|
|
std::optional<int> choice = RunOnObject(m_parent, [&] {
|
2018-03-22 05:20:15 -06:00
|
|
|
QDialog* dialog = new QDialog(m_parent);
|
|
|
|
dialog->setWindowTitle(tr("Update available"));
|
2018-05-14 01:00:40 -06:00
|
|
|
dialog->setWindowFlags(dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2018-03-22 05:20:15 -06:00
|
|
|
|
|
|
|
auto* label = new QLabel(
|
|
|
|
tr("<h2>A new version of Dolphin is available!</h2>Dolphin %1 is available for "
|
|
|
|
"download. "
|
|
|
|
"You are running %2.<br> Would you like to update?<br><h4>Release Notes:</h4>")
|
|
|
|
.arg(QString::fromStdString(info.new_shortrev))
|
2022-01-13 16:04:22 -07:00
|
|
|
.arg(QString::fromStdString(Common::GetScmDescStr())));
|
2018-03-22 05:20:15 -06:00
|
|
|
label->setTextFormat(Qt::RichText);
|
|
|
|
|
|
|
|
auto* changelog = new QTextBrowser;
|
|
|
|
|
|
|
|
changelog->setHtml(QString::fromStdString(info.changelog_html));
|
|
|
|
changelog->setOpenExternalLinks(true);
|
|
|
|
changelog->setMinimumWidth(400);
|
|
|
|
|
|
|
|
auto* update_later_check = new QCheckBox(tr("Update after closing Dolphin"));
|
|
|
|
|
|
|
|
connect(update_later_check, &QCheckBox::toggled, [&](bool checked) { later = checked; });
|
|
|
|
|
|
|
|
auto* buttons = new QDialogButtonBox;
|
|
|
|
|
|
|
|
auto* never_btn =
|
|
|
|
buttons->addButton(tr("Never Auto-Update"), QDialogButtonBox::DestructiveRole);
|
|
|
|
buttons->addButton(tr("Remind Me Later"), QDialogButtonBox::RejectRole);
|
|
|
|
buttons->addButton(tr("Install Update"), QDialogButtonBox::AcceptRole);
|
|
|
|
|
|
|
|
auto* layout = new QVBoxLayout;
|
|
|
|
dialog->setLayout(layout);
|
|
|
|
|
|
|
|
layout->addWidget(label);
|
|
|
|
layout->addWidget(changelog);
|
|
|
|
layout->addWidget(update_later_check);
|
|
|
|
layout->addWidget(buttons);
|
|
|
|
|
2019-07-23 16:18:58 -06:00
|
|
|
connect(never_btn, &QPushButton::clicked, [dialog] {
|
2019-07-30 05:57:06 -06:00
|
|
|
Settings::Instance().SetAutoUpdateTrack(QString{});
|
2018-03-22 05:20:15 -06:00
|
|
|
dialog->reject();
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
|
|
|
|
|
|
|
|
return dialog->exec();
|
|
|
|
});
|
|
|
|
|
2018-05-21 16:27:12 -06:00
|
|
|
if (choice && *choice == QDialog::Accepted)
|
2018-03-22 05:20:15 -06:00
|
|
|
{
|
2018-03-22 17:29:03 -06:00
|
|
|
TriggerUpdate(info, later ? AutoUpdateChecker::RestartMode::NO_RESTART_AFTER_UPDATE :
|
|
|
|
AutoUpdateChecker::RestartMode::RESTART_AFTER_UPDATE);
|
2018-03-22 05:20:15 -06:00
|
|
|
|
|
|
|
if (!later)
|
2019-06-24 13:20:34 -06:00
|
|
|
{
|
|
|
|
RunOnObject(m_parent, [this] {
|
|
|
|
m_parent->close();
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
2018-03-22 05:20:15 -06:00
|
|
|
}
|
|
|
|
}
|