[ui] Add auto-mount on first launch functionality #52
This commit is contained in:
@@ -477,6 +477,7 @@ inline constexpr auto JSON_API_PARENT{"ApiParent"};
|
||||
inline constexpr auto JSON_API_PASSWORD{"ApiPassword"};
|
||||
inline constexpr auto JSON_API_PATH{"ApiPath"};
|
||||
inline constexpr auto JSON_API_PORT{"ApiPort"};
|
||||
inline constexpr auto JSON_AUTO_START{"AutoStart"};
|
||||
inline constexpr auto JSON_API_USER{"ApiUser"};
|
||||
inline constexpr auto JSON_BUCKET{"Bucket"};
|
||||
inline constexpr auto JSON_CLIENT_POOL_SIZE{"ClientPoolSize"};
|
||||
|
@@ -113,6 +113,9 @@ private:
|
||||
void handle_put_settings(const httplib::Request &req,
|
||||
httplib::Response &res) const;
|
||||
|
||||
void handle_put_setting(const httplib::Request &req,
|
||||
httplib::Response &res) const;
|
||||
|
||||
auto launch_process(provider_type prov, std::string_view name,
|
||||
std::vector<std::string> args,
|
||||
bool background = false) const
|
||||
|
@@ -37,6 +37,7 @@ private:
|
||||
atomic<std::string> api_password_{"repertory"};
|
||||
std::atomic<std::uint16_t> api_port_{default_ui_mgmt_port};
|
||||
atomic<std::string> api_user_{"repertory"};
|
||||
std::atomic<bool> auto_start_{false};
|
||||
std::unordered_map<provider_type,
|
||||
std::unordered_map<std::string, std::string>>
|
||||
locations_;
|
||||
@@ -56,6 +57,8 @@ public:
|
||||
|
||||
[[nodiscard]] auto get_api_user() const -> std::string { return api_user_; }
|
||||
|
||||
[[nodiscard]] auto get_auto_start() const -> bool { return auto_start_; }
|
||||
|
||||
[[nodiscard]] auto get_hidden() const -> bool { return hidden_; }
|
||||
|
||||
[[nodiscard]] auto get_launch_only() const -> bool { return launch_only_; }
|
||||
@@ -70,6 +73,8 @@ public:
|
||||
|
||||
void set_api_user(std::string_view api_user);
|
||||
|
||||
void set_auto_start(bool auto_start);
|
||||
|
||||
void set_hidden(bool hidden);
|
||||
|
||||
void set_launch_only(bool launch_only);
|
||||
|
@@ -261,6 +261,9 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
||||
handle_put_set_value_by_name(req, res);
|
||||
});
|
||||
|
||||
server->Put("/api/v1/setting",
|
||||
[this](auto &&req, auto &&res) { handle_put_setting(req, res); });
|
||||
|
||||
server->Put("/api/v1/settings", [this](auto &&req, auto &&res) {
|
||||
handle_put_settings(req, res);
|
||||
});
|
||||
@@ -649,6 +652,18 @@ void handlers::handle_put_set_value_by_name(const httplib::Request &req,
|
||||
res.status = http_error_codes::ok;
|
||||
}
|
||||
|
||||
void handlers::handle_put_setting(const httplib::Request &req,
|
||||
httplib::Response &res) const {
|
||||
auto name = req.get_param_value("name");
|
||||
auto value = req.get_param_value("value");
|
||||
|
||||
if (name == JSON_AUTO_START) {
|
||||
config_->set_auto_start(utils::string::to_bool(value));
|
||||
}
|
||||
|
||||
res.status = http_error_codes::ok;
|
||||
}
|
||||
|
||||
void handlers::handle_put_settings(const httplib::Request &req,
|
||||
httplib::Response &res) const {
|
||||
auto data = nlohmann::json::parse(req.get_param_value("data"));
|
||||
|
@@ -94,7 +94,15 @@ mgmt_app_config::mgmt_app_config(bool hidden, bool launch_only)
|
||||
api_password_ = data.at(JSON_API_PASSWORD).get<std::string>();
|
||||
api_port_ = data.at(JSON_API_PORT).get<std::uint16_t>();
|
||||
api_user_ = data.at(JSON_API_USER).get<std::string>();
|
||||
auto_start_ = data.contains(JSON_AUTO_START)
|
||||
? data.at(JSON_AUTO_START).get<bool>()
|
||||
: false;
|
||||
locations_ = from_json(data.at(JSON_MOUNT_LOCATIONS));
|
||||
|
||||
if (not data.contains(JSON_AUTO_START)) {
|
||||
save();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -198,8 +206,18 @@ void mgmt_app_config::set_mount_location(provider_type prov,
|
||||
save();
|
||||
}
|
||||
|
||||
void mgmt_app_config::set_auto_start(bool auto_start) {
|
||||
if (auto_start_ == auto_start) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto_start_ = auto_start;
|
||||
save();
|
||||
}
|
||||
|
||||
auto mgmt_app_config::to_json() const -> nlohmann::json {
|
||||
nlohmann::json data;
|
||||
data[JSON_AUTO_START] = auto_start_;
|
||||
data[JSON_API_PASSWORD] = api_password_;
|
||||
data[JSON_API_PORT] = api_port_;
|
||||
data[JSON_API_USER] = api_user_;
|
||||
|
Reference in New Issue
Block a user