mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
Adds check for active simulator before commands
Implements a check to ensure a simulator is active before processing commands. This prevents errors and unexpected behavior when commands are sent without an active simulator. The check is performed at the beginning of the command parsing, and logs an error if no simulator is active, returning an empty JSON object.
This commit is contained in:
@@ -32,12 +32,22 @@ json Simulators::command_parser(json command)
|
||||
{
|
||||
case Command::get_UI_element:
|
||||
SPDLOG_INFO("Command {}: {}", type, (size_t)command.at("id"));
|
||||
if (is_not_active())
|
||||
{
|
||||
SPDLOG_ERROR("Command got called but there is no active simulator");
|
||||
return j;
|
||||
}
|
||||
j["response"]["type"] = type;
|
||||
j["response"]["UI_item"] =
|
||||
invoke_active_simulator()->get_UI_item(command.at("id"))->to_json(command.at("id"));
|
||||
break;
|
||||
case Command::get_UI_elements:
|
||||
SPDLOG_INFO("Command {}", type);
|
||||
if (is_not_active())
|
||||
{
|
||||
SPDLOG_ERROR("Command got called but there is no active simulator");
|
||||
return j;
|
||||
}
|
||||
j["response"]["type"] = type;
|
||||
j["response"]["UI_items"] = invoke_active_simulator()->get_UI_items()["UI_items"];
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user