Skip to content

Commit cf61e40

Browse files
authored
add changelog to update dialog (#373)
1 parent 8b7003c commit cf61e40

11 files changed

+166
-63
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ target_sources(
7676
PRIVATE src/plugin-main.c
7777
src/ort-utils/ort-session-utils.cpp
7878
src/obs-utils/obs-utils.cpp
79+
src/obs-utils/obs-config-utils.cpp
7980
src/update-checker/github-utils.cpp
8081
src/update-checker/update-checker.cpp
8182
src/update-checker/UpdateDialog.cpp

buildspec.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
}
4646
},
4747
"name": "obs-backgroundremoval",
48-
"version": "1.0.3",
48+
"version": "1.1.0",
4949
"author": "Roy Shilkrot",
5050
"website": "https://github.com/royshil/obs-backgroundremoval",
5151
"email": "[email protected]",
@@ -54,4 +54,4 @@
5454
"macosInstaller": "368f7535-4e71-4587-952b-33ad935bf9f3",
5555
"windowsApp": "1527c9ec-2638-4e3b-94d7-cc25d27cd725"
5656
}
57-
}
57+
}

src/obs-utils/obs-config-utils.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "obs-config-utils.h"
2+
3+
#include <obs-module.h>
4+
5+
int getFlagFromConfig(const char *name, bool *returnValue)
6+
{
7+
// Check configuration to see if update checks are disabled
8+
char *config_file = obs_module_file("config.json");
9+
if (!config_file) {
10+
blog(LOG_INFO, "Unable to find config file");
11+
return OBS_BGREMOVAL_CONFIG_FAIL;
12+
}
13+
14+
obs_data_t *data = obs_data_create_from_json_file(config_file);
15+
if (!data) {
16+
blog(LOG_INFO, "Failed to parse config file");
17+
return OBS_BGREMOVAL_CONFIG_FAIL;
18+
}
19+
20+
*returnValue = obs_data_get_bool(data, name);
21+
obs_data_release(data);
22+
23+
return OBS_BGREMOVAL_CONFIG_SUCCESS;
24+
}
25+
26+
int setFlagFromConfig(const char *name, const bool value)
27+
{
28+
// Get the config file
29+
char *config_file = obs_module_file("config.json");
30+
if (!config_file) {
31+
blog(LOG_INFO, "Unable to find config file");
32+
return OBS_BGREMOVAL_CONFIG_FAIL;
33+
}
34+
35+
// Parse the config file
36+
obs_data_t *json_data = obs_data_create_from_json_file(config_file);
37+
if (!json_data) {
38+
blog(LOG_INFO, "Failed to parse config file");
39+
return OBS_BGREMOVAL_CONFIG_FAIL;
40+
}
41+
42+
// Update the config
43+
obs_data_set_bool(json_data, name, value);
44+
obs_data_save_json(json_data, config_file);
45+
46+
obs_data_release(json_data);
47+
48+
return OBS_BGREMOVAL_CONFIG_SUCCESS;
49+
}

src/obs-utils/obs-config-utils.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef OBS_CONFIG_UTILS_H
2+
#define OBS_CONFIG_UTILS_H
3+
4+
enum {
5+
OBS_BGREMOVAL_CONFIG_SUCCESS = 0,
6+
OBS_BGREMOVAL_CONFIG_FAIL = 1,
7+
};
8+
9+
/**
10+
* Get a boolean flasg from the module configuration file.
11+
*
12+
* @param name The name of the config item.
13+
* @param returnValue The value of the config item.
14+
* @return OBS_BGREMOVAL_CONFIG_SUCCESS if the config item was found,
15+
* OBS_BGREMOVAL_CONFIG_FAIL otherwise.
16+
*/
17+
int getFlagFromConfig(const char *name, bool *returnValue);
18+
19+
/**
20+
* Set a boolean flag in the module configuration file.
21+
*
22+
* @param name The name of the config item.
23+
* @param value The value of the config item.
24+
* @return OBS_BGREMOVAL_CONFIG_SUCCESS if the config item was found,
25+
* OBS_BGREMOVAL_CONFIG_FAIL otherwise.
26+
*/
27+
int setFlagFromConfig(const char *name, const bool value);
28+
29+
#endif /* OBS_CONFIG_UTILS_H */

src/plugin-main.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ bool obs_module_load(void)
4040
obs_register_source(&enhance_filter_info);
4141
obs_log(LOG_INFO, "plugin loaded successfully (version %s)",
4242
PLUGIN_VERSION);
43-
const char *latestRelease = github_utils_get_release();
44-
if (latestRelease != NULL) {
45-
obs_log(LOG_INFO, "latest release is %s", latestRelease);
43+
44+
const struct github_utils_release_information latestRelease =
45+
github_utils_get_release_information();
46+
if (latestRelease.responseCode == OBS_BGREMOVAL_GITHUB_UTILS_SUCCESS) {
47+
obs_log(LOG_INFO, "Latest release is %s",
48+
latestRelease.version);
4649
check_update(latestRelease);
50+
} else {
51+
obs_log(LOG_INFO, "failed to get latest release information");
4752
}
53+
github_utils_release_information_free(latestRelease);
54+
4855
return true;
4956
}
5057

