Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -31,6 +31,7 @@ option(WIVRN_BUILD_SERVER_LIBRARY "Build OpenXR library for WiVRn server" ${WIVR
|
||||
option(WIVRN_BUILD_DASHBOARD "Build WiVRn dashboard" OFF)
|
||||
option(WIVRN_BUILD_WIVRNCTL "Build wivrnctl" ON)
|
||||
option(WIVRN_BUILD_DISSECTOR "Build Wireshark dissector" OFF)
|
||||
option(WIVRN_BUILD_TEST "Build test binaries" OFF)
|
||||
option(WIVRN_WERROR "Treat warnings as errors" OFF)
|
||||
|
||||
option(WIVRN_USE_NVENC "Enable nvenc (Nvidia) hardware encoder" ON)
|
||||
|
||||
+19
-6
@@ -23,19 +23,17 @@ endif()
|
||||
|
||||
configure_file(wivrn_config.h.in wivrn_config.h)
|
||||
|
||||
add_library(wivrn-common-base STATIC
|
||||
utils/xdg_base_directory.cpp
|
||||
utils/flatpak.cpp
|
||||
add_library(wivrn-common-base STATIC EXCLUDE_FROM_ALL
|
||||
utils/strings.cpp
|
||||
utils/xdg_base_directory.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
|
||||
)
|
||||
|
||||
add_library(wivrn-common STATIC
|
||||
add_library(wivrn-common STATIC EXCLUDE_FROM_ALL
|
||||
crypto.cpp
|
||||
smp.cpp
|
||||
secrets.cpp
|
||||
wivrn_sockets.cpp
|
||||
utils/xdg_base_directory.cpp
|
||||
utils/strings.cpp
|
||||
vk/allocation.cpp
|
||||
vk/error_category.cpp
|
||||
@@ -43,6 +41,22 @@ add_library(wivrn-common STATIC
|
||||
vk/vk_mem_alloc.cpp
|
||||
)
|
||||
|
||||
if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER)
|
||||
add_library(wivrn-common-server STATIC EXCLUDE_FROM_ALL
|
||||
utils/flatpak.cpp
|
||||
application.cpp
|
||||
)
|
||||
target_link_libraries(wivrn-common-server PRIVATE nlohmann_json::nlohmann_json PUBLIC wivrn-common-base)
|
||||
|
||||
if (WIVRN_BUILD_TEST)
|
||||
add_executable(list-apps
|
||||
test_application.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(list-apps wivrn-common-server)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
# The Vulkan headers in Android do not include the C++ headers, download them
|
||||
# Minimum version is 1.3.256
|
||||
@@ -113,5 +127,4 @@ endif()
|
||||
|
||||
target_include_directories(wivrn-common-base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(wivrn-common PUBLIC Boost::pfr OpenSSL::Crypto wivrn-external wivrn-common-base)
|
||||
target_compile_features(wivrn-common PRIVATE cxx_std_20)
|
||||
target_compile_definitions(wivrn-common PUBLIC VULKAN_HPP_NO_STRUCT_CONSTRUCTORS)
|
||||
|
||||
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "application.h"
|
||||
|
||||
#include "utils/flatpak.h"
|
||||
#include "utils/xdg_base_directory.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
std::string read_file(const std::filesystem::path & path)
|
||||
{
|
||||
std::ifstream f(path);
|
||||
std::istreambuf_iterator<char> begin{f}, end;
|
||||
|
||||
return {begin, end};
|
||||
}
|
||||
|
||||
std::filesystem::path home()
|
||||
{
|
||||
auto home = std::getenv("HOME");
|
||||
return home ? home : "";
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> read_vr_manifest()
|
||||
{
|
||||
// system Steam
|
||||
auto manifest = read_file(xdg_data_home() / "Steam/config/steamapps.vrmanifest");
|
||||
if (not manifest.empty())
|
||||
return {"steam", manifest};
|
||||
|
||||
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};
|
||||
|
||||
// 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};
|
||||
return {};
|
||||
}
|
||||
|
||||
void read_steam_vr_apps(std::unordered_map<std::string, application> & res)
|
||||
{
|
||||
auto [command, manifest] = read_vr_manifest();
|
||||
if (manifest.empty())
|
||||
return;
|
||||
nlohmann::json json = nlohmann::json::parse(manifest);
|
||||
|
||||
for (auto & i: json["applications"])
|
||||
{
|
||||
try
|
||||
{
|
||||
application app;
|
||||
|
||||
std::string app_key = i["app_key"];
|
||||
for (auto [locale, items]: i["strings"].items())
|
||||
{
|
||||
if (auto it = items.find("name"); it != items.end())
|
||||
app.name[locale] = *it;
|
||||
}
|
||||
|
||||
if (not app.name.contains(""))
|
||||
{
|
||||
auto it = app.name.find("en_us");
|
||||
if (it == app.name.end())
|
||||
it = app.name.begin();
|
||||
if (it != app.name.end())
|
||||
app.name[""] = it->second;
|
||||
}
|
||||
|
||||
if (i["launch_type"] == "url")
|
||||
{
|
||||
app.exec = command + " " + (std::string)i["url"];
|
||||
}
|
||||
else if (i["launch_type"] == "binary")
|
||||
{
|
||||
const char prefix[] = "steam.app.";
|
||||
if (app_key.starts_with(prefix))
|
||||
{
|
||||
// ¯\_(ツ)_/¯
|
||||
uint64_t appkey = stoll(app_key.substr(strlen(prefix)));
|
||||
app.exec = command + " steam://rungameid/" + std::to_string((appkey << 32) + 0x2000000);
|
||||
}
|
||||
}
|
||||
|
||||
if (not app.exec.empty())
|
||||
res[app_key] = std::move(app);
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
std::cerr << "Failed to parse Steam VR manifest: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string unescape(std::string_view in)
|
||||
{
|
||||
std::string out;
|
||||
out.reserve(in.size());
|
||||
for (auto c = in.begin(); c != in.end(); ++c)
|
||||
{
|
||||
if (*c == '\\')
|
||||
{
|
||||
++c;
|
||||
if (c == in.end())
|
||||
break;
|
||||
switch (*c)
|
||||
{
|
||||
case 's':
|
||||
out += ' ';
|
||||
break;
|
||||
case 'n':
|
||||
out += '\n';
|
||||
break;
|
||||
case 't':
|
||||
out += '\t';
|
||||
break;
|
||||
case 'r':
|
||||
out += '\r';
|
||||
break;
|
||||
default:
|
||||
out += *c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
out += *c;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
struct key_value
|
||||
{
|
||||
std::string_view key;
|
||||
std::string_view locale;
|
||||
std::string_view value;
|
||||
key_value(std::string_view l)
|
||||
{
|
||||
auto pos = l.find_first_of("[ =");
|
||||
if (pos == std::string_view::npos)
|
||||
return;
|
||||
key = l.substr(0, pos);
|
||||
l = l.substr(pos);
|
||||
if (l[0] == '[')
|
||||
{
|
||||
pos = l.find(']');
|
||||
if (pos == std::string_view::npos)
|
||||
{
|
||||
key = std::string_view();
|
||||
return;
|
||||
}
|
||||
locale = l.substr(1, pos - 1);
|
||||
l = l.substr(pos + 1);
|
||||
}
|
||||
pos = l.find('=');
|
||||
if (pos == std::string_view::npos)
|
||||
{
|
||||
key = std::string_view();
|
||||
locale = std::string_view();
|
||||
return;
|
||||
}
|
||||
l = l.substr(pos + 1);
|
||||
pos = l.find_first_not_of(" ");
|
||||
if (pos == std::string_view::npos)
|
||||
{
|
||||
key = std::string_view();
|
||||
locale = std::string_view();
|
||||
return;
|
||||
}
|
||||
value = l.substr(pos);
|
||||
}
|
||||
};
|
||||
|
||||
bool contains(std::string_view entries, std::string_view val, char sep = ';')
|
||||
{
|
||||
for (auto bounds: entries | std::views::split(sep))
|
||||
{
|
||||
if (std::string_view(bounds.begin(), bounds.end()) == val)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<application> do_desktop_entry(const std::filesystem::path & filename)
|
||||
{
|
||||
auto data = read_file(filename);
|
||||
std::optional<application> res;
|
||||
|
||||
// Most apps are not VR, don't bother parsing the rest
|
||||
bool vr = false;
|
||||
for (auto bounds: data | std::views::split('\n'))
|
||||
{
|
||||
std::string_view line(bounds.begin(), bounds.end());
|
||||
key_value item(line);
|
||||
if (item.key == "Categories")
|
||||
vr = contains(item.value, "X-WiVRn-VR");
|
||||
}
|
||||
if (not vr)
|
||||
return res;
|
||||
|
||||
res.emplace();
|
||||
for (auto bounds: data | std::views::split('\n'))
|
||||
{
|
||||
std::string_view line(bounds.begin(), bounds.end());
|
||||
if (line.empty())
|
||||
continue;
|
||||
if (line.starts_with("#"))
|
||||
continue;
|
||||
|
||||
// Only process the main section
|
||||
if (line.starts_with("[") and line != "[Desktop Entry]")
|
||||
break;
|
||||
|
||||
key_value item(line);
|
||||
if (item.key == "Type" and item.value != "Application")
|
||||
{
|
||||
res.reset();
|
||||
return res;
|
||||
}
|
||||
if (item.key == "Name")
|
||||
res->name.emplace(item.locale, unescape(item.value));
|
||||
if (item.key == "Exec")
|
||||
res->exec = unescape(item.value);
|
||||
if (item.key == "Path")
|
||||
res->path = unescape(item.value);
|
||||
}
|
||||
|
||||
if (res->exec.empty() or not res->name.contains(""))
|
||||
res.reset();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void do_data_dir(std::filesystem::path dir, std::unordered_map<std::string, application> & res)
|
||||
{
|
||||
dir = dir / "applications";
|
||||
if (not std::filesystem::is_directory(dir))
|
||||
return;
|
||||
for (const auto & entry: std::filesystem::recursive_directory_iterator(dir))
|
||||
{
|
||||
if (entry.is_directory())
|
||||
continue;
|
||||
|
||||
if (entry.path().extension() != ".desktop")
|
||||
continue;
|
||||
|
||||
// https://specifications.freedesktop.org/desktop-entry-spec/latest/file-naming.html#desktop-file-id
|
||||
auto file_id = entry.path()
|
||||
.lexically_relative(dir)
|
||||
.replace_extension("")
|
||||
.string();
|
||||
std::ranges::replace(file_id, '/', '-');
|
||||
|
||||
if (res.contains(file_id))
|
||||
continue;
|
||||
|
||||
auto app = do_desktop_entry(entry.path());
|
||||
if (app)
|
||||
res.emplace(std::move(file_id), std::move(*app));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::unordered_map<std::string, application> list_applications(bool include_steam)
|
||||
{
|
||||
std::unordered_map<std::string, application> res;
|
||||
|
||||
if (include_steam)
|
||||
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
|
||||
do_data_dir("/run/host/usr/share", res);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace wivrn
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
struct application
|
||||
{
|
||||
// localised names, with empty locale for default
|
||||
std::unordered_map<std::string, std::string> name;
|
||||
std::string exec;
|
||||
std::optional<std::string> path;
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, application> list_applications(bool include_steam = true);
|
||||
} // namespace wivrn
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "application.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
auto apps = wivrn::list_applications();
|
||||
|
||||
std::cout << "Parsed " << apps.size() << " applications" << std::endl;
|
||||
for (const auto & [k, app]: apps)
|
||||
{
|
||||
std::cout << "======================" << std::endl;
|
||||
std::cout << k << std::endl;
|
||||
for (const auto & [locale, name]: app.name)
|
||||
{
|
||||
std::cout << "Name";
|
||||
if (not locale.empty())
|
||||
std::cout << "[" << locale << "]";
|
||||
std::cout << "=" << name << std::endl;
|
||||
}
|
||||
std::cout << "Exec=" << app.exec << std::endl;
|
||||
if (app.path)
|
||||
std::cout << "Path=" << *app.path << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,11 @@
|
||||
#include <fstream>
|
||||
|
||||
static const std::filesystem::path info_path = "/.flatpak-info";
|
||||
static const bool is_flatpak_v = std::filesystem::exists(info_path);
|
||||
|
||||
bool wivrn::is_flatpak()
|
||||
{
|
||||
return std::filesystem::exists(info_path);
|
||||
return is_flatpak_v;
|
||||
}
|
||||
|
||||
std::optional<std::string> wivrn::flatpak_key(std::string section, std::string key)
|
||||
|
||||
@@ -19,13 +19,6 @@
|
||||
|
||||
#include "strings.h"
|
||||
|
||||
std::string utils::trim(std::string input)
|
||||
{
|
||||
input.resize(input.find_last_not_of("\n ") + 1);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
std::vector<std::string> utils::split(const std::string & s, const std::string & sep)
|
||||
{
|
||||
std::string::size_type i = 0;
|
||||
|
||||
@@ -19,32 +19,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
std::string trim(std::string input);
|
||||
|
||||
template <typename T>
|
||||
std::string join(const std::vector<T> & vec, const std::string & sep = ", ")
|
||||
{
|
||||
std::stringstream s;
|
||||
|
||||
if (!vec.empty())
|
||||
{
|
||||
s << vec[0];
|
||||
|
||||
for (size_t i = 1, n = vec.size(); i < n; i++)
|
||||
{
|
||||
s << sep << vec[i];
|
||||
}
|
||||
}
|
||||
|
||||
return s.str();
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string & s, const std::string & sep = "\n");
|
||||
|
||||
} // namespace utils
|
||||
|
||||
@@ -10,7 +10,7 @@ add_executable(wivrn-dashboard
|
||||
main.cpp
|
||||
wivrn_server.cpp
|
||||
wivrn_qdbus_types.cpp
|
||||
steam_apps.cpp
|
||||
apps.cpp
|
||||
escape_string.cpp
|
||||
settings.cpp
|
||||
rectangle_partitionner.cpp
|
||||
@@ -68,6 +68,7 @@ target_link_libraries(wivrn-dashboard
|
||||
QCoro::Network
|
||||
QCoro::Qml
|
||||
wivrn-common-base
|
||||
wivrn-common-server
|
||||
wivrn-external
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "apps.h"
|
||||
|
||||
#include "application.h"
|
||||
|
||||
#include <ranges>
|
||||
|
||||
Apps::Apps(QObject * parent)
|
||||
{
|
||||
auto apps = wivrn::list_applications();
|
||||
|
||||
for (const auto & [id, app]: apps)
|
||||
{
|
||||
m_apps.push_back(
|
||||
vrApp(
|
||||
QString::fromStdString(app.name.at("")),
|
||||
QString::fromStdString(app.exec)));
|
||||
}
|
||||
|
||||
std::ranges::sort(m_apps, [](const vrApp & a, const vrApp & b) {
|
||||
return a.name() < b.name();
|
||||
});
|
||||
}
|
||||
|
||||
#include "moc_apps.cpp"
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -21,37 +22,30 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <qqmlintegration.h>
|
||||
|
||||
class steamApp
|
||||
class vrApp
|
||||
{
|
||||
Q_GADGET
|
||||
QML_VALUE_TYPE(steamApp)
|
||||
QML_VALUE_TYPE(vrApp)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath)
|
||||
Q_PROPERTY(QString command READ command WRITE setCommand)
|
||||
|
||||
QString m_name;
|
||||
QString m_imagePath;
|
||||
QString m_command;
|
||||
|
||||
public:
|
||||
steamApp() = default;
|
||||
steamApp(const steamApp &) = default;
|
||||
steamApp(steamApp &&) = default;
|
||||
steamApp & operator=(const steamApp &) = default;
|
||||
steamApp & operator=(steamApp &&) = default;
|
||||
steamApp(QString name, QString imagePath, QString command) :
|
||||
m_name(name), m_imagePath(imagePath), m_command(command) {}
|
||||
vrApp() = default;
|
||||
vrApp(const vrApp &) = default;
|
||||
vrApp(vrApp &&) = default;
|
||||
vrApp & operator=(const vrApp &) = default;
|
||||
vrApp & operator=(vrApp &&) = default;
|
||||
vrApp(QString name, QString command) :
|
||||
m_name(name), m_command(command) {}
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
QString imagePath() const
|
||||
{
|
||||
return m_imagePath;
|
||||
}
|
||||
|
||||
QString command() const
|
||||
{
|
||||
return m_command;
|
||||
@@ -62,11 +56,6 @@ public:
|
||||
m_name = value;
|
||||
}
|
||||
|
||||
void setImagePath(QString value)
|
||||
{
|
||||
m_imagePath = value;
|
||||
}
|
||||
|
||||
void setCommand(QString value)
|
||||
{
|
||||
m_command = value;
|
||||
@@ -77,30 +66,25 @@ public:
|
||||
m_name = QString::fromStdString(value);
|
||||
}
|
||||
|
||||
void setImagePath(const std::string & value)
|
||||
{
|
||||
m_imagePath = QString::fromStdString(value);
|
||||
}
|
||||
|
||||
void setCommand(const std::string & value)
|
||||
{
|
||||
m_command = QString::fromStdString(value);
|
||||
}
|
||||
};
|
||||
|
||||
class SteamApps : public QObject
|
||||
class Apps : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_SINGLETON
|
||||
|
||||
Q_PROPERTY(QList<steamApp> apps READ apps)
|
||||
QList<steamApp> m_apps;
|
||||
Q_PROPERTY(QList<vrApp> apps READ apps)
|
||||
QList<vrApp> m_apps;
|
||||
|
||||
public:
|
||||
SteamApps(QObject * parent = nullptr);
|
||||
Apps(QObject * parent = nullptr);
|
||||
|
||||
const QList<steamApp> & apps() const
|
||||
const QList<vrApp> & apps() const
|
||||
{
|
||||
return m_apps;
|
||||
}
|
||||
@@ -12,24 +12,21 @@ ColumnLayout {
|
||||
Component.onCompleted: {
|
||||
apps.append({
|
||||
"name": i18nc("don't start an application automatically", "None"),
|
||||
"image_path": "",
|
||||
"command": "",
|
||||
"is_custom": false
|
||||
});
|
||||
|
||||
apps.append({
|
||||
"name": i18nc("choose a custom application to start", "Custom"),
|
||||
"image_path": "",
|
||||
"command": "",
|
||||
"is_custom": true
|
||||
});
|
||||
|
||||
var steam_apps = SteamApps.apps;
|
||||
for (var i = 0; i < steam_apps.length; i++) {
|
||||
var vr_apps = Apps.apps;
|
||||
for (var i = 0; i < vr_apps.length; i++) {
|
||||
apps.append({
|
||||
"name": steam_apps[i].name,
|
||||
"image_path": steam_apps[i].imagePath,
|
||||
"command": steam_apps[i].command,
|
||||
"name": vr_apps[i].name,
|
||||
"command": vr_apps[i].command,
|
||||
"is_custom": false
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "steam_apps.h"
|
||||
#include "escape_string.h"
|
||||
#include "utils/flatpak.h"
|
||||
#include <QProcess>
|
||||
#include <QtLogging>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string read_vr_manifest()
|
||||
{
|
||||
const char * home = getenv("HOME");
|
||||
|
||||
std::filesystem::path vrmanifest = std::string{home ? home : ""} + "/.steam/steam/config/steamapps.vrmanifest";
|
||||
|
||||
if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk")
|
||||
{
|
||||
QProcess flatpak_spawn;
|
||||
flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(vrmanifest)});
|
||||
flatpak_spawn.waitForFinished();
|
||||
return flatpak_spawn.readAllStandardOutput().toStdString();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ifstream f(vrmanifest);
|
||||
std::istreambuf_iterator<char> begin{f}, end;
|
||||
|
||||
return {begin, end};
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
SteamApps::SteamApps(QObject * parent)
|
||||
{
|
||||
auto manifest = read_vr_manifest();
|
||||
if (manifest.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json;
|
||||
try
|
||||
{
|
||||
json = nlohmann::json::parse(manifest);
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
qWarning() << "Error parsing VR manifest: " << e.what();
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto & i: json["applications"])
|
||||
{
|
||||
try
|
||||
{
|
||||
steamApp app;
|
||||
|
||||
app.setImagePath(i.value("image_path", ""));
|
||||
app.setName(i["strings"]["en_us"]["name"]);
|
||||
|
||||
if (i["launch_type"] == "url")
|
||||
{
|
||||
app.setCommand("steam " + (std::string)i["url"]);
|
||||
}
|
||||
else if (i["launch_type"] == "binary")
|
||||
{
|
||||
std::string app_key = i["app_key"];
|
||||
|
||||
const char prefix[] = "steam.app.";
|
||||
if (app_key.starts_with(prefix))
|
||||
{
|
||||
// ¯\_(ツ)_/¯
|
||||
uint64_t appkey = stoll(app_key.substr(strlen(prefix)));
|
||||
app.setCommand("steam steam://rungameid/" + std::to_string((appkey << 32) + 0x2000000));
|
||||
}
|
||||
}
|
||||
|
||||
if (app.command() != "")
|
||||
m_apps.push_back(app);
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
qWarning() << "Error adding app from VR manifest: " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
std::ranges::sort(m_apps, [](const steamApp & a, const steamApp & b) {
|
||||
return a.name() < b.name();
|
||||
});
|
||||
}
|
||||
|
||||
#include "moc_steam_apps.cpp"
|
||||
@@ -23,6 +23,11 @@ finish-args:
|
||||
- --system-talk-name=org.freedesktop.Avahi
|
||||
# Allow getting the pretty hostname
|
||||
- --system-talk-name=org.freedesktop.hostname1
|
||||
# List applications from $XDG_DATA_DIRS
|
||||
- --filesystem=host-os:ro
|
||||
- --filesystem=xdg-data:ro
|
||||
# List flatpak Steam games
|
||||
- --filesystem=~/.var/app/com.valvesoftware.Steam:ro
|
||||
# Pipewire
|
||||
- --filesystem=xdg-run/pipewire-0
|
||||
# Set the active OpenXR / OpenVR runtime
|
||||
|
||||
@@ -219,6 +219,7 @@ if (WIVRN_BUILD_SERVER)
|
||||
PkgConfig::AVAHI
|
||||
Eigen3::Eigen
|
||||
wivrn-common
|
||||
wivrn-common-server
|
||||
wivrn-external
|
||||
nlohmann_json::nlohmann_json
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user