Skip to content

Commit ab3e956

Browse files
authored
Add update checker functionality (#538)
* Add update checker functionality * Update CMakeLists.txt and CMakePresets.json to disable Qt and add Foundation framework Remove UpdateDialog.cpp and UpdateDialog.hpp Refactor code in background-filter.cpp and enhance-filter.cpp * Refactor code to use std::regex_replace for plugin info replacement
1 parent 7f045cc commit ab3e956

9 files changed

+47
-112
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ endif()
8080
if(APPLE)
8181
add_subdirectory(src/update-checker/URLSessionClient)
8282
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE URLSessionClient)
83+
# add Foundation framework
84+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "-framework Foundation")
8385
elseif(MSVC)
8486
add_subdirectory(src/update-checker/WinRTHttpClient)
8587
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE WinRTHttpClient)
@@ -96,7 +98,6 @@ target_sources(
9698
src/obs-utils/obs-config-utils.cpp
9799
src/update-checker/github-utils.cpp
98100
src/update-checker/update-checker.cpp
99-
src/update-checker/UpdateDialog.cpp
100101
src/background-filter-info.c
101102
src/background-filter.cpp
102103
src/enhance-filter.cpp

CMakePresets.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"CODESIGN_IDENTITY": "$penv{CODESIGN_IDENT}",
2525
"CODESIGN_TEAM": "$penv{CODESIGN_TEAM}",
2626
"ENABLE_FRONTEND_API": true,
27-
"ENABLE_QT": true
27+
"ENABLE_QT": false
2828
}
2929
},
3030
{
@@ -54,7 +54,7 @@
5454
"QT_VERSION": "6",
5555
"CMAKE_SYSTEM_VERSION": "10.0.18363.657",
5656
"ENABLE_FRONTEND_API": true,
57-
"ENABLE_QT": true
57+
"ENABLE_QT": false
5858
}
5959
},
6060
{
@@ -83,7 +83,7 @@
8383
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
8484
"CMAKE_POSITION_INDEPENDENT_CODE": true,
8585
"ENABLE_FRONTEND_API": true,
86-
"ENABLE_QT": true
86+
"ENABLE_QT": false
8787
}
8888
},
8989
{
@@ -113,7 +113,7 @@
113113
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
114114
"CMAKE_POSITION_INDEPENDENT_CODE": true,
115115
"ENABLE_FRONTEND_API": true,
116-
"ENABLE_QT": true
116+
"ENABLE_QT": false
117117
}
118118
},
119119
{

src/background-filter.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
#include <fstream>
1515
#include <new>
1616
#include <mutex>
17-
18-
#include <QString>
17+
#include <regex>
1918

2019
#include <plugin-support.h>
2120
#include "models/ModelSINET.h"
@@ -28,6 +27,7 @@
2827
#include "ort-utils/ort-session-utils.h"
2928
#include "obs-utils/obs-utils.h"
3029
#include "consts.h"
30+
#include "update-checker/update-checker.h"
3131

3232
struct background_removal_filter : public filter_data {
3333
bool enableThreshold = true;
@@ -224,11 +224,17 @@ obs_properties_t *background_filter_properties(void *data)
224224
OBS_GROUP_NORMAL, focal_blur_props);
225225

226226
// Add a informative text about the plugin
227-
obs_properties_add_text(props, "info",
228-
QString(PLUGIN_INFO_TEMPLATE)
229-
.arg(PLUGIN_VERSION)
230-
.toStdString()
231-
.c_str(),
227+
// replace the placeholder with the current version
228+
// use std::regex_replace instead of QString::arg because the latter doesn't work on Linux
229+
std::string basic_info = std::regex_replace(
230+
PLUGIN_INFO_TEMPLATE, std::regex("%1"), PLUGIN_VERSION);
231+
// Check for update
232+
if (get_latest_version() != nullptr) {
233+
basic_info += std::regex_replace(
234+
PLUGIN_INFO_TEMPLATE_UPDATE_AVAILABLE, std::regex("%1"),
235+
get_latest_version());
236+
}
237+
obs_properties_add_text(props, "info", basic_info.c_str(),
232238
OBS_TEXT_INFO);
233239

234240
UNUSED_PARAMETER(data);

src/consts.h

+2
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ const char *const PLUGIN_INFO_TEMPLATE =
2828
"<a href=\"https://github.com/occ-ai/obs-backgroundremoval/\">Background Removal</a> (%1) by "
2929
"<a href=\"https://github.com/occ-ai\">OCC AI</a> ❤️ "
3030
"<a href=\"https://www.patreon.com/RoyShilkrot\">Support & Follow</a>";
31+
const char *const PLUGIN_INFO_TEMPLATE_UPDATE_AVAILABLE =
32+
"<center><a href=\"https://github.com/occ-ai/obs-backgroundremoval/releases\">🚀 Update available! (%1)</a></center>";
3133

3234
#endif /* CONSTS_H */

src/enhance-filter.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
#include <fstream>
1515
#include <new>
1616
#include <mutex>
17-
18-
#include <QString>
17+
#include <regex>
1918

2019
#include <plugin-support.h>
2120
#include "consts.h"
@@ -24,6 +23,7 @@
2423
#include "models/ModelTBEFN.h"
2524
#include "models/ModelZeroDCE.h"
2625
#include "models/ModelURetinex.h"
26+
#include "update-checker/update-checker.h"
2727

2828
struct enhance_filter : public filter_data {
2929
cv::Mat outputBGRA;
@@ -77,11 +77,16 @@ obs_properties_t *enhance_filter_properties(void *data)
7777
#endif
7878

7979
// Add a informative text about the plugin
80-
obs_properties_add_text(props, "info",
81-
QString(PLUGIN_INFO_TEMPLATE)
82-
.arg(PLUGIN_VERSION)
83-
.toStdString()
84-
.c_str(),
80+
// replace the placeholder with the current version using std::regex_replace
81+
std::string basic_info = std::regex_replace(
82+
PLUGIN_INFO_TEMPLATE, std::regex("%1"), PLUGIN_VERSION);
83+
// Check for update
84+
if (get_latest_version() != nullptr) {
85+
basic_info += std::regex_replace(
86+
PLUGIN_INFO_TEMPLATE_UPDATE_AVAILABLE, std::regex("%1"),
87+
get_latest_version());
88+
}
89+
obs_properties_add_text(props, "info", basic_info.c_str(),
8590
OBS_TEXT_INFO);
8691

8792
return props;

src/update-checker/UpdateDialog.cpp

-60
This file was deleted.

src/update-checker/UpdateDialog.hpp

-13
This file was deleted.

src/update-checker/update-checker.cpp

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "update-checker.h"
2-
#include "UpdateDialog.hpp"
32
#include "github-utils.h"
43
#include "obs-utils/obs-config-utils.h"
54

@@ -8,11 +7,9 @@
87

98
#include <plugin-support.h>
109

11-
#include <QTimer>
12-
1310
extern "C" const char *PLUGIN_VERSION;
1411

15-
UpdateDialog *update_dialog = nullptr;
12+
static std::string latestVersionForUpdate;
1613

1714
void check_update(void)
1815
{
@@ -40,26 +37,22 @@ void check_update(void)
4037

4138
if (info.version == PLUGIN_VERSION) {
4239
// No update available, latest version is the same as the current version
40+
latestVersionForUpdate.clear();
4341
return;
4442
}
4543

46-
try {
47-
QTimer::singleShot(2000, [=]() {
48-
QWidget *main_window = (QWidget *)
49-
obs_frontend_get_main_window();
50-
if (main_window == nullptr) {
51-
obs_log(LOG_ERROR,
52-
"Update Checker failed to get main window");
53-
return;
54-
}
55-
update_dialog =
56-
new UpdateDialog(info, main_window);
57-
update_dialog->exec();
58-
});
59-
} catch (...) {
60-
obs_log(LOG_ERROR, "Failed to construct UpdateDialog");
61-
}
44+
latestVersionForUpdate = info.version;
6245
};
6346

6447
github_utils_get_release_information(callback);
6548
}
49+
50+
const char *get_latest_version(void)
51+
{
52+
obs_log(LOG_INFO, "get_latest_version: %s",
53+
latestVersionForUpdate.c_str());
54+
if (latestVersionForUpdate.empty()) {
55+
return nullptr;
56+
}
57+
return latestVersionForUpdate.c_str();
58+
}

src/update-checker/update-checker.h

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extern "C" {
55
#endif
66

77
void check_update(void);
8+
const char *get_latest_version(void);
89

910
#ifdef __cplusplus
1011
}

0 commit comments

Comments
 (0)