Move flatpak utils into common
This commit is contained in:
@@ -25,13 +25,12 @@
|
||||
#include "imgui.h"
|
||||
#include "input_profile.h"
|
||||
#include "openxr/openxr.h"
|
||||
#include "protocol_version.h"
|
||||
#include "render/scene_data.h"
|
||||
#include "render/scene_renderer.h"
|
||||
#include "stream.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "version.h"
|
||||
#include "wivrn_client.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include "xr/passthrough.h"
|
||||
#include "xr/space.h"
|
||||
#include <algorithm>
|
||||
|
||||
@@ -23,6 +23,12 @@ endif()
|
||||
|
||||
configure_file(wivrn_config.h.in wivrn_config.h)
|
||||
|
||||
add_library(wivrn-common-base STATIC
|
||||
utils/xdg_base_directory.cpp
|
||||
utils/flatpak.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
|
||||
)
|
||||
|
||||
add_library(wivrn-common STATIC
|
||||
wivrn_sockets.cpp
|
||||
utils/xdg_base_directory.cpp
|
||||
@@ -30,7 +36,6 @@ add_library(wivrn-common STATIC
|
||||
vk/error_category.cpp
|
||||
vk/vk_allocator.cpp
|
||||
vk/vk_mem_alloc.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
|
||||
)
|
||||
|
||||
if(ANDROID)
|
||||
@@ -55,8 +60,7 @@ else()
|
||||
target_link_libraries(wivrn-common PUBLIC Vulkan::Headers)
|
||||
endif()
|
||||
|
||||
target_link_libraries(wivrn-common PUBLIC Boost::pfr wivrn-external)
|
||||
target_include_directories(wivrn-common-base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(wivrn-common PUBLIC Boost::pfr 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)
|
||||
|
||||
target_include_directories(wivrn-common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "wivrn_packets.h"
|
||||
#include "wivrn_serialization.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
using protocol = std::variant<from_headset::packets, to_headset::packets>;
|
||||
static inline const constinit auto protocol_version = serialization_type_hash<protocol>();
|
||||
} // namespace wivrn
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2024 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
|
||||
@@ -17,10 +17,27 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "version.h"
|
||||
#include "flatpak.h"
|
||||
|
||||
namespace wivrn
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
static const std::filesystem::path info_path = "/.flatpak-info";
|
||||
|
||||
bool wivrn::is_flatpak()
|
||||
{
|
||||
const char git_version[] = "@GIT_DESC@";
|
||||
const char git_commit[] = "@GIT_COMMIT@";
|
||||
} // namespace wivrn
|
||||
return std::filesystem::exists(info_path);
|
||||
}
|
||||
|
||||
std::optional<std::string> wivrn::flatpak_key(std::string key)
|
||||
{
|
||||
key += "=";
|
||||
std::string line;
|
||||
std::ifstream info(info_path);
|
||||
while (std::getline(info, line))
|
||||
{
|
||||
if (line.starts_with(key))
|
||||
return line.substr(key.size());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2024 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
|
||||
@@ -19,8 +19,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
extern const char git_version[];
|
||||
extern const char git_commit[];
|
||||
bool is_flatpak();
|
||||
std::optional<std::string> flatpak_key(std::string key);
|
||||
} // namespace wivrn
|
||||
@@ -1,13 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "wivrn_packets.h"
|
||||
#include "wivrn_serialization.h"
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
using protocol = std::variant<from_headset::packets, to_headset::packets>;
|
||||
|
||||
extern const char git_version[];
|
||||
extern const char git_commit[];
|
||||
static inline const constinit auto protocol_version = serialization_type_hash<protocol>();
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
if (GIT_DESC)
|
||||
configure_file(version.cpp.in version.cpp)
|
||||
else ()
|
||||
add_custom_target(wivrn-dashboard-version ALL
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
|
||||
-D INPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in
|
||||
-D OUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/version.cpp
|
||||
-D CMAKE_PROJECT_VERSION=${CMAKE_PROJECT_VERSION}
|
||||
-P ${CMAKE_SOURCE_DIR}/cmake/GitVersion.cmake
|
||||
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/version.cpp
|
||||
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in
|
||||
)
|
||||
endif()
|
||||
|
||||
# Qt 6.7 changed qt_add_translations()
|
||||
try_compile(AT_LEAST_QT67 SOURCE_FROM_CONTENT check-qt-version.cpp "
|
||||
#include <QtGlobal>
|
||||
@@ -43,7 +28,6 @@ qt_add_executable(wivrn-dashboard
|
||||
steam_app.h
|
||||
adb.cpp
|
||||
adb.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png
|
||||
@@ -81,6 +65,7 @@ target_link_libraries(wivrn-dashboard PRIVATE
|
||||
Qt6::DBus
|
||||
Qt6::Network
|
||||
nlohmann_json
|
||||
wivrn-common-base
|
||||
)
|
||||
|
||||
if (WIVRN_CHECK_CAPSYSNICE)
|
||||
|
||||
+3
-1
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "adb.h"
|
||||
|
||||
#include "utils/flatpak.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
#include <chrono>
|
||||
@@ -31,7 +33,7 @@ std::unique_ptr<QProcess> escape_sandbox(const std::string & executable, Args &&
|
||||
auto process = std::make_unique<QProcess>();
|
||||
QStringList args;
|
||||
|
||||
if (std::filesystem::exists("/.flatpak-info"))
|
||||
if (wivrn::is_flatpak())
|
||||
{
|
||||
process->setProgram("flatpak-spawn");
|
||||
args.push_back("--host");
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "steam_app.h"
|
||||
#include "utils/flatpak.h"
|
||||
#include <QProcess>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
@@ -34,7 +35,7 @@ std::string read_vr_manifest()
|
||||
|
||||
std::filesystem::path vrmanifest = std::string{home ? home : ""} + "/.steam/steam/config/steamapps.vrmanifest";
|
||||
|
||||
if (std::filesystem::exists("/.flatpak-info"))
|
||||
if (wivrn::is_flatpak())
|
||||
{
|
||||
QProcess flatpak_spawn;
|
||||
flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(vrmanifest)});
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user