-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update version check and dialog (#370)
* add version check and dialog with link * implement check updates box * lint * lint * avoid var shadow in linux * lint
- Loading branch information
Showing
8 changed files
with
146 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"check_for_updates": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,70 @@ | ||
#include "UpdateDialog.hpp" | ||
|
||
UpdateDialog::UpdateDialog(QWidget *parent) | ||
#include <obs.h> | ||
#include <obs-module.h> | ||
|
||
#include <QLabel> | ||
#include <QVBoxLayout> | ||
#include <QString> | ||
|
||
static QString dialogContent = | ||
"<p>A new version of the Background Removal plugin (<a " | ||
"href=\"https://github.com/royshil/obs-backgroundremoval/releases\">v{version}</a>) is " | ||
"now available for download. We've made some exciting updates and improvements that we think " | ||
"you'll love. To get the latest features and enhancements, please follow the link below:</p>" | ||
"<p>Download the latest version from GitHub: <a " | ||
"href=\"https://github.com/royshil/obs-backgroundremoval/releases\">v{version}</a></p>" | ||
"<p>Once you've downloaded the new version, install the update as usual, there's no need to " | ||
"uninstall the previous version.</p>" | ||
"<p>If you have any questions or need assistance during the update process, feel free to reach out" | ||
" to our <a href=\"https://github.com/royshil/obs-backgroundremoval/issues\">support team</a>.</p>" | ||
"<p>Thank you for using our plugin and we hope you enjoy the latest release! 🙏</p>"; | ||
|
||
UpdateDialog::UpdateDialog(const char *latestVersion, QWidget *parent) | ||
: QDialog(parent), layout(new QVBoxLayout) | ||
{ | ||
setWindowTitle("Update available!"); | ||
setWindowTitle("Background Removal - Update available! 🚀"); | ||
setLayout(layout); | ||
QLabel *label = new QLabel("OBS Background Removal: Update available!"); | ||
QLabel *label = new QLabel(dialogContent.replace( | ||
QString("{version}"), QString(latestVersion))); | ||
label->setOpenExternalLinks(true); | ||
label->setTextInteractionFlags(Qt::TextBrowserInteraction); | ||
label->setTextFormat(Qt::RichText); | ||
label->setWordWrap(true); | ||
layout->addWidget(label); | ||
// Add a checkbox to disable update checks | ||
QCheckBox *disableCheckbox = new QCheckBox("Disable update checks"); | ||
layout->addWidget(disableCheckbox); | ||
connect(disableCheckbox, &QCheckBox::stateChanged, this, | ||
&UpdateDialog::disableUpdateChecks); | ||
// Add a button to close the dialog | ||
QPushButton *closeButton = new QPushButton("Close"); | ||
layout->addWidget(closeButton); | ||
connect(closeButton, &QPushButton::clicked, this, &QDialog::close); | ||
} | ||
|
||
void UpdateDialog::disableUpdateChecks(int state) | ||
{ | ||
UNUSED_PARAMETER(state); | ||
|
||
// Get the config file | ||
char *config_file = obs_module_file("config.json"); | ||
if (!config_file) { | ||
blog(LOG_INFO, "Unable to find config file"); | ||
return; | ||
} | ||
|
||
// Parse the config file | ||
obs_data_t *json_data = obs_data_create_from_json_file(config_file); | ||
if (!json_data) { | ||
blog(LOG_INFO, "Failed to parse config file"); | ||
return; | ||
} | ||
|
||
// Update the config | ||
obs_data_set_bool(json_data, "check_for_updates", | ||
state == Qt::Unchecked); | ||
obs_data_save_json(json_data, config_file); | ||
|
||
obs_data_release(json_data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,44 @@ | ||
#include <QTimer> | ||
|
||
#include "update-checker.h" | ||
#include "UpdateDialog.hpp" | ||
|
||
#include <obs-frontend-api.h> | ||
#include <obs-module.h> | ||
|
||
#include <QTimer> | ||
|
||
UpdateDialog *update_dialog; | ||
|
||
void check_update(void) | ||
extern "C" const char *PLUGIN_VERSION; | ||
|
||
void check_update(const char *latestRelease) | ||
{ | ||
update_dialog = | ||
new UpdateDialog((QWidget *)obs_frontend_get_main_window()); | ||
// Check configuration to see if update checks are disabled | ||
char *config_file = obs_module_file("config.json"); | ||
if (!config_file) { | ||
blog(LOG_INFO, "Unable to find config file"); | ||
return; | ||
} | ||
|
||
obs_data_t *data = obs_data_create_from_json_file(config_file); | ||
if (!data) { | ||
blog(LOG_INFO, "Failed to parse config file"); | ||
return; | ||
} | ||
|
||
bool shouldCheckForUpdates = | ||
obs_data_get_bool(data, "check_for_updates"); | ||
obs_data_release(data); | ||
if (!shouldCheckForUpdates) { | ||
// Update checks are disabled | ||
return; | ||
} | ||
|
||
if (strcmp(latestRelease, PLUGIN_VERSION) == 0) { | ||
// No update available, latest version is the same as the current version | ||
return; | ||
} | ||
|
||
update_dialog = new UpdateDialog( | ||
latestRelease, (QWidget *)obs_frontend_get_main_window()); | ||
QTimer::singleShot(2000, update_dialog, &UpdateDialog::exec); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters