applist image attribute
This commit is contained in:
@@ -7,7 +7,8 @@
|
|||||||
"name":"Steam BigPicture",
|
"name":"Steam BigPicture",
|
||||||
|
|
||||||
"output":"steam.txt",
|
"output":"steam.txt",
|
||||||
"detached":["steam steam://open/bigpicture"]
|
"detached":["steam steam://open/bigpicture"],
|
||||||
|
"image":"steam.png"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
+29
-2
@@ -761,12 +761,39 @@ void cancel(resp_https_t response, req_https_t request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CHECK_EXPECTED_EXTENTIONS(extention) (extention == "png" || extention == "jpg" || extention == "jpeg")
|
||||||
|
|
||||||
void appasset(resp_https_t response, req_https_t request) {
|
void appasset(resp_https_t response, req_https_t request) {
|
||||||
print_req<SimpleWeb::HTTPS>(request);
|
print_req<SimpleWeb::HTTPS>(request);
|
||||||
|
|
||||||
std::ifstream in(SUNSHINE_ASSETS_DIR "/box.png");
|
auto args = request->parse_query_string();
|
||||||
response->write(SimpleWeb::StatusCode::success_ok, in);
|
auto appid = util::from_view(args.at("appid")) - 1;
|
||||||
|
auto app_image = proc::proc.get_app_image(appid);
|
||||||
|
|
||||||
|
BOOST_LOG(debug) << "/appasset: ["sv << app_image << "] -- image"sv;
|
||||||
|
|
||||||
|
if (app_image.empty()) {
|
||||||
|
app_image = "steam.png";
|
||||||
|
}
|
||||||
|
auto file_path = SUNSHINE_ASSETS_DIR "/" + app_image;
|
||||||
|
|
||||||
|
BOOST_LOG(debug) << "/appasset: ["sv << file_path << "] -- image path"sv;
|
||||||
|
// check if files exists
|
||||||
|
std::error_code code;
|
||||||
|
auto image_extention = std::filesystem::path(file_path).extension().string();
|
||||||
|
image_extention = image_extention.substr(1, image_extention.length() - 1);
|
||||||
|
if (!std::filesystem::exists(file_path, code) || !CHECK_EXPECTED_EXTENTIONS(image_extention)) {
|
||||||
|
BOOST_LOG(debug) << "/appasset: ["sv << file_path << "] [extention="sv << image_extention << "] -- file not found"sv;
|
||||||
|
response->write(SimpleWeb::StatusCode::client_error_not_found);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleWeb::CaseInsensitiveMultimap header;
|
||||||
|
header.emplace("Content-Type", "image/" + image_extention);
|
||||||
|
std::ifstream in(file_path);
|
||||||
|
response->write(SimpleWeb::StatusCode::success_ok, in, header);
|
||||||
response->close_connection_after_response = true;
|
response->close_connection_after_response = true;
|
||||||
|
BOOST_LOG(debug) << "/appasset: ["sv << file_path << "] [extention="sv << image_extention << "] -- sent"sv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start() {
|
void start() {
|
||||||
|
|||||||
@@ -189,6 +189,14 @@ std::vector<ctx_t> &proc_t::get_apps() {
|
|||||||
return _apps;
|
return _apps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string proc_t::get_app_image(int app_id) {
|
||||||
|
if(app_id < 0 || app_id >= _apps.size()) {
|
||||||
|
BOOST_LOG(error) << "Couldn't find app with ID ["sv << app_id << ']';
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return _apps[app_id].image;
|
||||||
|
}
|
||||||
|
|
||||||
proc_t::~proc_t() {
|
proc_t::~proc_t() {
|
||||||
terminate();
|
terminate();
|
||||||
}
|
}
|
||||||
@@ -279,6 +287,7 @@ std::optional<proc::proc_t> parse(const std::string &file_name) {
|
|||||||
auto output = app_node.get_optional<std::string>("output"s);
|
auto output = app_node.get_optional<std::string>("output"s);
|
||||||
auto name = parse_env_val(this_env, app_node.get<std::string>("name"s));
|
auto name = parse_env_val(this_env, app_node.get<std::string>("name"s));
|
||||||
auto cmd = app_node.get_optional<std::string>("cmd"s);
|
auto cmd = app_node.get_optional<std::string>("cmd"s);
|
||||||
|
auto image = app_node.get_optional<std::string>("image"s);
|
||||||
auto working_dir = app_node.get_optional<std::string>("working-dir"s);
|
auto working_dir = app_node.get_optional<std::string>("working-dir"s);
|
||||||
|
|
||||||
std::vector<proc::cmd_t> prep_cmds;
|
std::vector<proc::cmd_t> prep_cmds;
|
||||||
@@ -321,6 +330,10 @@ std::optional<proc::proc_t> parse(const std::string &file_name) {
|
|||||||
ctx.working_dir = parse_env_val(this_env, *working_dir);
|
ctx.working_dir = parse_env_val(this_env, *working_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (image) {
|
||||||
|
ctx.image = parse_env_val(this_env, *image);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.name = std::move(name);
|
ctx.name = std::move(name);
|
||||||
ctx.prep_cmds = std::move(prep_cmds);
|
ctx.prep_cmds = std::move(prep_cmds);
|
||||||
ctx.detached = std::move(detached);
|
ctx.detached = std::move(detached);
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ struct ctx_t {
|
|||||||
std::string cmd;
|
std::string cmd;
|
||||||
std::string working_dir;
|
std::string working_dir;
|
||||||
std::string output;
|
std::string output;
|
||||||
|
std::string image;
|
||||||
};
|
};
|
||||||
|
|
||||||
class proc_t {
|
class proc_t {
|
||||||
@@ -78,6 +79,7 @@ public:
|
|||||||
|
|
||||||
const std::vector<ctx_t> &get_apps() const;
|
const std::vector<ctx_t> &get_apps() const;
|
||||||
std::vector<ctx_t> &get_apps();
|
std::vector<ctx_t> &get_apps();
|
||||||
|
std::string get_app_image(int app_id);
|
||||||
|
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user