From 2d487b0bef9e27c15dae30ad73513682095e82e3 Mon Sep 17 00:00:00 2001 From: Riccardo Zaglia Date: Wed, 22 Nov 2023 18:21:22 +0800 Subject: [PATCH] fix(dashboard): :bug: Set pipewire devices in the setup wizard --- .../src/dashboard/components/connections.rs | 33 ++----- .../components/settings_controls/help.rs | 1 - .../components/settings_controls/mod.rs | 1 - .../presets/builtin_schema.rs | 2 - .../src/dashboard/components/setup_wizard.rs | 94 +++++++++++++++---- alvr/packets/src/lib.rs | 1 - alvr/server/src/web_server.rs | 3 +- alvr/server_io/src/lib.rs | 37 +------- 8 files changed, 85 insertions(+), 87 deletions(-) delete mode 100644 alvr/dashboard/src/dashboard/components/settings_controls/help.rs diff --git a/alvr/dashboard/src/dashboard/components/connections.rs b/alvr/dashboard/src/dashboard/components/connections.rs index 97b0aed0bb..f0bd7f9748 100644 --- a/alvr/dashboard/src/dashboard/components/connections.rs +++ b/alvr/dashboard/src/dashboard/components/connections.rs @@ -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; @@ -8,7 +8,6 @@ use eframe::{ emath::{Align, Align2}, epaint::Color32, }; -use std::net::{IpAddr, Ipv4Addr}; struct EditPopupState { new_client: bool, @@ -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), @@ -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 { diff --git a/alvr/dashboard/src/dashboard/components/settings_controls/help.rs b/alvr/dashboard/src/dashboard/components/settings_controls/help.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/alvr/dashboard/src/dashboard/components/settings_controls/help.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/alvr/dashboard/src/dashboard/components/settings_controls/mod.rs b/alvr/dashboard/src/dashboard/components/settings_controls/mod.rs index 74935c85b5..0c638540bf 100644 --- a/alvr/dashboard/src/dashboard/components/settings_controls/mod.rs +++ b/alvr/dashboard/src/dashboard/components/settings_controls/mod.rs @@ -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; diff --git a/alvr/dashboard/src/dashboard/components/settings_controls/presets/builtin_schema.rs b/alvr/dashboard/src/dashboard/components/settings_controls/presets/builtin_schema.rs index f1883ba671..d1c6782169 100644 --- a/alvr/dashboard/src/dashboard/components/settings_controls/presets/builtin_schema.rs +++ b/alvr/dashboard/src/dashboard/components/settings_controls/presets/builtin_schema.rs @@ -239,8 +239,6 @@ pub fn microphone_schema(devices: Vec) -> 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, }) diff --git a/alvr/dashboard/src/dashboard/components/setup_wizard.rs b/alvr/dashboard/src/dashboard/components/setup_wizard.rs index 2f3fc7e070..e22fe47eef 100644 --- a/alvr/dashboard/src/dashboard/components/setup_wizard.rs +++ b/alvr/dashboard/src/dashboard/components/setup_wizard.rs @@ -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") @@ -166,6 +220,7 @@ Script is not 100% stable and might cause some instability issues with pipewire, } }, ), + Page::HandGestures => page_content( ui, "Hand Gestures", @@ -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), }]), )); diff --git a/alvr/packets/src/lib.rs b/alvr/packets/src/lib.rs index 2c85e18f82..b70f8fac62 100644 --- a/alvr/packets/src/lib.rs +++ b/alvr/packets/src/lib.rs @@ -188,7 +188,6 @@ pub enum ClientListAction { RemoveEntry, UpdateCurrentIp(Option), SetConnectionState(ConnectionState), - SetCabled(bool), } #[derive(Serialize, Deserialize, Default, Clone)] diff --git a/alvr/server/src/web_server.rs b/alvr/server/src/web_server.rs index 69f8d65e67..95959fcb22 100644 --- a/alvr/server/src/web_server.rs +++ b/alvr/server/src/web_server.rs @@ -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 { diff --git a/alvr/server_io/src/lib.rs b/alvr/server_io/src/lib.rs index c2c5ad4524..4a49cc3e88 100644 --- a/alvr/server_io/src/lib.rs +++ b/alvr/server_io/src/lib.rs @@ -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}, }; @@ -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 {