Merge branch 'feat/flatpak'

This commit is contained in:
Guillaume Meunier
2024-08-31 13:39:24 +02:00
12 changed files with 263 additions and 124 deletions
+19 -2
View File
@@ -164,6 +164,10 @@ target_link_libraries(
nlohmann_json::nlohmann_json
)
if(WIVRN_USE_GLIB)
target_link_libraries( wivrn-server PRIVATE PkgConfig::glib2)
endif()
configure_file(dist/wivrn.service.in wivrn.service)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/wivrn.service
DESTINATION lib/systemd/user/)
@@ -182,9 +186,9 @@ set_target_properties(${RUNTIME_TARGET} PROPERTIES EXCLUDE_FROM_ALL FALSE)
set(_extra_args)
if(WIVRN_OPENXR_INSTALL_ABSOLUTE_RUNTIME_PATH)
set(_extra_args ABSOLUTE_RUNTIME_PATH)
set(_extra_args ABSOLUTE_RUNTIME_PATH)
else()
set(_extra_args RUNTIME_DIR_RELATIVE_TO_MANIFEST ../../../${CMAKE_INSTALL_LIBDIR}/wivrn)
set(_extra_args RUNTIME_DIR_RELATIVE_TO_MANIFEST ../../../${CMAKE_INSTALL_LIBDIR}/wivrn)
endif()
generate_openxr_runtime_manifest_at_install(
@@ -199,3 +203,16 @@ install(TARGETS ${RUNTIME_TARGET} monado
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}/wivrn
COMPONENT Runtime)
install(FILES ../flatpak/io.github.wivrn.wivrn.metainfo.xml
DESTINATION share/metainfo
)
install(FILES ../images/wivrn.svg
DESTINATION share/icons/hicolor/scalable/apps
RENAME io.github.wivrn.wivrn.svg
)
install(FILES ../flatpak/io.github.wivrn.wivrn.desktop
DESTINATION share/applications
)
+58 -3
View File
@@ -5,13 +5,61 @@
#include "util/u_logging.h"
#include "wivrn_config.h"
#ifdef WIVRN_USE_SYSTEMD
#ifdef WIVRN_USE_GLIB
#include <gio/gio.h>
#elif defined(WIVRN_USE_SYSTEMD)
#include <systemd/sd-bus.h>
#endif
std::string hostname()
static std::string _hostname()
{
#ifdef WIVRN_USE_SYSTEMD
#ifdef WIVRN_USE_GLIB
GError * error = NULL;
GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (!con)
{
U_LOG_W("Failed to connect to system bus: %s", error->message);
}
else
{
for (auto property: {"PrettyHostname", "StaticHostname", "Hostname"})
{
GVariant * result = g_dbus_connection_call_sync(con,
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
"org.freedesktop.DBus.Properties",
"Get",
g_variant_new("(ss)", "org.freedesktop.hostname1", property),
G_VARIANT_TYPE("(v)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if (error)
continue;
GVariant * property_value;
g_variant_get(result, "(v)", &property_value);
const char * hostname = g_variant_get_string(property_value, NULL);
if (hostname && strcmp(hostname, ""))
{
std::string s = hostname;
g_variant_unref(property_value);
g_variant_unref(result);
g_object_unref(con);
return s;
}
g_variant_unref(property_value);
g_variant_unref(result);
}
g_object_unref(con);
}
#elif defined(WIVRN_USE_SYSTEMD)
sd_bus * bus;
if (sd_bus_default_system(&bus) < 0)
{
@@ -52,3 +100,10 @@ std::string hostname()
U_LOG_W("Failed to get hostname");
return "no-hostname";
}
std::string hostname()
{
// Accessing hostname in child process fails with glib
static std::string result = _hostname();
return result;
}
+38 -1
View File
@@ -18,6 +18,7 @@
#include "wivrn_sockets.h"
#include <CLI/CLI.hpp>
#include <filesystem>
#include <iostream>
#include <memory>
#include <poll.h>
@@ -123,11 +124,47 @@ void waitpid_verbose(pid_t pid, const std::string & name)
}
}
static std::filesystem::path flatpak_app_path()
{
const std::string key("app-path=");
std::string line;
std::ifstream info("/.flatpak-info");
while (std::getline(info, line))
{
if (line.starts_with(key))
{
std::filesystem::path path = line.substr(key.size());
while (path != "" and path != path.parent_path() and path.filename() != "io.github.wivrn.wivrn")
path = path.parent_path();
return path;
}
}
return "/";
}
static std::string steam_command()
{
std::string pressure_vessel_filesystems_rw = "$XDG_RUNTIME_DIR/" XRT_IPC_MSG_SOCK_FILENAME;
// Check if in a flatpak
if (std::filesystem::exists("/.flatpak-info"))
{
std::string app_path = flatpak_app_path().string();
// /usr and /var are remapped by steam
if (app_path.starts_with("/usr") or app_path.starts_with("/var"))
pressure_vessel_filesystems_rw += ":" + app_path;
}
return "PRESSURE_VESSEL_FILESYSTEMS_RW=" + pressure_vessel_filesystems_rw + " %command%";
}
int inner_main(int argc, char * argv[], bool use_systemd)
{
std::cerr << "WiVRn " << xrt::drivers::wivrn::git_version << " starting" << std::endl;
std::string command = "PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/" XRT_IPC_MSG_SOCK_FILENAME " %command%";
std::string command = steam_command();
if (auto p = active_runtime::manifest_path().string(); p.starts_with("/usr"))
command = "XR_RUNTIME_JSON=/run/host" + p + " " + command;