Send application icons to the headset

This commit is contained in:
Guillaume Meunier
2025-08-03 10:50:22 +02:00
parent 5435513da2
commit 5e93c87403
12 changed files with 1022 additions and 14 deletions
+86 -12
View File
@@ -20,7 +20,10 @@
#include "application.h"
#include "utils/flatpak.h"
#include "utils/load_icon.h"
#include "utils/steam_app_info.h"
#include "utils/xdg_base_directory.h"
#include "utils/xdg_icon_lookup.h"
#include <filesystem>
#include <fstream>
@@ -32,7 +35,6 @@ namespace wivrn
namespace
{
std::string read_file(const std::filesystem::path & path)
{
std::ifstream f(path);
@@ -47,30 +49,82 @@ std::filesystem::path home()
return home ? home : "";
}
std::pair<std::string, std::string> read_vr_manifest()
std::pair<std::string, std::optional<std::filesystem::path>> find_steam()
{
// system Steam
auto manifest = read_file(xdg_data_home() / "Steam/config/steamapps.vrmanifest");
if (not manifest.empty())
return {"steam", manifest};
if (std::filesystem::exists(xdg_data_home() / "Steam"))
return {"steam", xdg_data_home() / "Steam"};
auto h = home();
// system Steam (accessed from flatpak)
manifest = read_file(h / ".local/share/Steam/config/steamapps.vrmanifest");
if (not manifest.empty())
return {"steam", manifest};
if (std::filesystem::exists(h / ".local/share/Steam"))
return {"steam", h / ".local/share/Steam"};
// Flatpak Steam
manifest = read_file(h / ".var/app/com.valvesoftware.Steam/.steam/steam/config/steamapps.vrmanifest");
if (not manifest.empty())
return {"flatpak run com.valvesoftware.Steam", manifest};
if (std::filesystem::exists(h / ".var/app/com.valvesoftware.Steam/.steam/steam"))
return {"flatpak run com.valvesoftware.Steam", h / ".var/app/com.valvesoftware.Steam/.steam/steam"};
return {};
}
std::string read_vr_manifest(const std::filesystem::path & root)
{
return read_file(root / "config/steamapps.vrmanifest");
}
steam_app_info read_steam_app_info(const std::filesystem::path & root)
{
try
{
return steam_app_info{root / "appcache/appinfo.vdf"};
}
catch (...)
{}
return {};
}
std::vector<std::byte> load_steam_icon(const std::filesystem::path & root, int app_id, const steam_app_info & info)
{
const auto & app_info = info.get(app_id);
try
{
std::string icon{std::get<std::string_view>(app_info.at("common.clienticon"))};
auto image = load_icon(root / "steam/games" / (icon + ".ico"), 128);
if (not image.empty())
return image;
}
catch (...)
{
}
try
{
std::string icon{std::get<std::string_view>(app_info.at("common.LinuxClientIcon"))};
auto image = load_icon(root / "steam/games" / (icon + ".zip"), 128);
if (not image.empty())
return image;
}
catch (...)
{
}
return {};
}
void read_steam_vr_apps(std::unordered_map<std::string, application> & res)
{
auto [command, manifest] = read_vr_manifest();
auto [command, root] = find_steam();
if (not root)
return;
auto manifest = read_vr_manifest(*root);
auto info = read_steam_app_info(*root);
if (manifest.empty())
return;
nlohmann::json json = nlohmann::json::parse(manifest);
@@ -112,6 +166,19 @@ void read_steam_vr_apps(std::unordered_map<std::string, application> & res)
}
}
try
{
const char prefix[] = "steam.app.";
if (app_key.starts_with(prefix))
{
uint32_t app_id = stoll(app_key.substr(strlen(prefix)));
app.image = load_steam_icon(*root, app_id, info);
}
}
catch (...)
{
}
if (not app.exec.empty())
res[app_key] = std::move(app);
}
@@ -253,6 +320,11 @@ std::optional<application> do_desktop_entry(const std::filesystem::path & filena
res->exec = unescape(item.value);
if (item.key == "Path")
res->path = unescape(item.value);
if (item.key == "Icon")
{
if (auto filename = xdg_icon_lookup(std::string{item.value}, 256))
res->image = load_icon(*filename, 256);
}
}
if (res->exec.empty() or not res->name.contains(""))
@@ -299,8 +371,10 @@ std::unordered_map<std::string, application> list_applications(bool include_stea
read_steam_vr_apps(res);
do_data_dir(xdg_data_home(), res);
for (auto && dir: xdg_data_dirs())
do_data_dir(std::move(dir), res);
if (wivrn::is_flatpak())
{
// Try to guess host data dirs