Skip to content

Commit

Permalink
add $HOME/.local/share/slimevr to the possible dirs of the sockets (fix
Browse files Browse the repository at this point in the history
#43) (#44)

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

* Don't throw exception when socket fails to open

Co-authored-by: Uriel <[email protected]>

* Add path constants

Co-authored-by: Kitlith <[email protected]>

* Update src/bridge/bridge-unix-sockets.cpp

Co-authored-by: Kitlith <[email protected]>

* fixup!

---------

Co-authored-by: Kitlith <[email protected]>
Co-authored-by: Uriel <[email protected]>
  • Loading branch information
3 people authored Apr 25, 2024
1 parent ce80726 commit 3aa3792
Showing 1 changed file with 21 additions and 3 deletions.
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

0 comments on commit 3aa3792

Please sign in to comment.