src/update-checker/UpdateDialog.cpp

+23-31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "UpdateDialog.hpp"
2+
#include "obs-utils/obs-config-utils.h"
23

34
#include <obs.h>
45
#include <obs-module.h>
@@ -8,6 +9,7 @@
89
#include <QString>
910

1011
static QString dialogContent =
12+
"<h1>Background Removal - Update available! 🚀</h1>"
1113
"<p>A new version of the Background Removal plugin (<a "
1214
"href=\"https://github.com/royshil/obs-backgroundremoval/releases\">v{version}</a>) is "
1315
"now available for download. We've made some exciting updates and improvements that we think "
@@ -18,53 +20,43 @@ static QString dialogContent =
1820
"uninstall the previous version.</p>"
1921
"<p>If you have any questions or need assistance during the update process, feel free to reach out"
2022
" to our <a href=\"https://github.com/royshil/obs-backgroundremoval/issues\">support team</a>.</p>"
21-
"<p>Thank you for using our plugin and we hope you enjoy the latest release! 🙏</p>";
23+
"<p>Thank you for using our plugin and we hope you enjoy the latest release! 🙏</p>"
24+
"<h2>Changelog</h2>";
2225

23-
UpdateDialog::UpdateDialog(const char *latestVersion, QWidget *parent)
26+
UpdateDialog::UpdateDialog(
27+
struct github_utils_release_information latestVersion, QWidget *parent)
2428
: QDialog(parent), layout(new QVBoxLayout)
2529
{
2630
setWindowTitle("Background Removal - Update available! 🚀");
2731
setLayout(layout);
2832
QLabel *label = new QLabel(dialogContent.replace(
29-
QString("{version}"), QString(latestVersion)));
33+
QString("{version}"), QString(latestVersion.version)));
3034
label->setOpenExternalLinks(true);
3135
label->setTextInteractionFlags(Qt::TextBrowserInteraction);
3236
label->setTextFormat(Qt::RichText);
3337
label->setWordWrap(true);
3438
layout->addWidget(label);
39+
40+
QScrollArea *scrollArea = new QScrollArea;
41+
QLabel *scrollAreaLabel =
42+
new QLabel(QString(latestVersion.responseBody));
43+
scrollAreaLabel->setOpenExternalLinks(true);
44+
scrollAreaLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
45+
scrollAreaLabel->setTextFormat(Qt::MarkdownText);
46+
scrollAreaLabel->setWordWrap(true);
47+
scrollArea->setWidget(scrollAreaLabel);
48+
scrollArea->setWidgetResizable(true);
49+
layout->addWidget(scrollArea);
50+
3551
// Add a checkbox to disable update checks
3652
QCheckBox *disableCheckbox = new QCheckBox("Disable update checks");
3753
layout->addWidget(disableCheckbox);
38-
connect(disableCheckbox, &QCheckBox::stateChanged, this,
39-
&UpdateDialog::disableUpdateChecks);
54+
connect(disableCheckbox, &QCheckBox::stateChanged, this, [](int state) {
55+
setFlagFromConfig("check_for_updates", state == Qt::Unchecked);
56+
});
57+
4058
// Add a button to close the dialog
4159
QPushButton *closeButton = new QPushButton("Close");
4260
layout->addWidget(closeButton);
4361
connect(closeButton, &QPushButton::clicked, this, &QDialog::close);
4462
}
45-
46-
void UpdateDialog::disableUpdateChecks(int state)
47-
{
48-
UNUSED_PARAMETER(state);
49-
50-
// Get the config file
51-
char *config_file = obs_module_file("config.json");
52-
if (!config_file) {
53-
blog(LOG_INFO, "Unable to find config file");
54-
return;
55-
}
56-
57-
// Parse the config file
58-
obs_data_t *json_data = obs_data_create_from_json_file(config_file);
59-
if (!json_data) {
60-
blog(LOG_INFO, "Failed to parse config file");
61-
return;
62-
}
63-
64-
// Update the config
65-
obs_data_set_bool(json_data, "check_for_updates",
66-
state == Qt::Unchecked);
67-
obs_data_save_json(json_data, config_file);
68-
69-
obs_data_release(json_data);
70-
}

src/update-checker/UpdateDialog.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include <QtWidgets>
22

3+
#include "github-utils.h"
4+
35
class UpdateDialog : public QDialog {
46
Q_OBJECT
57
public:
6-
UpdateDialog(const char *latestVersion, QWidget *parent = nullptr);
8+
UpdateDialog(struct github_utils_release_information latestVersion,
9+
QWidget *parent = nullptr);
710

811
private:
912
QVBoxLayout *layout;
10-
void disableUpdateChecks(int state);
1113
};

src/update-checker/github-utils.cpp

+20-7
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ std::size_t writeFunctionStdString(void *ptr, std::size_t size, size_t nmemb,
2323
return size * nmemb;
2424
}
2525

