2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
#include "ui-updater.hpp"
|
|
|
|
#include "common.hpp"
|
2021-09-07 02:29:41 +00:00
|
|
|
#include "util/util-logging.hpp"
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2021-09-07 02:29:41 +00:00
|
|
|
#define ST_PREFIX "<%s> "
|
|
|
|
#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
|
|
|
|
#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
|
|
|
|
#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
|
|
|
|
#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
|
2020-09-09 03:06:15 +00:00
|
|
|
#else
|
2021-09-07 02:29:41 +00:00
|
|
|
#define ST_PREFIX "<ui::updater> "
|
|
|
|
#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__)
|
|
|
|
#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__)
|
|
|
|
#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__)
|
|
|
|
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
|
2020-09-09 03:06:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define D_I18N_MENU_CHECKFORUPDATES "UI.Updater.Menu.CheckForUpdates"
|
|
|
|
#define D_I18N_MENU_CHECKFORUPDATES_AUTOMATICALLY "UI.Updater.Menu.CheckForUpdates.Automatically"
|
|
|
|
#define D_I18N_MENU_CHANNEL "UI.Updater.Menu.Channel"
|
2022-06-11 06:02:41 +00:00
|
|
|
#define D_I18N_MENU_CHANNEL_STABLE "UI.Updater.Menu.Channel.Stable"
|
|
|
|
#define D_I18N_MENU_CHANNEL_CANDIDATE "UI.Updater.Menu.Channel.Candidate"
|
|
|
|
#define D_I18N_MENU_CHANNEL_BETA "UI.Updater.Menu.Channel.Beta"
|
|
|
|
#define D_I18N_MENU_CHANNEL_ALPHA "UI.Updater.Menu.Channel.Alpha"
|
2020-09-09 03:06:15 +00:00
|
|
|
#define D_I18N_DIALOG_TITLE "UI.Updater.Dialog.Title"
|
|
|
|
#define D_I18N_GITHUBPERMISSION_TITLE "UI.Updater.GitHubPermission.Title"
|
|
|
|
#define D_I18N_GITHUBPERMISSION_TEXT "UI.Updater.GitHubPermission.Text"
|
|
|
|
|
|
|
|
streamfx::ui::updater_dialog::updater_dialog() : QDialog(reinterpret_cast<QWidget*>(obs_frontend_get_main_window()))
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
|
|
|
setWindowFlag(Qt::WindowMinimizeButtonHint, false);
|
|
|
|
setWindowFlag(Qt::WindowMaximizeButtonHint, false);
|
2022-06-11 06:02:41 +00:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose, false); // Do not delete on close.
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
connect(ok, &QPushButton::clicked, this, &streamfx::ui::updater_dialog::on_ok);
|
|
|
|
connect(cancel, &QPushButton::clicked, this, &streamfx::ui::updater_dialog::on_cancel);
|
|
|
|
}
|
|
|
|
|
|
|
|
streamfx::ui::updater_dialog::~updater_dialog() {}
|
|
|
|
|
2022-06-11 06:02:41 +00:00
|
|
|
void streamfx::ui::updater_dialog::show(streamfx::version_info current, streamfx::version_info update)
|
2020-09-09 03:06:15 +00:00
|
|
|
{
|
2022-06-11 06:02:41 +00:00
|
|
|
currentVersion->setText(QString::fromStdString(static_cast<std::string>(current)));
|
|
|
|
latestVersion->setText(QString::fromStdString(static_cast<std::string>(update)));
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
{
|
2022-06-11 06:02:41 +00:00
|
|
|
std::string buf = latestVersion->text().toStdString();
|
|
|
|
std::vector<char> buf2;
|
|
|
|
buf2.resize(static_cast<size_t>(snprintf(nullptr, 0, D_TRANSLATE(D_I18N_DIALOG_TITLE), buf.data())) + 1);
|
|
|
|
snprintf(buf2.data(), buf2.size(), D_TRANSLATE(D_I18N_DIALOG_TITLE), buf.data());
|
|
|
|
setWindowTitle(QString::fromUtf8(buf2.data()));
|
2020-09-09 03:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_update_url = QUrl(QString::fromStdString(update.url));
|
|
|
|
|
2020-09-30 00:20:16 +00:00
|
|
|
this->setModal(true);
|
2020-09-09 03:06:15 +00:00
|
|
|
QDialog::show();
|
|
|
|
}
|
|
|
|
|
2020-09-30 00:20:16 +00:00
|
|
|
void streamfx::ui::updater_dialog::hide()
|
|
|
|
{
|
|
|
|
QDialog::hide();
|
2020-11-01 23:36:57 +00:00
|
|
|
this->setModal(false);
|
2020-09-30 00:20:16 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 03:06:15 +00:00
|
|
|
void streamfx::ui::updater_dialog::on_ok()
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(_update_url);
|
|
|
|
hide();
|
2022-06-11 06:02:41 +00:00
|
|
|
accept();
|
2020-09-09 03:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::updater_dialog::on_cancel()
|
|
|
|
{
|
|
|
|
hide();
|
2022-06-11 06:02:41 +00:00
|
|
|
reject();
|
2020-09-09 03:06:15 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 12:35:46 +00:00
|
|
|
streamfx::ui::updater::updater(QMenu* menu) : _updater(), _dialog(nullptr), _gdpr(nullptr), _cfu(nullptr), _cfu_auto(nullptr), _channel(nullptr), _channel_menu(nullptr), _channel_stable(nullptr), _channel_candidate(nullptr), _channel_beta(nullptr), _channel_alpha(nullptr), _channel_group(nullptr)
|
2020-09-09 03:06:15 +00:00
|
|
|
{
|
|
|
|
// Create dialog.
|
|
|
|
_dialog = new updater_dialog();
|
|
|
|
|
|
|
|
{ // Create the necessary menu entries.
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
// Check for Updates
|
|
|
|
_cfu = menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHECKFORUPDATES)));
|
2021-04-19 12:01:09 +00:00
|
|
|
_cfu->setMenuRole(QAction::NoRole);
|
2020-09-09 03:06:15 +00:00
|
|
|
connect(_cfu, &QAction::triggered, this, &streamfx::ui::updater::on_cfu_triggered);
|
|
|
|
|
|
|
|
// Automatically check for Updates
|
|
|
|
_cfu_auto = menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHECKFORUPDATES_AUTOMATICALLY)));
|
2021-04-19 12:01:09 +00:00
|
|
|
_cfu_auto->setMenuRole(QAction::NoRole);
|
2020-09-09 03:06:15 +00:00
|
|
|
_cfu_auto->setCheckable(true);
|
|
|
|
connect(_cfu_auto, &QAction::toggled, this, &streamfx::ui::updater::on_cfu_auto_toggled);
|
|
|
|
|
|
|
|
// Update Channel
|
|
|
|
_channel_menu = menu->addMenu(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL)));
|
2021-04-19 12:01:09 +00:00
|
|
|
_channel_menu->menuAction()->setMenuRole(QAction::NoRole);
|
2020-09-09 03:06:15 +00:00
|
|
|
|
2022-06-11 06:02:41 +00:00
|
|
|
_channel_stable = _channel_menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL_STABLE)));
|
2021-04-19 12:01:09 +00:00
|
|
|
_channel_stable->setMenuRole(QAction::NoRole);
|
2020-09-09 03:06:15 +00:00
|
|
|
_channel_stable->setCheckable(true);
|
|
|
|
|
2022-06-11 06:02:41 +00:00
|
|
|
_channel_candidate = _channel_menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL_CANDIDATE)));
|
|
|
|
_channel_candidate->setMenuRole(QAction::NoRole);
|
|
|
|
_channel_candidate->setCheckable(true);
|
|
|
|
|
|
|
|
_channel_beta = _channel_menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL_BETA)));
|
|
|
|
_channel_beta->setMenuRole(QAction::NoRole);
|
|
|
|
_channel_beta->setCheckable(true);
|
|
|
|
|
|
|
|
_channel_alpha = _channel_menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL_ALPHA)));
|
|
|
|
_channel_alpha->setMenuRole(QAction::NoRole);
|
|
|
|
_channel_alpha->setCheckable(true);
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
_channel_group = new QActionGroup(_channel_menu);
|
|
|
|
_channel_group->addAction(_channel_stable);
|
2022-06-11 06:02:41 +00:00
|
|
|
_channel_group->addAction(_channel_candidate);
|
|
|
|
_channel_group->addAction(_channel_beta);
|
|
|
|
_channel_group->addAction(_channel_alpha);
|
2020-09-09 03:06:15 +00:00
|
|
|
connect(_channel_group, &QActionGroup::triggered, this, &streamfx::ui::updater::on_channel_group_triggered);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connect internal signals.
|
2023-05-13 12:35:46 +00:00
|
|
|
connect(this, &streamfx::ui::updater::autoupdate_changed, this, &streamfx::ui::updater::on_autoupdate_changed, Qt::QueuedConnection);
|
|
|
|
connect(this, &streamfx::ui::updater::channel_changed, this, &streamfx::ui::updater::on_channel_changed, Qt::QueuedConnection);
|
|
|
|
connect(this, &streamfx::ui::updater::update_detected, this, &streamfx::ui::updater::on_update_detected, Qt::QueuedConnection);
|
|
|
|
connect(this, &streamfx::ui::updater::check_active, this, &streamfx::ui::updater::on_check_active, Qt::QueuedConnection);
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
{ // Retrieve the updater object and listen to it.
|
|
|
|
_updater = streamfx::updater::instance();
|
2023-05-13 12:35:46 +00:00
|
|
|
_updater->events.automation_changed.add(std::bind(&streamfx::ui::updater::on_updater_automation_changed, this, std::placeholders::_1, std::placeholders::_2));
|
|
|
|
_updater->events.channel_changed.add(std::bind(&streamfx::ui::updater::on_updater_channel_changed, this, std::placeholders::_1, std::placeholders::_2));
|
|
|
|
_updater->events.refreshed.add(std::bind(&streamfx::ui::updater::on_updater_refreshed, this, std::placeholders::_1));
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
// Sync with updater information.
|
2022-06-11 06:02:41 +00:00
|
|
|
emit autoupdate_changed(_updater->is_automated());
|
|
|
|
emit channel_changed(_updater->get_channel());
|
2020-09-09 03:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
streamfx::ui::updater::~updater() {}
|
|
|
|
|
|
|
|
void streamfx::ui::updater::on_updater_automation_changed(streamfx::updater&, bool value)
|
|
|
|
{
|
|
|
|
emit autoupdate_changed(value);
|
|
|
|
}
|
|
|
|
|
2022-06-11 06:02:41 +00:00
|
|
|
void streamfx::ui::updater::on_updater_channel_changed(streamfx::updater&, streamfx::version_stage channel)
|
2020-09-09 03:06:15 +00:00
|
|
|
{
|
|
|
|
emit channel_changed(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::updater::on_updater_refreshed(streamfx::updater&)
|
|
|
|
{
|
|
|
|
emit check_active(false);
|
|
|
|
|
2022-06-11 06:02:41 +00:00
|
|
|
if (!_updater->is_update_available())
|
2020-09-09 03:06:15 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
emit update_detected();
|
|
|
|
}
|
|
|
|
|
2021-01-21 01:42:56 +00:00
|
|
|
void streamfx::ui::updater::obs_ready()
|
|
|
|
{
|
2022-06-11 06:02:41 +00:00
|
|
|
if (_updater->is_automated()) {
|
|
|
|
if (_updater->is_data_sharing_allowed()) {
|
2021-01-21 01:42:56 +00:00
|
|
|
_updater->refresh();
|
|
|
|
} else {
|
|
|
|
create_gdpr_box();
|
|
|
|
_gdpr->exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-11 06:02:41 +00:00
|
|
|
void streamfx::ui::updater::on_channel_changed(streamfx::version_stage ch)
|
2020-09-09 03:06:15 +00:00
|
|
|
{
|
2022-06-11 06:02:41 +00:00
|
|
|
QSignalBlocker bgroup(_channel_group);
|
|
|
|
QSignalBlocker bs(_channel_stable);
|
|
|
|
QSignalBlocker bc(_channel_candidate);
|
|
|
|
QSignalBlocker bb(_channel_beta);
|
|
|
|
QSignalBlocker ba(_channel_alpha);
|
|
|
|
_channel_stable->setChecked(ch == streamfx::version_stage::STABLE);
|
|
|
|
_channel_candidate->setChecked(ch == streamfx::version_stage::CANDIDATE);
|
|
|
|
_channel_beta->setChecked(ch == streamfx::version_stage::BETA);
|
|
|
|
_channel_alpha->setChecked(ch == streamfx::version_stage::ALPHA);
|
2020-09-09 03:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::updater::on_update_detected()
|
|
|
|
{
|
|
|
|
_dialog->show(_updater->get_current_info(), _updater->get_update_info());
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::updater::on_autoupdate_changed(bool enabled)
|
|
|
|
{
|
2022-06-11 06:02:41 +00:00
|
|
|
QSignalBlocker blocker(_cfu_auto);
|
2020-09-09 03:06:15 +00:00
|
|
|
_cfu_auto->setChecked(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::updater::on_gdpr_button(QAbstractButton* btn)
|
|
|
|
{
|
|
|
|
if (_gdpr->standardButton(btn) == QMessageBox::Ok) {
|
2022-06-11 06:02:41 +00:00
|
|
|
_updater->set_data_sharing_allowed(true);
|
2020-09-09 03:06:15 +00:00
|
|
|
emit check_active(true);
|
|
|
|
_updater->refresh();
|
|
|
|
} else {
|
2022-06-11 06:02:41 +00:00
|
|
|
_updater->set_data_sharing_allowed(false);
|
2020-09-09 03:06:15 +00:00
|
|
|
_updater->set_automation(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::updater::on_cfu_triggered(bool)
|
|
|
|
{
|
2022-06-11 06:02:41 +00:00
|
|
|
if (!_updater->is_data_sharing_allowed()) {
|
2020-09-30 00:20:16 +00:00
|
|
|
create_gdpr_box();
|
2020-09-09 03:06:15 +00:00
|
|
|
_gdpr->exec();
|
|
|
|
} else {
|
|
|
|
emit check_active(true);
|
|
|
|
_updater->refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::updater::on_cfu_auto_toggled(bool flag)
|
|
|
|
{
|
|
|
|
_updater->set_automation(flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::updater::on_channel_group_triggered(QAction* action)
|
|
|
|
{
|
2022-06-11 06:02:41 +00:00
|
|
|
if (action == _channel_alpha) {
|
|
|
|
_updater->set_channel(streamfx::version_stage::ALPHA);
|
|
|
|
} else if (action == _channel_beta) {
|
|
|
|
_updater->set_channel(streamfx::version_stage::BETA);
|
|
|
|
} else if (action == _channel_candidate) {
|
|
|
|
_updater->set_channel(streamfx::version_stage::CANDIDATE);
|
2020-09-09 03:06:15 +00:00
|
|
|
} else {
|
2022-06-11 06:02:41 +00:00
|
|
|
_updater->set_channel(streamfx::version_stage::STABLE);
|
2020-09-09 03:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<streamfx::ui::updater> streamfx::ui::updater::instance(QMenu* menu)
|
|
|
|
{
|
|
|
|
static std::weak_ptr<streamfx::ui::updater> _instance;
|
|
|
|
static std::mutex _lock;
|
|
|
|
|
|
|
|
auto lock = std::lock_guard<std::mutex>(_lock);
|
|
|
|
if (_instance.expired() && menu) {
|
|
|
|
auto ptr = std::make_shared<streamfx::ui::updater>(menu);
|
|
|
|
_instance = ptr;
|
|
|
|
return ptr;
|
|
|
|
} else {
|
|
|
|
return _instance.lock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void streamfx::ui::updater::on_check_active(bool active)
|
|
|
|
{
|
|
|
|
_cfu->setEnabled(!active);
|
|
|
|
_channel_group->setEnabled(!active);
|
2022-06-11 06:02:41 +00:00
|
|
|
_channel_alpha->setEnabled(!active);
|
|
|
|
_channel_beta->setEnabled(!active);
|
|
|
|
_channel_candidate->setEnabled(!active);
|
2020-09-09 03:06:15 +00:00
|
|
|
_channel_stable->setEnabled(!active);
|
|
|
|
_channel_menu->setEnabled(!active);
|
|
|
|
}
|
2020-09-30 00:20:16 +00:00
|
|
|
|
|
|
|
void streamfx::ui::updater::create_gdpr_box()
|
|
|
|
{
|
|
|
|
if (_gdpr) {
|
|
|
|
_gdpr->deleteLater();
|
|
|
|
_gdpr = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create GitHub message box.
|
|
|
|
_gdpr = new QMessageBox(reinterpret_cast<QWidget*>(obs_frontend_get_main_window()));
|
|
|
|
_gdpr->setWindowTitle(QString::fromUtf8(D_TRANSLATE(D_I18N_GITHUBPERMISSION_TITLE)));
|
|
|
|
_gdpr->setTextFormat(Qt::TextFormat::RichText);
|
|
|
|
_gdpr->setText(QString::fromUtf8(D_TRANSLATE(D_I18N_GITHUBPERMISSION_TEXT)));
|
|
|
|
_gdpr->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
connect(_gdpr, &QMessageBox::buttonClicked, this, &streamfx::ui::updater::on_gdpr_button);
|
|
|
|
}
|