refactor ui server
Some checks failed
Blockstorage/repertory/pipeline/head There was a failure building this commit
BlockStorage/repertory/pipeline/head There was a failure building this commit

This commit is contained in:
2025-09-15 13:34:52 -05:00
parent 6b2bf3ab67
commit 290bdb5fda
2 changed files with 20 additions and 9 deletions

View File

@@ -24,12 +24,15 @@
#include "events/consumers/console_consumer.hpp" #include "events/consumers/console_consumer.hpp"
#include "events/consumers/logging_consumer.hpp" #include "events/consumers/logging_consumer.hpp"
#include "events/event_system.hpp"
#include "utils/common.hpp" #include "utils/common.hpp"
namespace repertory::ui { namespace repertory::ui {
class mgmt_app_config; class mgmt_app_config;
class ui_server final { class ui_server final {
E_CONSUMER();
private: private:
static constexpr auto nonce_length{128U}; static constexpr auto nonce_length{128U};
static constexpr auto nonce_timeout{15U}; static constexpr auto nonce_timeout{15U};

View File

@@ -129,6 +129,16 @@ ui_server::ui_server(mgmt_app_config *config)
repertory_binary_(utils::path::combine(".", {REPERTORY})) repertory_binary_(utils::path::combine(".", {REPERTORY}))
#endif // defined(_WIN32) #endif // defined(_WIN32)
{ {
E_SUBSCRIBE(event_level_changed, [this](auto &&event) {
config_->set_event_level(event.new_level);
});
#if defined(_WIN32)
if (config_->get_hidden()) {
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
}
#endif // defined(_WIN32)
#if defined(__APPLE__) #if defined(__APPLE__)
server_.set_mount_point("/ui", "../Resources/web"); server_.set_mount_point("/ui", "../Resources/web");
#else // !defined(__APPLE__) #else // !defined(__APPLE__)
@@ -137,11 +147,11 @@ ui_server::ui_server(mgmt_app_config *config)
server_.set_socket_options([](auto &&sock) { server_.set_socket_options([](auto &&sock) {
#if defined(_WIN32) #if defined(_WIN32)
BOOL enable = TRUE; BOOL enable{TRUE};
::setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, ::setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
reinterpret_cast<const char *>(&enable), sizeof(enable)); reinterpret_cast<const char *>(&enable), sizeof(enable));
#else // !defined(_WIN32)! #else // !defined(_WIN32)!
int one = 1; int one{1};
::setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, ::setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
reinterpret_cast<const char *>(&one), sizeof(one)); reinterpret_cast<const char *>(&one), sizeof(one));
#ifdef SO_REUSEPORT #ifdef SO_REUSEPORT
@@ -262,15 +272,13 @@ ui_server::ui_server(mgmt_app_config *config)
server_.Put("/api/v1/settings", [this](auto &&req, auto &&res) { server_.Put("/api/v1/settings", [this](auto &&req, auto &&res) {
handle_put_settings(req, res); handle_put_settings(req, res);
}); });
#if defined(_WIN32)
if (config_->get_hidden()) {
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
}
#endif // defined(_WIN32)
} }
ui_server::~ui_server() { stop(); } ui_server::~ui_server() {
stop();
E_CONSUMER_RELEASE();
}
auto ui_server::data_directory_exists(provider_type prov, auto ui_server::data_directory_exists(provider_type prov,
std::string_view name) const -> bool { std::string_view name) const -> bool {