26-
const char *github_utils_get_release(void)
26+
struct github_utils_release_information
27+
github_utils_get_release_information(void)
2728
{
2829
CURL *curl = curl_easy_init();
2930
if (!curl) {
3031
blog(LOG_INFO, "Failed to initialize curl");
31-
return NULL;
32+
return {OBS_BGREMOVAL_GITHUB_UTILS_ERROR, NULL, NULL};
3233
}
3334
CURLcode code;
3435
curl_easy_setopt(curl, CURLOPT_URL, GITHUB_LATEST_RELEASE_URL.c_str());
@@ -40,26 +41,38 @@ const char *github_utils_get_release(void)
4041
curl_easy_cleanup(curl);
4142
if (code != CURLE_OK) {
4243
blog(LOG_INFO, "Failed to get latest release info");
43-
return NULL;
44+
return {OBS_BGREMOVAL_GITHUB_UTILS_ERROR, NULL, NULL};
4445
}
4546

4647
// Parse the JSON response
4748
obs_data_t *data = obs_data_create_from_json(responseBody.c_str());
4849
if (!data) {
4950
blog(LOG_INFO, "Failed to parse latest release info");
50-
return NULL;
51+
return {OBS_BGREMOVAL_GITHUB_UTILS_ERROR, NULL, NULL};
5152
}
5253

5354
// The version is in the "tag_name" property
5455
char *version = strdup(obs_data_get_string(data, "tag_name"));
56+
char *body = strdup(obs_data_get_string(data, "body"));
5557
obs_data_release(data);
5658

57-
// remove the "v" prefix, if it exists
59+
// remove the "v" prefix in version, if it exists
5860
if (version[0] == 'v') {
59-
char *newVersion = strdup(version + 1);
61+
char *newVersion = (char *)malloc(strlen(version) - 1);
62+
strcpy(newVersion, version + 1);
6063
free(version);
6164
version = newVersion;
6265
}
6366

64-
return version;
67+
return {OBS_BGREMOVAL_GITHUB_UTILS_SUCCESS, body, version};
68+
}
69+
70+
void github_utils_release_information_free(
71+
struct github_utils_release_information info)
72+
{
73+
if (info.responseBody != NULL)
74+
free(info.responseBody);
75+
if (info.version != NULL)
76+
free(info.version);
77+
info.responseCode = OBS_BGREMOVAL_GITHUB_UTILS_ERROR;
6578
}

src/update-checker/github-utils.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@
44
extern "C" {
55
#endif
66

7-
const char *github_utils_get_release(void);
7+
enum {
8+
OBS_BGREMOVAL_GITHUB_UTILS_SUCCESS = 0,
9+
OBS_BGREMOVAL_GITHUB_UTILS_ERROR = -1,
10+
};
11+
12+
struct github_utils_release_information {
13+
int responseCode;
14+
char *responseBody;
15+
char *version;
16+
};
17+
18+
struct github_utils_release_information
19+
github_utils_get_release_information(void);
20+
21+
void github_utils_release_information_free(
22+
struct github_utils_release_information info);
823

924
#ifdef __cplusplus
1025
}

src/update-checker/update-checker.cpp

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "update-checker.h"
22
#include "UpdateDialog.hpp"
3+
#include "github-utils.h"
4+
#include "obs-utils/obs-config-utils.h"
35

46
#include <obs-frontend-api.h>
57
#include <obs-module.h>
@@ -10,30 +12,21 @@ UpdateDialog *update_dialog;
1012

1113
extern "C" const char *PLUGIN_VERSION;
1214

13-
void check_update(const char *latestRelease)
15+
void check_update(struct github_utils_release_information latestRelease)
1416
{
15-
// Check configuration to see if update checks are disabled
16-
char *config_file = obs_module_file("config.json");
17-
if (!config_file) {
18-
blog(LOG_INFO, "Unable to find config file");
19-
return;
20-
}
21-
22-
obs_data_t *data = obs_data_create_from_json_file(config_file);
23-
if (!data) {
24-
blog(LOG_INFO, "Failed to parse config file");
25-
return;
17+
bool shouldCheckForUpdates = false;
18+
if (getFlagFromConfig("check_for_updates", &shouldCheckForUpdates) !=
19+
OBS_BGREMOVAL_CONFIG_SUCCESS) {
20+
// Failed to get the config value, assume it's enabled
21+
shouldCheckForUpdates = true;
2622
}
2723

28-
bool shouldCheckForUpdates =
29-
obs_data_get_bool(data, "check_for_updates");
30-
obs_data_release(data);
3124
if (!shouldCheckForUpdates) {
3225
// Update checks are disabled
3326
return;
3427
}
3528

36-
if (strcmp(latestRelease, PLUGIN_VERSION) == 0) {
29+
if (strcmp(latestRelease.version, PLUGIN_VERSION) == 0) {
3730
// No update available, latest version is the same as the current version
3831
return;
3932
}

src/update-checker/update-checker.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#pragma once
22

3+
#include "github-utils.h"
4+
35
#ifdef __cplusplus
46
extern "C" {
57
#endif
68

7-
void check_update(const char *latestRelease);
9+
void check_update(struct github_utils_release_information latestRelease);
810

911
#ifdef __cplusplus
1012
}

0 commit comments

Comments
 (0)