Skip to content

Commit

Permalink
2.2.3 - Fix SteamVR
Browse files Browse the repository at this point in the history
  • Loading branch information
ShayBox committed Jun 7, 2023
1 parent 0224dcc commit 015acd1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 70 deletions.
76 changes: 34 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = ["loader", "plugin-clock", "plugin-control", "plugin-debug", "plugin-lastfm", "plugin-spotify", "plugin-steamvr"]

[workspace.package]
version = "2.2.2"
version = "2.2.3"
authors = ["Shayne Hartford <[email protected]>"]
edition = "2021"
readme = "README.md"
Expand Down
10 changes: 4 additions & 6 deletions loader/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
collections::HashMap,
fs::File,
io::{Read, Seek, Write},
path::PathBuf,
Expand All @@ -8,7 +7,6 @@ use std::{

use anyhow::Result;
use dialoguer::Confirm;
use libloading::Library;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -36,7 +34,7 @@ impl LoaderConfig {
Ok(path)
}

pub fn load(libraries: &HashMap<String, Library>) -> Result<Self> {
pub fn load() -> Result<Self> {
let path = Self::get_path()?;
let mut file = File::options()
.read(true)
Expand All @@ -52,7 +50,7 @@ impl LoaderConfig {
Ok(config) => Ok(config),
Err(_) => {
let mut config = LoaderConfig::default();
config.setup_wizard(libraries)?;
config.setup_wizard()?;

let text = toml::to_string_pretty(&config)?;
file.write_all(text.as_bytes())?;
Expand All @@ -62,8 +60,8 @@ impl LoaderConfig {
}
}

pub fn setup_wizard(&mut self, libraries: &HashMap<String, Library>) -> Result<()> {
let mut filenames = libraries.keys().collect::<Vec<_>>();
pub fn setup_wizard(&mut self) -> Result<()> {
let mut filenames = crate::get_plugin_names()?;
filenames.sort();

for filename in filenames {
Expand Down
41 changes: 23 additions & 18 deletions loader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
collections::HashMap,
ffi::OsStr,
net::{SocketAddr, UdpSocket},
};
Expand All @@ -13,7 +12,7 @@ use crate::config::LoaderConfig;

pub mod config;

pub fn get_libraries() -> Result<HashMap<String, Library>> {
pub fn get_plugin_names() -> Result<Vec<String>> {
let current_exe = std::env::current_exe()?;
let Some(current_dir) = current_exe.parent() else {
panic!("This shouldn't be possible");
Expand All @@ -26,17 +25,8 @@ pub fn get_libraries() -> Result<HashMap<String, Library>> {
.map(DirEntry::into_path)
.collect::<Vec<_>>();

let mut libraries = HashMap::new();
let mut libraries = Vec::new();
for path in paths {
// libloading doesn't support relative paths on Linux
let path = path.absolutize()?;
let Some(filename) = path.to_str() else {
continue; // No file name
};
let Some(lib_name) = path.file_name().and_then(OsStr::to_str) else {
continue; // No file name
};

let extension = path.extension().and_then(OsStr::to_str);
let Some(extension) = extension else {
continue; // No file extension
Expand All @@ -45,33 +35,48 @@ pub fn get_libraries() -> Result<HashMap<String, Library>> {
continue; // Not a dynamic library
}

unsafe {
let library = Library::new(filename)?;
libraries.insert(lib_name.to_string(), library);
}
let Some(filename) = path.file_name().and_then(OsStr::to_str) else {
continue; // No file name
};

libraries.push(filename.to_owned());
}

Ok(libraries)
}

pub fn load_plugins(
libraries: HashMap<String, Library>,
plugin_names: Vec<String>,
loader_config: &LoaderConfig,
) -> Result<Vec<SocketAddr>> {
let current_exe = std::env::current_exe()?;
let Some(current_dir) = current_exe.parent() else {
panic!("This shouldn't be possible");
};

let mut addrs = Vec::new();
for (filename, library) in libraries {
for filename in plugin_names {
if !loader_config.enabled.contains(&filename) {
continue; // Skip disabled libraries
}

// libloading doesn't support relative paths on Linux
let path = current_dir.join(filename);
let path = path.absolutize()?;
let Some(filename) = path.to_str() else {
continue; // No file name
};

let plugin_socket = UdpSocket::bind("127.0.0.1:0")?; // Dynamic port
let loader_addr = loader_config.bind_addr.replace("0.0.0.0", "127.0.0.1");
plugin_socket.connect(loader_addr)?;

let plugin_addr = plugin_socket.local_addr()?;
addrs.push(plugin_addr);

let filename = filename.to_owned();
tokio::spawn(async move {
let library = unsafe { Library::new(filename).expect("Failed to get the library") };
let load_fn: Symbol<fn(socket: UdpSocket)> = unsafe {
library
.get(b"load")
Expand Down
6 changes: 3 additions & 3 deletions loader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use vrc_osc::config::LoaderConfig;
async fn main() -> Result<()> {
human_panic::setup_panic!();

let libraries = vrc_osc::get_libraries()?;
let loader_config = LoaderConfig::load(&libraries)?;
let loader_config = LoaderConfig::load()?;
let loader_socket = UdpSocket::bind(&loader_config.bind_addr)?;
let plugin_addrs = vrc_osc::load_plugins(libraries, &loader_config)?;
let plugin_names = vrc_osc::get_plugin_names()?;
let plugin_addrs = vrc_osc::load_plugins(plugin_names, &loader_config)?;

loop {
let mut buf = [0u8; MTU];
Expand Down

0 comments on commit 015acd1

Please sign in to comment.