@@ -3,17 +3,20 @@ mod linux_steamvr;
33#[ cfg( windows) ]
44mod windows_steamvr;
55
6+ use std:: { path:: PathBuf , process:: Command } ;
7+
68use crate :: data_sources;
79use alvr_adb:: commands as adb;
810use alvr_common:: {
911 anyhow:: { Context , Result } ,
10- debug,
12+ debug, error ,
1113 glam:: bool,
1214 parking_lot:: Mutex ,
1315 warn,
1416} ;
1517use alvr_filesystem as afs;
1618use serde_json:: { self , json} ;
19+ use settings_schema:: Switch ;
1720use 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+
110131pub 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
0 commit comments