Skip to content

Commit

Permalink
Modest update notification (#178)
Browse files Browse the repository at this point in the history
* Fix

* Fix

* Fix

* Fix

* Format
  • Loading branch information
umireon authored Apr 22, 2024
1 parent d6b1963 commit 1cda4b7
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 393 deletions.
12 changes: 2 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,8 @@ if(ENABLE_QT)
AUTORCC ON)
endif()

target_sources(
${CMAKE_PROJECT_NAME}
PRIVATE src/plugin-main.c
src/screen-source.cpp
src/factory.cpp
src/ScreenBuilder/ActionHandler.cpp
src/ScreenBuilder/StateMachine.cpp
src/UpdateChecker/UpdateDialog.cpp
src/UpdateChecker/UpdateChecker.cpp
src/UpdateChecker/CurlClient.cpp)
target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/plugin-main.c src/screen-source.cpp src/factory.cpp
src/ScreenBuilder/ActionHandler.cpp src/ScreenBuilder/StateMachine.cpp)

include(cmake/FetchOpenCV.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${OpenCV_LIBS})
Expand Down
2 changes: 1 addition & 1 deletion buildspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"name": "obs-pokemon-sv-screen-builder",
"displayName": "OBS Pokémon SV Screen Builder",
"version": "0.7.4",
"version": "0.7.5",
"author": "Kaito Udagawa",
"website": "https://github.com/umireon/obs-pokemon-sv-screen-builder",
"email": "[email protected]",
Expand Down
3 changes: 3 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ PokemonSVScreenBuilderOpponentRank="Pokémon SV (Opponent Rank)"
PokemonSVScreenBuilderMyRank="Pokémon SV (My Rank)"
GamePlaySource="Game Play Source"
TimerSource="Timer Source"
VersionInfoTextLatest="OBS Pokémon SV Screen Builder 0.0.0 - This is the latest version"
VersionInfoTextUpdateAvailable="OBS Pokémon SV Screen Builder 0.0.0 - Update available!"
CustomDataDescription="Custom data"

AddDefaultLayoutDescription="Add sources for default layout"
MySelectionSource="My Selection"
Expand Down
3 changes: 3 additions & 0 deletions data/locale/ja-JP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ PokemonSVScreenBuilderOpponentRank="ポケモンSV(相手のランク)"
PokemonSVScreenBuilderMyRank="ポケモンSV (自分のランク)"
GamePlaySource="ゲーム画面ソース"
TimerSource="タイマーソース"
VersionInfoTextLatest="OBSポケモンSVスクリーンビルダー 0.0.0 - 最新です"
VersionInfoTextUpdateAvailable="OBSポケモンSVスクリーンビルダー 0.0.0 - アップデートがあります!"
GoToDownloadPage="ダウンロードはこちら"

AddDefaultLayoutDescription="デフォルトレイアウトのソースを追加"
MySelectionSource="自分の選出"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <functional>
#pragma once

#include <string>

#include <curl/curl.h>
Expand All @@ -7,38 +8,41 @@

#include "plugin-support.h"

const std::string userAgent = std::string(PLUGIN_NAME) + "/" + PLUGIN_VERSION;
namespace UpdateChecker {
static const std::string userAgent =
std::string(PLUGIN_NAME) + "/" + PLUGIN_VERSION;

static std::size_t writeFunc(void *ptr, std::size_t size, size_t nmemb,
std::string *data)
static std::size_t fetchStringFromUrlWriteFunc(void *ptr, std::size_t size,
size_t nmemb, std::string *data)
{
data->append(static_cast<char *>(ptr), size * nmemb);
return size * nmemb;
}

void fetchStringFromUrl(const char *urlString,
std::function<void(std::string, int)> callback)
static std::string fetchStringFromUrl(const char *urlString)
{
CURL *curl = curl_easy_init();
if (!curl) {
obs_log(LOG_INFO, "Failed to initialize curl");
callback("", CURL_LAST);
return;
return "";
}

std::string responseBody;
curl_easy_setopt(curl, CURLOPT_URL, urlString);
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeFunc);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
fetchStringFromUrlWriteFunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseBody);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

CURLcode code = curl_easy_perform(curl);
curl_easy_cleanup(curl);

if (code == CURLE_OK) {
callback(responseBody, 0);
return responseBody;
} else {
obs_log(LOG_INFO, "Failed to get latest release info");
callback("", code);
return "";
}
}
} // namespace UpdateChecker
7 changes: 0 additions & 7 deletions src/UpdateChecker/CurlClient/CMakeLists.txt

This file was deleted.

44 changes: 0 additions & 44 deletions src/UpdateChecker/CurlClient/CurlClient.cpp

This file was deleted.

70 changes: 19 additions & 51 deletions src/UpdateChecker/GitHubClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,29 @@

#include <string>

#include <nlohmann/json.hpp>

#include <obs.h>

#include "plugin-support.h"

void fetchStringFromUrl(const char *urlString,
std::function<void(std::string, int)> callback);

class GitHubClient {
public:
struct LatestRelease {
std::string version;
std::string body;
bool error;
};
#include "CurlClient.hpp"

void getLatestRelease(const char *latestReleaseUrl,
std::function<void(LatestRelease)> callback) const
{
auto cb = [callback](std::string responseBody, int errorCode) {
if (errorCode != 0) {
obs_log(LOG_INFO,
"Failed to get the latest release info!");
callback({"", "", true});
return;
}

obs_data_t *data =
obs_data_create_from_json(responseBody.c_str());
if (!data) {
obs_log(LOG_INFO,
"Failed to parse the latest release info! %s",
responseBody.c_str());
callback({"", "", true});
return;
}
namespace UpdateChecker {
std::string getLatestReleaseVersion(const char *latestReleaseUrl)
{
std::string responseBody = fetchStringFromUrl(latestReleaseUrl);
if (responseBody.empty()) {
obs_log(LOG_INFO, "Failed to get the latest release info!");
return "";
}

LatestRelease result;
const char *version =
obs_data_get_string(data, "tag_name");
const char *body = obs_data_get_string(data, "body");
if (!version || !body) {
obs_log(LOG_INFO,
"Malformed JSON from GitHub!");
result.error = true;
} else {
result.version =
obs_data_get_string(data, "tag_name");
result.body = obs_data_get_string(data, "body");
result.error = false;
}
obs_data_release(data);
callback(result);
};
fetchStringFromUrl(latestReleaseUrl, cb);
obs_data_t *data = obs_data_create_from_json(responseBody.c_str());
const char *rawVersion = obs_data_get_string(data, "tag_name");
if (!rawVersion) {
obs_log(LOG_INFO, "Malformed JSON from GitHub!");
return "";
}
};
std::string version = rawVersion;
obs_data_release(data);
return version;
}
} // namespace UpdateChecker
3 changes: 0 additions & 3 deletions src/UpdateChecker/URLSessionClient/CMakeLists.txt

This file was deleted.

41 changes: 0 additions & 41 deletions src/UpdateChecker/URLSessionClient/URLSessionClient.mm

This file was deleted.

82 changes: 0 additions & 82 deletions src/UpdateChecker/UpdateChecker.cpp

This file was deleted.

13 changes: 0 additions & 13 deletions src/UpdateChecker/UpdateChecker.h

This file was deleted.

Loading

0 comments on commit 1cda4b7

Please sign in to comment.