Update app id on edit (#670)
Co-authored-by: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com>
This commit is contained in:
parent
12efe96297
commit
052297a1a5
8 changed files with 79 additions and 24 deletions
|
|
@ -84,14 +84,17 @@ int proc_t::execute(int app_id) {
|
|||
// Ensure starting from a clean slate
|
||||
terminate();
|
||||
|
||||
if(app_id < 0 || app_id >= _apps.size()) {
|
||||
BOOST_LOG(error) << "Couldn't find app with ID ["sv << app_id << ']';
|
||||
auto iter = std::find_if(_apps.begin(), _apps.end(), [&app_id](const auto app) {
|
||||
return app.id == std::to_string(app_id);
|
||||
});
|
||||
|
||||
if(iter == _apps.end()) {
|
||||
BOOST_LOG(error) << "Couldn't find app with ID ["sv << app_id << ']';
|
||||
return 404;
|
||||
}
|
||||
|
||||
_app_id = app_id;
|
||||
auto &proc = _apps[app_id];
|
||||
auto &proc = *iter;
|
||||
|
||||
_undo_begin = std::begin(proc.prep_cmds);
|
||||
_undo_it = _undo_begin;
|
||||
|
|
@ -182,7 +185,7 @@ int proc_t::running() {
|
|||
terminate();
|
||||
}
|
||||
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void proc_t::terminate() {
|
||||
|
|
@ -230,16 +233,15 @@ std::vector<ctx_t> &proc_t::get_apps() {
|
|||
// Returns default image if image configuration is not set.
|
||||
// Returns http content-type header compatible image type.
|
||||
std::string proc_t::get_app_image(int app_id) {
|
||||
auto app_index = app_id - 1;
|
||||
if(app_index < 0 || app_index >= _apps.size()) {
|
||||
BOOST_LOG(error) << "Couldn't find app with ID ["sv << app_id << ']';
|
||||
return SUNSHINE_ASSETS_DIR "/box.png";
|
||||
}
|
||||
auto default_image = SUNSHINE_ASSETS_DIR "/box.png";
|
||||
|
||||
auto iter = std::find_if(_apps.begin(), _apps.end(), [&app_id](const auto app) {
|
||||
return app.id == std::to_string(app_id);
|
||||
});
|
||||
auto app_image_path = iter == _apps.end() ? std::string() : iter->image_path;
|
||||
|
||||
auto default_image = SUNSHINE_ASSETS_DIR "/box.png";
|
||||
auto app_image_path = _apps[app_index].image_path;
|
||||
if(app_image_path.empty()) {
|
||||
// image is empty, return default box image
|
||||
BOOST_LOG(warning) << "Couldn't find app image for ID ["sv << app_id << ']';
|
||||
return default_image;
|
||||
}
|
||||
|
||||
|
|
@ -368,6 +370,7 @@ std::optional<proc::proc_t> parse(const std::string &file_name) {
|
|||
this_env[name] = parse_env_val(this_env, val.get_value<std::string>());
|
||||
}
|
||||
|
||||
int app_index = 1; // Start at 1, 0 indicates no app running
|
||||
std::vector<proc::ctx_t> apps;
|
||||
for(auto &[_, app_node] : apps_node) {
|
||||
proc::ctx_t ctx;
|
||||
|
|
@ -379,6 +382,7 @@ std::optional<proc::proc_t> parse(const std::string &file_name) {
|
|||
auto cmd = app_node.get_optional<std::string>("cmd"s);
|
||||
auto image_path = app_node.get_optional<std::string>("image-path"s);
|
||||
auto working_dir = app_node.get_optional<std::string>("working-dir"s);
|
||||
auto id = app_node.get_optional<std::string>("id"s);
|
||||
|
||||
std::vector<proc::cmd_t> prep_cmds;
|
||||
if(prep_nodes_opt) {
|
||||
|
|
@ -424,6 +428,15 @@ std::optional<proc::proc_t> parse(const std::string &file_name) {
|
|||
ctx.image_path = parse_env_val(this_env, *image_path);
|
||||
}
|
||||
|
||||
if(id) {
|
||||
ctx.id = parse_env_val(this_env, *id);
|
||||
}
|
||||
else {
|
||||
ctx.id = std::to_string(app_index);
|
||||
}
|
||||
// Always increment index to avoid order shuffling in moonlight
|
||||
app_index++;
|
||||
|
||||
ctx.name = std::move(name);
|
||||
ctx.prep_cmds = std::move(prep_cmds);
|
||||
ctx.detached = std::move(detached);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue