Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
©2018 Valve Corporation. Steam and the Steam logo are trademarks and/or
registered trademarks of Valve Corporation in the U.S. and/or other countries. All
rights reserved.
3 changes: 2 additions & 1 deletion assets/apps_linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"name":"Steam BigPicture",

"output":"steam.txt",
"detached":["setsid steam steam://open/bigpicture"]
"detached":["setsid steam steam://open/bigpicture"],
"image-path":"./assets/steam.png"
}
]
}
3 changes: 2 additions & 1 deletion assets/apps_windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"name":"Steam BigPicture",

"output":"steam.txt",
"detached":["steam steam://open/bigpicture"]
"detached":["steam steam://open/bigpicture"],
"image-path":"./assets/steam.png"
}
]
}
Binary file added assets/steam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 18 additions & 1 deletion assets/web/apps.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ <h1>Applications</h1>
If not set, Sunshine will default to the parent directory of the command
</div>
</div>
<!-- Image path -->
<div class="mb-3">
<label for="appImagePath" class="form-label">Image</label>
<input
type="text"
class="form-control monospace"
id="appImagePath"
aria-describedby="appImagePathHelp"
v-model="editForm['image-path']"
/>
<div id="appImagePathHelp" class="form-text">
Application icon/picture/image path that will be sent to client. Image must be a PNG file.
If not set, Sunshine will send default box image.
</div>
</div>
<!--buttons-->
<div class="d-flex">
<button @click="showEditForm = false" class="btn btn-secondary m-2">
Expand Down Expand Up @@ -208,6 +223,7 @@ <h1>Applications</h1>
index: -1,
"prep-cmd": [],
detached: [],
"image-path": ""
};
this.editForm.index = -1;
this.showEditForm = true;
Expand Down Expand Up @@ -238,6 +254,7 @@ <h1>Applications</h1>
});
},
save() {
this.editForm["image-path"] = this.editForm["image-path"].toString().replace(/"/g, '');
fetch("/api/apps", {
method: "POST",
body: JSON.stringify(this.editForm),
Expand All @@ -257,4 +274,4 @@ <h1>Applications</h1>
.monospace {
font-family: monospace;
}
</style>
</style>
10 changes: 8 additions & 2 deletions sunshine/nvhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,17 @@ void cancel(resp_https_t response, req_https_t request) {
}
}


void appasset(resp_https_t response, req_https_t request) {
print_req<SimpleWeb::HTTPS>(request);

std::ifstream in(SUNSHINE_ASSETS_DIR "/box.png");
response->write(SimpleWeb::StatusCode::success_ok, in);
auto args = request->parse_query_string();
auto app_image = proc::proc.get_app_image(util::from_view(args.at("appid")));

std::ifstream in(app_image, std::ios::binary);
SimpleWeb::CaseInsensitiveMultimap headers;
headers.emplace("Content-Type", "image/png");
response->write(SimpleWeb::StatusCode::success_ok, in, headers);
response->close_connection_after_response = true;
}

Expand Down
34 changes: 34 additions & 0 deletions sunshine/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

#include <string>
#include <vector>
#include <filesystem>

#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>

#include "main.h"
#include "utility.h"
Expand Down Expand Up @@ -189,6 +191,33 @@ std::vector<ctx_t> &proc_t::get_apps() {
return _apps;
}

/// Gets application image from application list.
/// 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 app_image_path = _apps[app_index].image_path;
if (app_image_path.empty()) {
return SUNSHINE_ASSETS_DIR "/box.png";
}

auto image_extension = std::filesystem::path(app_image_path).extension().string();
boost::to_lower(image_extension);

std::error_code code;
if (!std::filesystem::exists(app_image_path, code) || image_extension != ".png") {
return SUNSHINE_ASSETS_DIR "/box.png";
}

// return only "content-type" http header compatible image type.
return app_image_path;
}

proc_t::~proc_t() {
terminate();
}
Expand Down Expand Up @@ -279,6 +308,7 @@ std::optional<proc::proc_t> parse(const std::string &file_name) {
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 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);

std::vector<proc::cmd_t> prep_cmds;
Expand Down Expand Up @@ -321,6 +351,10 @@ std::optional<proc::proc_t> parse(const std::string &file_name) {
ctx.working_dir = parse_env_val(this_env, *working_dir);
}

if (image_path) {
ctx.image_path = parse_env_val(this_env, *image_path);
}

ctx.name = std::move(name);
ctx.prep_cmds = std::move(prep_cmds);
ctx.detached = std::move(detached);
Expand Down
2 changes: 2 additions & 0 deletions sunshine/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct ctx_t {
std::string cmd;
std::string working_dir;
std::string output;
std::string image_path;
};

class proc_t {
Expand All @@ -78,6 +79,7 @@ class proc_t {

const std::vector<ctx_t> &get_apps() const;
std::vector<ctx_t> &get_apps();
std::string get_app_image(int app_id);

void terminate();

Expand Down