Skip to content

Commit 7aa00ca

Browse files
Iemand005zmerp
andauthored
Add SteamVR offline launch feature (#2994)
* Add SteamVR fastlaunch command * Add quick launch setting toggle * Setting name change * Fix SteamVR naming * Add description for SteamVR Quick Launch * temp * test * SteamVR dynamic root dir * Add default path fallback * SteamVR Launcher bug fix. Quick Launch tested working on Windows * Foxes for Linux * Fixes for macOS * Document formatting fix * Fix small warning * Hard code back app ID * Fix missing function for Linux * Formatting * Remove unused import * Use Switch for SteamVR path * Formatting * Add label for executable path * Name change * Auto launch clarification and naming consistency * Small code adjustments * Formatting * Small fix * Remove redundant description * Small fix * Imports cleanup * Refactor SteamVR launch function * Refactor SteamVR quick launch optimization * parameter fix * Formatting --------- Co-authored-by: zmerp <[email protected]>
1 parent faa9e81 commit 7aa00ca

4 files changed

Lines changed: 68 additions & 12 deletions

File tree

alvr/dashboard/src/steamvr_launcher/linux_steamvr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alvr_common::anyhow::bail;
66
use alvr_common::{debug, error, info, warn};
77
use sysinfo::Process;
88

9-
pub fn start_steamvr() {
9+
pub fn launch_steamvr_with_steam() {
1010
Command::new("steam")
1111
.args(["steam://rungameid/250820"])
1212
.spawn()
@@ -153,9 +153,9 @@ fn linux_gpu_checks(device_infos: &[(&wgpu::Adapter, DeviceInfo)]) {
153153
Ok(dir) => dir,
154154
Err(e) => {
155155
error!(
156-
"Couldn't detect openvr or steamvr files. \
157-
Please make sure you have installed and ran SteamVR at least once. \
158-
Or if you're using Flatpak Steam, make sure to use ALVR Dashboard from Flatpak ALVR. {e}"
156+
"Couldn't find OpenVR or SteamVR files. \
157+
Please make sure you have installed and ran SteamVR at least once. \
158+
Or if you're using Flatpak Steam, make sure to use ALVR Dashboard from Flatpak ALVR. {e}"
159159
);
160160
return;
161161
}

alvr/dashboard/src/steamvr_launcher/mod.rs

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ mod linux_steamvr;
33
#[cfg(windows)]
44
mod windows_steamvr;
55

6+
use std::{path::PathBuf, process::Command};
7+
68
use crate::data_sources;
79
use alvr_adb::commands as adb;
810
use alvr_common::{
911
anyhow::{Context, Result},
10-
debug,
12+
debug, error,
1113
glam::bool,
1214
parking_lot::Mutex,
1315
warn,
1416
};
1517
use alvr_filesystem as afs;
1618
use serde_json::{self, json};
19+
use settings_schema::Switch;
1720
use std::{
1821
ffi::OsStr,
1922
fs,
@@ -107,6 +110,24 @@ fn unblock_alvr_driver_within_vrsettings(text: &str) -> Result<String> {
107110
Ok(serde_json::to_string_pretty(&settings)?)
108111
}
109112

113+
pub fn get_default_steamvr_executable_path() -> Result<String> {
114+
let steamvr_bin_dir = alvr_server_io::steamvr_root_dir()?.join("bin");
115+
116+
let steamvr_path = if cfg!(windows) {
117+
steamvr_bin_dir.join("win64").join("vrstartup.exe")
118+
} else {
119+
steamvr_bin_dir.join("vrmonitor.sh")
120+
};
121+
122+
Ok(steamvr_path.into_os_string().into_string().unwrap())
123+
}
124+
125+
pub fn launch_steamvr_from_path(steamvr_path: &String) {
126+
debug!("Launching SteamVR from path: {}", steamvr_path);
127+
128+
Command::new(steamvr_path).spawn().ok();
129+
}
130+
110131
pub struct Launcher {
111132
_phantom: PhantomData<()>,
112133
}
@@ -156,11 +177,29 @@ impl Launcher {
156177
if !is_steamvr_running() {
157178
debug!("SteamVR is dead. Launching...");
158179

159-
#[cfg(windows)]
160-
windows_steamvr::start_steamvr();
161-
162-
#[cfg(target_os = "linux")]
163-
linux_steamvr::start_steamvr();
180+
if let Switch::Enabled(steamvr_path) = &data_sources::get_read_only_local_session()
181+
.settings()
182+
.extra
183+
.steamvr_launcher
184+
.use_steamvr_path
185+
{
186+
if PathBuf::from(&steamvr_path).exists() {
187+
launch_steamvr_from_path(steamvr_path);
188+
} else {
189+
warn!("SteamVR executable not found at: {steamvr_path}. Trying default path.");
190+
191+
match get_default_steamvr_executable_path() {
192+
Ok(path) => launch_steamvr_from_path(&path),
193+
Err(e) => error!("Couldn't find SteamVR files. {e}"),
194+
};
195+
}
196+
} else {
197+
#[cfg(windows)]
198+
windows_steamvr::launch_steamvr_with_steam();
199+
200+
#[cfg(target_os = "linux")]
201+
linux_steamvr::launch_steamvr_with_steam();
202+
}
164203
}
165204
}
166205

alvr/dashboard/src/steamvr_launcher/windows_steamvr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::process::Command;
33

44
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
55

6-
pub fn start_steamvr() {
6+
pub fn launch_steamvr_with_steam() {
77
Command::new("cmd")
88
.args(["/C", "start", "steam://rungameid/250820"])
99
.creation_flags(CREATE_NO_WINDOW)

alvr/session/src/settings.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,8 +1470,16 @@ pub struct LoggingConfig {
14701470

14711471
#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
14721472
pub struct SteamvrLauncher {
1473-
#[schema(strings(display_name = "Open and close SteamVR with dashboard"))]
1473+
#[schema(strings(
1474+
display_name = "Open and close SteamVR automatically",
1475+
help = "Launches SteamVR automatically when the ALVR dashboard is opened, and closes it when the dashboard is closed."
1476+
))]
14741477
pub open_close_steamvr_with_dashboard: bool,
1478+
#[schema(strings(
1479+
display_name = "Quick launch",
1480+
help = "This speeds up SteamVR launches and allows it to work offline, independent of Steam."
1481+
))]
1482+
pub use_steamvr_path: Switch<String>,
14751483
}
14761484

14771485
#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
@@ -1513,6 +1521,7 @@ pub struct NewVersionPopupConfig {
15131521

15141522
#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
15151523
pub struct ExtraConfig {
1524+
#[schema(strings(display_name = "SteamVR Launcher"))]
15161525
pub steamvr_launcher: SteamvrLauncher,
15171526
pub capture: CaptureConfig,
15181527
pub logging: LoggingConfig,
@@ -2133,6 +2142,14 @@ pub fn session_settings_default() -> SettingsDefault {
21332142
},
21342143
steamvr_launcher: SteamvrLauncherDefault {
21352144
open_close_steamvr_with_dashboard: false,
2145+
use_steamvr_path: SwitchDefault {
2146+
enabled: false,
2147+
content: if cfg!(target_os = "windows") {
2148+
r"C:\Program Files (x86)\Steam\steamapps\common\SteamVR\bin\win64\vrstartup.exe".into()
2149+
} else {
2150+
"".into()
2151+
},
2152+
},
21362153
},
21372154
capture: CaptureConfigDefault {
21382155
startup_video_recording: false,

0 commit comments

Comments
 (0)