Avoid loading app icons in the dashboard, add error handling when loading steam icon

This commit is contained in:
Guillaume Meunier
2025-08-04 09:13:51 +02:00
committed by Patrick Nicolas
parent fddfb8eb57
commit 06240858fd
3 changed files with 30 additions and 22 deletions
+28 -20
View File
@@ -116,7 +116,7 @@ std::vector<std::byte> load_steam_icon(const std::filesystem::path & root, int a
return {}; return {};
} }
void read_steam_vr_apps(std::unordered_map<std::string, application> & res) void read_steam_vr_apps(std::unordered_map<std::string, application> & res, bool load_icons)
{ {
auto [command, root] = find_steam(); auto [command, root] = find_steam();
if (not root) if (not root)
@@ -166,17 +166,20 @@ void read_steam_vr_apps(std::unordered_map<std::string, application> & res)
} }
} }
try if (load_icons)
{ {
const char prefix[] = "steam.app."; try
if (app_key.starts_with(prefix)) {
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 (...)
{ {
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()) if (not app.exec.empty())
@@ -278,7 +281,7 @@ bool contains(std::string_view entries, std::string_view val, char sep = ';')
return false; return false;
} }
std::optional<application> do_desktop_entry(const std::filesystem::path & filename) std::optional<application> do_desktop_entry(const std::filesystem::path & filename, bool load_icons)
{ {
auto data = read_file(filename); auto data = read_file(filename);
std::optional<application> res; std::optional<application> res;
@@ -320,10 +323,15 @@ std::optional<application> do_desktop_entry(const std::filesystem::path & filena
res->exec = unescape(item.value); res->exec = unescape(item.value);
if (item.key == "Path") if (item.key == "Path")
res->path = unescape(item.value); res->path = unescape(item.value);
if (item.key == "Icon") if (item.key == "Icon" and load_icons)
{ {
if (auto filename = xdg_icon_lookup(std::string{item.value}, 256)) try
res->image = load_icon(*filename, 256); {
if (auto filename = xdg_icon_lookup(std::string{item.value}, 256))
res->image = load_icon(*filename, 256);
}
catch (...)
{}
} }
} }
@@ -333,7 +341,7 @@ std::optional<application> do_desktop_entry(const std::filesystem::path & filena
return res; return res;
} }
void do_data_dir(std::filesystem::path dir, std::unordered_map<std::string, application> & res) void do_data_dir(std::filesystem::path dir, std::unordered_map<std::string, application> & res, bool load_icons)
{ {
dir = dir / "applications"; dir = dir / "applications";
if (not std::filesystem::is_directory(dir)) if (not std::filesystem::is_directory(dir))
@@ -356,29 +364,29 @@ void do_data_dir(std::filesystem::path dir, std::unordered_map<std::string, appl
if (res.contains(file_id)) if (res.contains(file_id))
continue; continue;
auto app = do_desktop_entry(entry.path()); auto app = do_desktop_entry(entry.path(), load_icons);
if (app) if (app)
res.emplace(std::move(file_id), std::move(*app)); res.emplace(std::move(file_id), std::move(*app));
} }
} }
} // namespace } // namespace
std::unordered_map<std::string, application> list_applications(bool include_steam) std::unordered_map<std::string, application> list_applications(bool include_steam, bool load_icons)
{ {
std::unordered_map<std::string, application> res; std::unordered_map<std::string, application> res;
if (include_steam) if (include_steam)
read_steam_vr_apps(res); read_steam_vr_apps(res, load_icons);
do_data_dir(xdg_data_home(), res); do_data_dir(xdg_data_home(), res, load_icons);
for (auto && dir: xdg_data_dirs()) for (auto && dir: xdg_data_dirs())
do_data_dir(std::move(dir), res); do_data_dir(std::move(dir), res, load_icons);
if (wivrn::is_flatpak()) if (wivrn::is_flatpak())
{ {
// Try to guess host data dirs // Try to guess host data dirs
do_data_dir("/run/host/usr/share", res); do_data_dir("/run/host/usr/share", res, load_icons);
} }
return res; return res;
+1 -1
View File
@@ -35,5 +35,5 @@ struct application
std::optional<std::string> path; std::optional<std::string> path;
}; };
std::unordered_map<std::string, application> list_applications(bool include_steam = true); std::unordered_map<std::string, application> list_applications(bool include_steam = true, bool load_icons = true);
} // namespace wivrn } // namespace wivrn
+1 -1
View File
@@ -25,7 +25,7 @@
Apps::Apps(QObject * parent) Apps::Apps(QObject * parent)
{ {
auto apps = wivrn::list_applications(); auto apps = wivrn::list_applications(true /* Include steam apps */, false /* Don't load icons */);
for (const auto & [id, app]: apps) for (const auto & [id, app]: apps)
{ {