mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-19 01:36:12 +08:00
UI: Migrate branches to nlohmann JSON
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
include_guard(DIRECTORY)
|
||||
|
||||
find_package(nlohmann_json REQUIRED)
|
||||
|
||||
if(NOT TARGET OBS::blake2)
|
||||
add_subdirectory("${CMAKE_SOURCE_DIR}/deps/blake2" "${CMAKE_BINARY_DIR}/deps/blake2")
|
||||
endif()
|
||||
|
||||
target_sources(obs-studio PRIVATE update/crypto-helpers.hpp update/crypto-helpers-mac.mm update/shared-update.cpp
|
||||
update/shared-update.hpp update/update-helpers.cpp update/update-helpers.hpp)
|
||||
target_sources(
|
||||
obs-studio
|
||||
PRIVATE update/crypto-helpers.hpp
|
||||
update/crypto-helpers-mac.mm
|
||||
update/shared-update.cpp
|
||||
update/shared-update.hpp
|
||||
update/update-helpers.cpp
|
||||
update/update-helpers.hpp
|
||||
update/models/branches.hpp)
|
||||
|
||||
target_link_libraries(obs-studio PRIVATE "$<LINK_LIBRARY:FRAMEWORK,Security.framework>" OBS::blake2)
|
||||
target_link_libraries(obs-studio PRIVATE "$<LINK_LIBRARY:FRAMEWORK,Security.framework>" nlohmann_json::nlohmann_json
|
||||
OBS::blake2)
|
||||
|
||||
+14
-4
@@ -357,6 +357,7 @@ if(OS_WINDOWS)
|
||||
update/update-helpers.hpp
|
||||
update/crypto-helpers-mbedtls.cpp
|
||||
update/crypto-helpers.hpp
|
||||
update/models/branches.hpp
|
||||
win-update/updater/manifest.hpp
|
||||
${CMAKE_BINARY_DIR}/obs.rc)
|
||||
|
||||
@@ -425,17 +426,26 @@ elseif(OS_MACOS)
|
||||
|
||||
if(ENABLE_WHATSNEW)
|
||||
find_library(SECURITY Security)
|
||||
find_package(nlohmann_json REQUIRED)
|
||||
mark_as_advanced(SECURITY)
|
||||
target_link_libraries(obs PRIVATE ${SECURITY} OBS::blake2)
|
||||
|
||||
target_sources(obs PRIVATE update/crypto-helpers.hpp update/crypto-helpers-mac.mm update/shared-update.cpp
|
||||
update/shared-update.hpp update/update-helpers.cpp update/update-helpers.hpp)
|
||||
target_link_libraries(obs PRIVATE ${SECURITY} OBS::blake2 nlohmann_json::nlohmann_json)
|
||||
|
||||
target_sources(
|
||||
obs
|
||||
PRIVATE update/crypto-helpers.hpp
|
||||
update/crypto-helpers-mac.mm
|
||||
update/shared-update.cpp
|
||||
update/shared-update.hpp
|
||||
update/update-helpers.cpp
|
||||
update/update-helpers.hpp)
|
||||
|
||||
if(SPARKLE_APPCAST_URL AND SPARKLE_PUBLIC_KEY)
|
||||
find_library(SPARKLE Sparkle)
|
||||
mark_as_advanced(SPARKLE)
|
||||
|
||||
target_sources(obs PRIVATE update/mac-update.cpp update/mac-update.hpp update/sparkle-updater.mm)
|
||||
target_sources(obs PRIVATE update/mac-update.cpp update/mac-update.hpp update/sparkle-updater.mm
|
||||
update/models/branches.hpp)
|
||||
target_compile_definitions(obs PRIVATE ENABLE_SPARKLE_UPDATER)
|
||||
target_link_libraries(obs PRIVATE ${SPARKLE})
|
||||
# Enable Automatic Reference Counting for Sparkle wrapper
|
||||
|
||||
@@ -28,6 +28,7 @@ target_sources(
|
||||
update/update-window.hpp
|
||||
update/win-update.cpp
|
||||
update/win-update.hpp
|
||||
update/models/branches.hpp
|
||||
win-update/updater/manifest.hpp)
|
||||
|
||||
target_link_libraries(obs-studio PRIVATE crypt32 OBS::blake2 OBS::w32-pthreads MbedTLS::MbedTLS
|
||||
|
||||
+18
-15
@@ -65,7 +65,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
|
||||
#include <json11.hpp>
|
||||
#include "update/models/branches.hpp"
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
@@ -1289,28 +1289,31 @@ bool OBSApp::InitTheme()
|
||||
void ParseBranchesJson(const std::string &jsonString, vector<UpdateBranch> &out,
|
||||
std::string &error)
|
||||
{
|
||||
json11::Json root;
|
||||
root = json11::Json::parse(jsonString, error);
|
||||
if (!error.empty() || !root.is_array())
|
||||
return;
|
||||
JsonBranches branches;
|
||||
|
||||
for (const json11::Json &item : root.array_items()) {
|
||||
try {
|
||||
nlohmann::json json = nlohmann::json::parse(jsonString);
|
||||
branches = json.get<JsonBranches>();
|
||||
} catch (nlohmann::json::exception &e) {
|
||||
error = e.what();
|
||||
return;
|
||||
}
|
||||
|
||||
for (const JsonBranch &json_branch : branches) {
|
||||
#ifdef _WIN32
|
||||
if (!item["windows"].bool_value())
|
||||
if (!json_branch.windows)
|
||||
continue;
|
||||
#elif defined(__APPLE__)
|
||||
if (!item["macos"].bool_value())
|
||||
if (!json_branch.macos)
|
||||
continue;
|
||||
#endif
|
||||
|
||||
UpdateBranch branch = {
|
||||
QString::fromStdString(item["name"].string_value()),
|
||||
QString::fromStdString(
|
||||
item["display_name"].string_value()),
|
||||
QString::fromStdString(
|
||||
item["description"].string_value()),
|
||||
item["enabled"].bool_value(),
|
||||
item["visible"].bool_value(),
|
||||
QString::fromStdString(json_branch.name),
|
||||
QString::fromStdString(json_branch.display_name),
|
||||
QString::fromStdString(json_branch.description),
|
||||
json_branch.enabled,
|
||||
json_branch.visible,
|
||||
};
|
||||
out.push_back(branch);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Dennis Sädtler <dennis@obsproject.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
struct JsonBranch {
|
||||
/* Internal name / ID of the branch (used in updater) */
|
||||
std::string name;
|
||||
/* Human readable name */
|
||||
std::string display_name;
|
||||
/* Description */
|
||||
std::string description;
|
||||
/* Whether updating should use the branch if selected or fall back to stable */
|
||||
bool enabled = false;
|
||||
/* Whether the branch should be displayed in the UI */
|
||||
bool visible = false;
|
||||
/* OS compatibility */
|
||||
bool windows = false;
|
||||
bool macos = false;
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(JsonBranch, name,
|
||||
display_name, description,
|
||||
enabled, visible, windows,
|
||||
macos)
|
||||
};
|
||||
|
||||
using JsonBranches = std::vector<JsonBranch>;
|
||||
Reference in New Issue
Block a user