(Create Windows installer #53) ([ui] UI console window should close after launch #51)

This commit is contained in:
2025-07-29 14:11:51 -05:00
parent 7d06fb5617
commit e02eebba99
6 changed files with 87 additions and 41 deletions

View File

@@ -42,6 +42,7 @@ inline const option get_directory_items_option = {"-gdi",
inline const option get_pinned_files_option = {"-gpf", "--get_pinned_files"};
inline const option help_option = {"-h", "--help"};
inline const option hidden_option = {"-hidden", "--hidden"};
inline const option launch_only_option = {"-lo", "--launch_only"};
inline const option open_files_option = {"-of", "--open_files"};
inline const option pin_file_option = {"-pf", "--pin_file"};
inline const option pinned_status_option = {"-ps", "--pinned_status"};
@@ -71,6 +72,7 @@ inline const std::vector<option> option_list = {
get_pinned_files_option,
help_option,
hidden_option,
launch_only_option,
open_files_option,
password_option,
pin_file_option,

View File

@@ -27,7 +27,11 @@
namespace repertory::ui {
class mgmt_app_config final {
public:
mgmt_app_config();
mgmt_app_config(bool hidden, bool launch_only);
private:
std::atomic<bool> hidden_{false};
std::atomic<bool> launch_only_{false};
private:
atomic<std::string> api_password_{"repertory"};
@@ -52,6 +56,10 @@ public:
[[nodiscard]] auto get_api_user() const -> std::string { return api_user_; }
[[nodiscard]] auto get_hidden() const -> bool { return hidden_; }
[[nodiscard]] auto get_launch_only() const -> bool { return launch_only_; }
[[nodiscard]] auto get_mount_location(provider_type prov,
std::string_view name) const
-> std::string;
@@ -62,6 +70,10 @@ public:
void set_api_user(std::string_view api_user);
void set_hidden(bool hidden);
void set_launch_only(bool launch_only);
void set_mount_location(provider_type prov, std::string_view name,
std::string_view location);
};

View File

@@ -55,7 +55,10 @@ auto main(int argc, char **argv) -> int {
int ret{0};
if (utils::cli::has_option(args, utils::cli::options::ui_option)) {
ui::mgmt_app_config config{};
ui::mgmt_app_config config{
utils::cli::has_option(args, utils::cli::options::hidden_option),
utils::cli::has_option(args, utils::cli::options::launch_only_option),
};
std::string data;
auto res = utils::cli::parse_string_option(

View File

@@ -113,6 +113,41 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
server_(server) {
REPERTORY_USES_FUNCTION_NAME();
#if defined(_WIN32)
if (config_->get_hidden()) {
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
}
#endif // defined(_WIN32)
if (not config_->get_launch_only()) {
#if defined(_WIN32)
system(
fmt::format(
R"(start "Repertory Management Portal" "http://127.0.0.1:{}/ui")",
config_->get_api_port())
.c_str());
#elif defined(__linux__)
system(fmt::format(R"(xdg-open "http://127.0.0.1:{}/ui")",
config_->get_api_port())
.c_str());
#else // error
build fails here
#endif
}
std::uint16_t port{};
if (not utils::get_next_available_port(config_->get_api_port(), port)) {
fmt::println("failed to detect if port is available|{}",
config_->get_api_port());
return;
}
if (port != config_->get_api_port()) {
fmt::println("failed to listen on port|{}|next available|{}",
config_->get_api_port(), port);
return;
}
server_->set_socket_options([](auto &&sock) {
#if defined(_WIN32)
int enable{1};
@@ -244,32 +279,6 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
#endif // !defined(_WIN32)
std::signal(SIGTERM, quit_handler);
#if defined(_WIN32)
system(fmt::format(
R"(start "Repertory Management Portal" "http://127.0.0.1:{}/ui")",
config_->get_api_port())
.c_str());
#elif defined(__linux__)
system(fmt::format(R"(xdg-open "http://127.0.0.1:{}/ui")",
config_->get_api_port())
.c_str());
#else // error
build fails here
#endif
std::uint16_t port{};
if (not utils::get_next_available_port(config_->get_api_port(), port)) {
fmt::println("failed to detect if port is available|{}",
config_->get_api_port());
return;
}
if (port != config_->get_api_port()) {
fmt::println("failed to listen on port|{}|next available|{}",
config_->get_api_port(), port);
return;
}
event_system::instance().start();
nonce_thread_ =

View File

@@ -72,7 +72,8 @@ namespace {
} // namespace
namespace repertory::ui {
mgmt_app_config::mgmt_app_config() {
mgmt_app_config::mgmt_app_config(bool hidden, bool launch_only)
: hidden_(hidden), launch_only_(launch_only) {
REPERTORY_USES_FUNCTION_NAME();
auto config_file =
@@ -174,6 +175,12 @@ void mgmt_app_config::set_api_user(std::string_view api_user) {
save();
}
void mgmt_app_config::set_hidden(bool hidden) { hidden_ = hidden; }
void mgmt_app_config::set_launch_only(bool launch_only) {
launch_only_ = launch_only;
}
void mgmt_app_config::set_mount_location(provider_type prov,
std::string_view name,
std::string_view location) {