diff --git a/alvr/dashboard/src/steamvr_launcher/linux_steamvr.rs b/alvr/dashboard/src/steamvr_launcher/linux_steamvr.rs index 234dba3d06..f9d530644d 100644 --- a/alvr/dashboard/src/steamvr_launcher/linux_steamvr.rs +++ b/alvr/dashboard/src/steamvr_launcher/linux_steamvr.rs @@ -6,7 +6,7 @@ use alvr_common::anyhow::bail; use alvr_common::{debug, error, info, warn}; use sysinfo::Process; -pub fn start_steamvr() { +pub fn launch_steamvr_with_steam() { Command::new("steam") .args(["steam://rungameid/250820"]) .spawn() @@ -153,9 +153,9 @@ fn linux_gpu_checks(device_infos: &[(&wgpu::Adapter, DeviceInfo)]) { Ok(dir) => dir, Err(e) => { error!( - "Couldn't detect openvr or steamvr files. \ - Please make sure you have installed and ran SteamVR at least once. \ - Or if you're using Flatpak Steam, make sure to use ALVR Dashboard from Flatpak ALVR. {e}" + "Couldn't find OpenVR or SteamVR files. \ + Please make sure you have installed and ran SteamVR at least once. \ + Or if you're using Flatpak Steam, make sure to use ALVR Dashboard from Flatpak ALVR. {e}" ); return; } diff --git a/alvr/dashboard/src/steamvr_launcher/mod.rs b/alvr/dashboard/src/steamvr_launcher/mod.rs index 012e7d1aee..d2092ab959 100644 --- a/alvr/dashboard/src/steamvr_launcher/mod.rs +++ b/alvr/dashboard/src/steamvr_launcher/mod.rs @@ -3,17 +3,20 @@ mod linux_steamvr; #[cfg(windows)] mod windows_steamvr; +use std::{path::PathBuf, process::Command}; + use crate::data_sources; use alvr_adb::commands as adb; use alvr_common::{ anyhow::{Context, Result}, - debug, + debug, error, glam::bool, parking_lot::Mutex, warn, }; use alvr_filesystem as afs; use serde_json::{self, json}; +use settings_schema::Switch; use std::{ ffi::OsStr, fs, @@ -107,6 +110,24 @@ fn unblock_alvr_driver_within_vrsettings(text: &str) -> Result { Ok(serde_json::to_string_pretty(&settings)?) } +pub fn get_default_steamvr_executable_path() -> Result { + let steamvr_bin_dir = alvr_server_io::steamvr_root_dir()?.join("bin"); + + let steamvr_path = if cfg!(windows) { + steamvr_bin_dir.join("win64").join("vrstartup.exe") + } else { + steamvr_bin_dir.join("vrmonitor.sh") + }; + + Ok(steamvr_path.into_os_string().into_string().unwrap()) +} + +pub fn launch_steamvr_from_path(steamvr_path: &String) { + debug!("Launching SteamVR from path: {}", steamvr_path); + + Command::new(steamvr_path).spawn().ok(); +} + pub struct Launcher { _phantom: PhantomData<()>, } @@ -156,11 +177,29 @@ impl Launcher { if !is_steamvr_running() { debug!("SteamVR is dead. Launching..."); - #[cfg(windows)] - windows_steamvr::start_steamvr(); - - #[cfg(target_os = "linux")] - linux_steamvr::start_steamvr(); + if let Switch::Enabled(steamvr_path) = &data_sources::get_read_only_local_session() + .settings() + .extra + .steamvr_launcher + .use_steamvr_path + { + if PathBuf::from(&steamvr_path).exists() { + launch_steamvr_from_path(steamvr_path); + } else { + warn!("SteamVR executable not found at: {steamvr_path}. Trying default path."); + + match get_default_steamvr_executable_path() { + Ok(path) => launch_steamvr_from_path(&path), + Err(e) => error!("Couldn't find SteamVR files. {e}"), + }; + } + } else { + #[cfg(windows)] + windows_steamvr::launch_steamvr_with_steam(); + + #[cfg(target_os = "linux")] + linux_steamvr::launch_steamvr_with_steam(); + } } } diff --git a/alvr/dashboard/src/steamvr_launcher/windows_steamvr.rs b/alvr/dashboard/src/steamvr_launcher/windows_steamvr.rs index f95b546531..e52765d296 100644 --- a/alvr/dashboard/src/steamvr_launcher/windows_steamvr.rs +++ b/alvr/dashboard/src/steamvr_launcher/windows_steamvr.rs @@ -3,7 +3,7 @@ use std::process::Command; const CREATE_NO_WINDOW: u32 = 0x0800_0000; -pub fn start_steamvr() { +pub fn launch_steamvr_with_steam() { Command::new("cmd") .args(["/C", "start", "steam://rungameid/250820"]) .creation_flags(CREATE_NO_WINDOW) diff --git a/alvr/session/src/settings.rs b/alvr/session/src/settings.rs index 318e830eab..985c314350 100644 --- a/alvr/session/src/settings.rs +++ b/alvr/session/src/settings.rs @@ -1470,8 +1470,16 @@ pub struct LoggingConfig { #[derive(SettingsSchema, Serialize, Deserialize, Clone)] pub struct SteamvrLauncher { - #[schema(strings(display_name = "Open and close SteamVR with dashboard"))] + #[schema(strings( + display_name = "Open and close SteamVR automatically", + help = "Launches SteamVR automatically when the ALVR dashboard is opened, and closes it when the dashboard is closed." + ))] pub open_close_steamvr_with_dashboard: bool, + #[schema(strings( + display_name = "Quick launch", + help = "This speeds up SteamVR launches and allows it to work offline, independent of Steam." + ))] + pub use_steamvr_path: Switch, } #[derive(SettingsSchema, Serialize, Deserialize, Clone)] @@ -1513,6 +1521,7 @@ pub struct NewVersionPopupConfig { #[derive(SettingsSchema, Serialize, Deserialize, Clone)] pub struct ExtraConfig { + #[schema(strings(display_name = "SteamVR Launcher"))] pub steamvr_launcher: SteamvrLauncher, pub capture: CaptureConfig, pub logging: LoggingConfig, @@ -2133,6 +2142,14 @@ pub fn session_settings_default() -> SettingsDefault { }, steamvr_launcher: SteamvrLauncherDefault { open_close_steamvr_with_dashboard: false, + use_steamvr_path: SwitchDefault { + enabled: false, + content: if cfg!(target_os = "windows") { + r"C:\Program Files (x86)\Steam\steamapps\common\SteamVR\bin\win64\vrstartup.exe".into() + } else { + "".into() + }, + }, }, capture: CaptureConfigDefault { startup_video_recording: false,