Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add $HOME/.local/share/slimevr to the possible dirs of the sockets (fix #43) #44

Merged
merged 5 commits into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/bridge/bridge-unix-sockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <filesystem>

#define TMP_DIR "/tmp"
#define XDG_DATA_DIR_DEFAULT ".local/share"
#define SLIMEVR_DATA_DIR "slimevr"
#define SOCKET_NAME "SlimeVRDriver"

namespace fs = std::filesystem;
Expand Down Expand Up @@ -156,12 +158,28 @@ bool sendBridgeMessage(messages::ProtobufMessage& message, SlimeVRDriver::VRDriv
BridgeStatus runBridgeFrame(SlimeVRDriver::VRDriver& driver) {
try {
if (!client.IsOpen()) {
fs::path socket;
// TODO: do this once in the constructor or something
if(const char* ptr = std::getenv("XDG_RUNTIME_DIR")) {
const fs::path xdg_runtime = ptr;
client.Open((xdg_runtime / SOCKET_NAME).native());
} else {
client.Open((fs::path(TMP_DIR) / SOCKET_NAME).native());
socket = (xdg_runtime / SOCKET_NAME);
}
if(!fs::exists(socket)) {
socket = (fs::path(TMP_DIR) / SOCKET_NAME);
}
// try using home dir if the vrserver is run in a chroot like
if(!fs::exists(socket)) {
if (const char* ptr = std::getenv("XDG_DATA_DIR")) {
const fs::path data_dir = ptr;
socket = (data_dir / SLIMEVR_DATA_DIR / SOCKET_NAME);
} else if (const char* ptr = std::getenv("HOME")) {
const fs::path home = ptr;
socket = (home / XDG_DATA_DIR_DEFAULT / SLIMEVR_DATA_DIR / SOCKET_NAME);
}
}
if(fs::exists(socket)) {
driver.Log("bridge socket: " + std::string(socket));
client.Open(socket.native());
}
}
client.UpdateOnce();
Expand Down
Loading