Skip to content

Commit

Permalink
fix(dashboard): 🐛 Set pipewire devices in the setup wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Nov 22, 2023
1 parent 0b0d044 commit 2d487b0
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 87 deletions.
33 changes: 8 additions & 25 deletions alvr/dashboard/src/dashboard/components/connections.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::dashboard::{basic_components, ServerRequest};
use crate::dashboard::ServerRequest;
use alvr_common::ConnectionState;
use alvr_gui_common::theme::{self, log_colors};
use alvr_packets::ClientListAction;
Expand All @@ -8,7 +8,6 @@ use eframe::{
emath::{Align, Align2},
epaint::Color32,
};
use std::net::{IpAddr, Ipv4Addr};

struct EditPopupState {
new_client: bool,
Expand Down Expand Up @@ -214,12 +213,7 @@ fn trusted_clients_section(
.num_columns(2)
.spacing(egui::vec2(8.0, 8.0))
.show(ui, |ui| {
ui.label(format!(
"{hostname}: {} ({})",
data.current_ip
.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)),
data.display_name
));
ui.label(&data.display_name);
ui.horizontal(|ui| {
ui.with_layout(
Layout::right_to_left(Align::Center),
Expand Down Expand Up @@ -248,23 +242,12 @@ fn trusted_clients_section(

ui.end_row();

ui.horizontal(|ui| {
ui.hyperlink_to(
"Use Cable:",
format!(
"https://github.com/alvr-org/ALVR/wiki/{}#{}",
"ALVR-wired-setup-(ALVR-over-USB)",
"letting-your-pc-communicate-with-your-hmd"
),
);
if basic_components::switch(ui, &mut data.cabled).changed()
{
request = Some(ServerRequest::UpdateClientList {
hostname: hostname.clone(),
action: ClientListAction::SetCabled(data.cabled),
});
}
});
ui.label(format!(
"{hostname}: {}",
data.current_ip
.map(|ip| ip.to_string())
.unwrap_or_else(|| "Unknown IP".into()),
));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if ui.button("Remove").clicked() {
request = Some(ServerRequest::UpdateClientList {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub mod boolean;
pub mod choice;
pub mod collapsible;
pub mod dictionary;
pub mod help;
pub mod notice;
pub mod number;
pub mod optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ pub fn microphone_schema(devices: Vec<String>) -> PresetSchemaNode {
string_modifier(&format!("{PREFIX}.variant"), "Custom"),
string_modifier(&format!("{PREFIX}.Custom.sink.variant"), "NameSubstring"),
string_modifier(&format!("{PREFIX}.Custom.sink.NameSubstring"), &name),
// string_modifier(&format!("{PREFIX}.Custom.source.variant"), "NameSubstring"),
// string_modifier(&format!("{PREFIX}.Custom.source.NameSubstring"), ""),
],
content: None,
})
Expand Down
94 changes: 75 additions & 19 deletions alvr/dashboard/src/dashboard/components/setup_wizard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,82 @@ Script is not 100% stable and might cause some instability issues with pipewire,

#[cfg(target_os = "linux")]
if ui
.button("Download and set 'On connect/On disconnect' script")
.button(format!(
"Download and set 'On connect/On disconnect' script, {}",
"set Pipewire audio"
))
.clicked()
{
match download_and_prepare_audio_script() {
Ok(audio_script_path) => {
let path_json = serde_json::Value::String(
audio_script_path.to_string_lossy().to_string(),
);
fn bool_path_value_pair(
session_path: &str,
value: bool,
) -> PathValuePair {
PathValuePair {
path: alvr_packets::parse_path(session_path),
value: serde_json::Value::Bool(value),
}
}
fn string_path_value_pair(
session_path: &str,
value: &str,
) -> PathValuePair {
PathValuePair {
path: alvr_packets::parse_path(session_path),
value: serde_json::Value::String(value.to_owned()),
}
}

const GAME_AUDIO_PREFIX: &str =
"session_settings.audio.game_audio.content.device";
const MIC_PREFIX: &str =
"session_settings.audio.microphone.content.devices";
request = Some(SetupWizardRequest::ServerRequest(
ServerRequest::SetValues(vec![
PathValuePair {
path: alvr_packets::parse_path(
"session_settings.connection.on_connect_script",
),
value: path_json.clone(),
},
PathValuePair {
path: alvr_packets::parse_path(
"session_settings.connection.on_disconnect_script",
),
value: path_json,
},
// scripts
string_path_value_pair(
"session_settings.connection.on_connect_script",
&audio_script_path.to_string_lossy().to_string(),
),
string_path_value_pair(
"session_settings.connection.on_disconnect_script",
&audio_script_path.to_string_lossy().to_string(),
),
// game audio
bool_path_value_pair(
"session_settings.audio.game_audio.enabled",
true,
),
bool_path_value_pair(
&format!("{GAME_AUDIO_PREFIX}.set"),
true,
),
string_path_value_pair(
&format!("{GAME_AUDIO_PREFIX}.content.variant"),
"NameSubstring",
),
string_path_value_pair(
&format!("{GAME_AUDIO_PREFIX}.content.NameSubstring"),
"pipewire",
),
// microphone
bool_path_value_pair(
"session_settings.audio.microphone.enabled",
true,
),
string_path_value_pair(
&format!("{MIC_PREFIX}.variant"),
"Custom",
),
string_path_value_pair(
&format!("{MIC_PREFIX}.Custom.sink.variant"),
"NameSubstring",
),
string_path_value_pair(
&format!("{MIC_PREFIX}.Custom.sink.NameSubstring"),
"pipewire",
),
]),
));
alvr_common::info!("Successfully downloaded and set On connect / On disconnect script")
Expand All @@ -166,6 +220,7 @@ Script is not 100% stable and might cause some instability issues with pipewire,
}
},
),

Page::HandGestures => page_content(
ui,
"Hand Gestures",
Expand All @@ -176,9 +231,10 @@ By default, controller button emulation is set to prevent accidental clicks. You
if basic_components::switch(ui, &mut self.only_touch).changed() {
request = Some(SetupWizardRequest::ServerRequest(
ServerRequest::SetValues(vec![PathValuePair {
path: alvr_packets::parse_path(
"session_settings.headset.controllers.content.gestures.content.only_touch",
),
path: alvr_packets::parse_path(&format!(
"session_settings.headset.controllers.content.{}",
"gestures.content.only_touch"
)),
value: serde_json::Value::Bool(self.only_touch),
}]),
));
Expand Down
1 change: 0 additions & 1 deletion alvr/packets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ pub enum ClientListAction {
RemoveEntry,
UpdateCurrentIp(Option<IpAddr>),
SetConnectionState(ConnectionState),
SetCabled(bool),
}

#[derive(Serialize, Deserialize, Default, Clone)]
Expand Down
3 changes: 1 addition & 2 deletions alvr/server/src/web_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ async fn http_api(

reply(StatusCode::OK)?
}
// Latency in ms
"/api/average-video-latency" => {
"/api/average-video-latency-ms" => {
let latency = if let Some(manager) = &*STATISTICS_MANAGER.lock() {
manager.video_pipeline_latency_average().as_millis()
} else {
Expand Down
37 changes: 1 addition & 36 deletions alvr/server_io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ use alvr_common::{
};
use alvr_events::EventType;
use alvr_packets::{AudioDevicesList, ClientListAction, PathSegment, PathValuePair};
use alvr_session::{ClientConnectionConfig, SessionConfig, Settings, SocketProtocolDefaultVariant};
use alvr_session::{ClientConnectionConfig, SessionConfig, Settings};
use cpal::traits::{DeviceTrait, HostTrait};
use serde_json as json;
use std::{
collections::{hash_map::Entry, HashMap},
fs,
net::{IpAddr, Ipv4Addr},
ops::{Deref, DerefMut},
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -257,40 +256,6 @@ impl ServerDataManager {
}
}
}
ClientListAction::SetCabled(state) => {
if let Entry::Occupied(mut entry) = maybe_client_entry {
entry.get_mut().cabled = state;

if entry.get().cabled {
entry
.get_mut()
.manual_ips
.insert(IpAddr::V4(Ipv4Addr::LOCALHOST));
self.session
.session_settings
.connection
.client_discovery
.enabled = false;
self.session
.session_settings
.connection
.stream_protocol
.variant = SocketProtocolDefaultVariant::Tcp;
} else {
entry
.get_mut()
.manual_ips
.remove(&IpAddr::V4(Ipv4Addr::LOCALHOST));
self.session
.session_settings
.connection
.client_discovery
.enabled = true;
}

updated = true;
}
}
}

if updated {
Expand Down

0 comments on commit 2d487b0

Please sign in to comment.