Skip to content

Commit

Permalink
Added automatic audio script download/placement for alvr
Browse files Browse the repository at this point in the history
  • Loading branch information
Meister1593 committed Nov 13, 2023
1 parent 2d99a37 commit e9058bd
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions alvr/dashboard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
settings-schema = { git = "https://github.com/alvr-org/settings-schema-rs", rev = "676185f" }
statrs = "0.16"
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "blocking", "json"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
alvr_server_io.workspace = true
Expand Down
86 changes: 67 additions & 19 deletions alvr/dashboard/src/dashboard/components/setup_wizard.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use crate::dashboard::basic_components;
use alvr_common::{error, warn};
use alvr_packets::{FirewallRulesAction, PathValuePair, ServerRequest};
use eframe::{
egui::{Button, Label, Layout, OpenUrl, RichText, Ui},
emath::Align,
};
use std::{error::Error, f32::consts::E, os::unix::fs::PermissionsExt};
use std::{
fs::{self, File},
io,
};

pub enum SetupWizardRequest {
ServerRequest(ServerRequest),
Expand Down Expand Up @@ -114,25 +120,47 @@ impl SetupWizard {
Make sure you have at least one output audio device.",
|_| (),
),
Page::SoftwareRequirements => page_content(
ui,
"Software requirements",
r"To stream the Quest microphone on Windows you need to install VB-Cable or Voicemeeter.
On Linux, game audio and microphone might require pipewire and On connect/On disconnect script.",
|ui| {
if ui.button("Download VB-Cable").clicked() {
ui.ctx()
.open_url(OpenUrl::same_tab("https://vb-audio.com/Cable/"));
}
if ui
.button("'On connect/On disconnect' audio script")
.clicked()
{
ui.ctx()
.open_url(OpenUrl::same_tab("https://github.com/alvr-org/ALVR-Distrobox-Linux-Guide/blob/main/audio-setup.sh"));
}
},
),
Page::SoftwareRequirements => {
page_content(
ui,
"Software requirements",
r"To stream the Quest microphone on Windows you need to install VB-Cable or Voicemeeter.
On Linux, game audio and microphone might require pipewire and On connect/On disconnect script.
Script is not 100% stable and might cause some instability issues with pipewire, but it should work.",
|ui| {
if ui.button("Download VB-Cable").clicked() {
ui.ctx()
.open_url(OpenUrl::same_tab("https://vb-audio.com/Cable/"));
}
let button = ui.button("'On connect/On disconnect' audio script");
if button.clicked() {
match download_and_prepare_audio_script() {
Ok(audio_script_path) => {
request =
Some(SetupWizardRequest::ServerRequest(
ServerRequest::SetValues(vec![
PathValuePair {
path: alvr_packets::parse_path(
"session_settings.connection.on_connect_script",
),
value: serde_json::Value::String(audio_script_path.clone()),
},
PathValuePair {
path: alvr_packets::parse_path(
"session_settings.connection.on_disconnect_script",
),
value: serde_json::Value::String(audio_script_path.clone()),
},
]),
));
warn!("Successfully downloaded and set On connect / On disconnect script")
}
Err(e) => error!("{e}"),
}
}
},
)
}
Page::HandGestures => page_content(
ui,
"Hand Gestures",
Expand Down Expand Up @@ -203,3 +231,23 @@ This requires administrator rights!",
request
}
}

fn download_and_prepare_audio_script() -> Result<String, Box<dyn Error>> {
let response = reqwest::blocking::get(
"https://raw.githubusercontent.com/alvr-org/ALVR-Distrobox-Linux-Guide/main/audio-setup.s",
)?;
if !response.status().is_success() {
return Err(format!("Could not download script, status {}", response.status()).into());
}
let body = response.text()?;
let layout = alvr_filesystem::filesystem_layout_invalid();
let config_path = layout
.config_dir
.to_str()
.ok_or("Couldn't get config dir")?;
let audio_script_path = format!("{}/audio-setup.sh", config_path);
let mut out = File::create(audio_script_path.clone())?;
io::copy(&mut body.as_bytes(), &mut out)?;
fs::set_permissions(audio_script_path.clone(), fs::Permissions::from_mode(0o755))?;
Ok(audio_script_path)
}

0 comments on commit e9058bd

Please sign in to comment.