A new version of the Background Removal plugin (v{version}) 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:
" + "Download the latest version from GitHub: v{version}
" + "Once you've downloaded the new version, install the update as usual, there's no need to " + "uninstall the previous version.
" + "If you have any questions or need assistance during the update process, feel free to reach out" + " to our support team.
" + "Thank you for using our plugin and we hope you enjoy the latest release! 🙏
"; + +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); } diff --git a/src/update-checker/UpdateDialog.hpp b/src/update-checker/UpdateDialog.hpp index 5011d3df..1c7a5871 100644 --- a/src/update-checker/UpdateDialog.hpp +++ b/src/update-checker/UpdateDialog.hpp @@ -3,8 +3,9 @@ class UpdateDialog : public QDialog { Q_OBJECT public: - UpdateDialog(QWidget *parent = nullptr); + UpdateDialog(const char *latestVersion, QWidget *parent = nullptr); private: QVBoxLayout *layout; + void disableUpdateChecks(int state); }; diff --git a/src/update-checker/github-utils.cpp b/src/update-checker/github-utils.cpp index 45179eeb..22cc2aed 100644 --- a/src/update-checker/github-utils.cpp +++ b/src/update-checker/github-utils.cpp @@ -23,21 +23,43 @@ std::size_t writeFunctionStdString(void *ptr, std::size_t size, size_t nmemb, return size * nmemb; } -void github_utils_get_release(void) +const char *github_utils_get_release(void) { CURL *curl = curl_easy_init(); - if (curl) { - std::string str; - CURLcode code; - curl_easy_setopt(curl, CURLOPT_URL, - GITHUB_LATEST_RELEASE_URL.c_str()); - curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT.c_str()); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, - writeFunctionStdString); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &str); - code = curl_easy_perform(curl); - curl_easy_cleanup(curl); - blog(LOG_INFO, "%s\n", str.c_str()); - blog(LOG_INFO, "%s\n", curl_easy_strerror(code)); + if (!curl) { + blog(LOG_INFO, "Failed to initialize curl"); + return NULL; } + CURLcode code; + curl_easy_setopt(curl, CURLOPT_URL, GITHUB_LATEST_RELEASE_URL.c_str()); + curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT.c_str()); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeFunctionStdString); + std::string responseBody; + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseBody); + code = curl_easy_perform(curl); + curl_easy_cleanup(curl); + if (code != CURLE_OK) { + blog(LOG_INFO, "Failed to get latest release info"); + return NULL; + } + + // Parse the JSON response + obs_data_t *data = obs_data_create_from_json(responseBody.c_str()); + if (!data) { + blog(LOG_INFO, "Failed to parse latest release info"); + return NULL; + } + + // The version is in the "tag_name" property + char *version = strdup(obs_data_get_string(data, "tag_name")); + obs_data_release(data); + + // remove the "v" prefix, if it exists + if (version[0] == 'v') { + char *newVersion = strdup(version + 1); + free(version); + version = newVersion; + } + + return version; } diff --git a/src/update-checker/github-utils.h b/src/update-checker/github-utils.h index b767204b..bba6dae6 100644 --- a/src/update-checker/github-utils.h +++ b/src/update-checker/github-utils.h @@ -4,7 +4,7 @@ extern "C" { #endif -void github_utils_get_release(void); +const char *github_utils_get_release(void); #ifdef __cplusplus } diff --git a/src/update-checker/update-checker.cpp b/src/update-checker/update-checker.cpp index fefd4547..b4941947 100644 --- a/src/update-checker/update-checker.cpp +++ b/src/update-checker/update-checker.cpp @@ -1,15 +1,44 @@ -#include