Move flatpak utils into common

This commit is contained in:
Patrick Nicolas
2024-11-07 19:41:33 +01:00
parent 4123b35175
commit 19a399640a
12 changed files with 69 additions and 67 deletions
+3 -12
View File
@@ -18,10 +18,10 @@
*/
#include "active_runtime.h"
#include "utils/flatpak.h"
#include "utils/xdg_base_directory.h"
#include "wivrn_config.h"
#include <filesystem>
#include <fstream>
#include <iostream>
namespace wivrn
@@ -31,17 +31,8 @@ std::filesystem::path active_runtime::manifest_path()
{
const std::filesystem::path install_location = "share/openxr/1/openxr_wivrn.json";
// Check if in a flatpak
if (std::filesystem::exists("/.flatpak-info"))
{
const std::string key("app-path=");
std::string line;
std::ifstream info("/.flatpak-info");
while (std::getline(info, line))
{
if (line.starts_with(key))
return line.substr(key.size()) / install_location.relative_path();
}
}
if (auto path = flatpak_key("app-path"))
return *path / install_location.relative_path();
// Check if running from build directory
auto exe = std::filesystem::read_symlink("/proc/self/exe");
+8 -12
View File
@@ -14,7 +14,9 @@
#include "driver/configuration.h"
#include "exit_codes.h"
#include "hostname.h"
#include "protocol_version.h"
#include "start_application.h"
#include "utils/flatpak.h"
#include "version.h"
#include "wivrn_config.h"
#include "wivrn_ipc.h"
@@ -131,19 +133,13 @@ void display_child_status(int wstatus, 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 (auto value = flatpak_key("app-path"))
{
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();
std::filesystem::path path = *value;
while (path != "" and path != path.parent_path() and path.filename() != "io.github.wivrn.wivrn")
path = path.parent_path();
return path;
}
return path;
}
return "/";
@@ -154,7 +150,7 @@ 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"))
if (is_flatpak())
{
std::string app_path = flatpak_app_path().string();
// /usr and /var are remapped by steam
+2 -2
View File
@@ -9,8 +9,8 @@
#include "start_application.h"
#include "driver/configuration.h"
#include "utils/flatpak.h"
#include <filesystem>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
@@ -235,7 +235,7 @@ int wivrn::exec_application(configuration config)
std::string executable;
std::vector<std::string> args;
if (std::filesystem::exists("/.flatpak-info"))
if (is_flatpak())
{
executable = "flatpak-spawn";
args.push_back("flatpak-spawn");