mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-04 07:08:53 +00:00
feat: handle active runtime and openvrpaths replacement non fatal errors
This commit is contained in:
parent
7a88489ef3
commit
7816cf436e
6 changed files with 87 additions and 33 deletions
8
src/checkerr.rs
Normal file
8
src/checkerr.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! checkerr {
|
||||||
|
($ex:expr) => {
|
||||||
|
if $ex.is_err() {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
|
checkerr,
|
||||||
file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly},
|
file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly},
|
||||||
paths::{get_backup_dir, get_xdg_config_dir, get_xdg_data_dir, SYSTEM_PREFIX},
|
paths::{get_backup_dir, get_xdg_config_dir, get_xdg_data_dir, SYSTEM_PREFIX},
|
||||||
profile::{Profile, XRServiceType},
|
profile::{Profile, XRServiceType},
|
||||||
|
@ -69,13 +70,18 @@ pub fn get_current_active_runtime() -> Option<ActiveRuntime> {
|
||||||
get_active_runtime_from_path(&get_active_runtime_json_path())
|
get_active_runtime_from_path(&get_active_runtime_json_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dump_active_runtime_to_path(active_runtime: &ActiveRuntime, path_s: &String) {
|
fn dump_active_runtime_to_path(
|
||||||
|
active_runtime: &ActiveRuntime,
|
||||||
|
path_s: &String,
|
||||||
|
) -> Result<(), serde_json::Error> {
|
||||||
let writer = get_writer(path_s);
|
let writer = get_writer(path_s);
|
||||||
serde_json::to_writer_pretty(writer, active_runtime).expect("Unable to save active runtime");
|
serde_json::to_writer_pretty(writer, active_runtime)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dump_current_active_runtime(active_runtime: &ActiveRuntime) {
|
pub fn dump_current_active_runtime(
|
||||||
dump_active_runtime_to_path(active_runtime, &get_active_runtime_json_path());
|
active_runtime: &ActiveRuntime,
|
||||||
|
) -> Result<(), serde_json::Error> {
|
||||||
|
dump_active_runtime_to_path(active_runtime, &get_active_runtime_json_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_steam_active_runtime() -> ActiveRuntime {
|
fn build_steam_active_runtime() -> ActiveRuntime {
|
||||||
|
@ -96,9 +102,10 @@ fn build_steam_active_runtime() -> ActiveRuntime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_current_active_runtime_to_steam() {
|
pub fn set_current_active_runtime_to_steam() -> Result<(), ()> {
|
||||||
set_file_readonly(&get_active_runtime_json_path(), false);
|
checkerr!(set_file_readonly(&get_active_runtime_json_path(), false));
|
||||||
dump_current_active_runtime(&build_steam_active_runtime())
|
checkerr!(dump_current_active_runtime(&build_steam_active_runtime()));
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_profile_active_runtime(profile: &Profile) -> ActiveRuntime {
|
pub fn build_profile_active_runtime(profile: &Profile) -> ActiveRuntime {
|
||||||
|
@ -119,9 +126,9 @@ pub fn build_profile_active_runtime(profile: &Profile) -> ActiveRuntime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_current_active_runtime_to_profile(profile: &Profile) {
|
pub fn set_current_active_runtime_to_profile(profile: &Profile) -> Result<(), ()> {
|
||||||
let dest = get_active_runtime_json_path();
|
let dest = get_active_runtime_json_path();
|
||||||
set_file_readonly(&dest, false);
|
checkerr!(set_file_readonly(&dest, false));
|
||||||
backup_steam_active_runtime();
|
backup_steam_active_runtime();
|
||||||
let pfx = profile.clone().prefix;
|
let pfx = profile.clone().prefix;
|
||||||
let mut ar = build_profile_active_runtime(profile);
|
let mut ar = build_profile_active_runtime(profile);
|
||||||
|
@ -139,8 +146,9 @@ pub fn set_current_active_runtime_to_profile(profile: &Profile) {
|
||||||
rels = rel_chain.join("/")
|
rels = rel_chain.join("/")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
dump_current_active_runtime(&ar);
|
checkerr!(dump_current_active_runtime(&ar));
|
||||||
set_file_readonly(&dest, true);
|
checkerr!(set_file_readonly(&dest, true));
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -175,6 +183,7 @@ mod tests {
|
||||||
name: Some("SteamVR".into()),
|
name: Some("SteamVR".into()),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
dump_active_runtime_to_path(&ar, &"./target/testout/active_runtime.json.steamvr".into());
|
dump_active_runtime_to_path(&ar, &"./target/testout/active_runtime.json.steamvr".into())
|
||||||
|
.expect("could not dump active runtime to path");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
|
checkerr,
|
||||||
file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly},
|
file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly},
|
||||||
paths::{get_backup_dir, get_xdg_config_dir, get_xdg_data_dir},
|
paths::{get_backup_dir, get_xdg_config_dir, get_xdg_data_dir},
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
|
@ -68,12 +69,15 @@ pub fn get_current_openvrpaths() -> Option<OpenVrPaths> {
|
||||||
get_openvrpaths_from_path(&get_openvrpaths_vrpath_path())
|
get_openvrpaths_from_path(&get_openvrpaths_vrpath_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dump_openvrpaths_to_path(ovr_paths: &OpenVrPaths, path_s: &String) {
|
fn dump_openvrpaths_to_path(
|
||||||
|
ovr_paths: &OpenVrPaths,
|
||||||
|
path_s: &String,
|
||||||
|
) -> Result<(), serde_json::Error> {
|
||||||
let writer = get_writer(path_s);
|
let writer = get_writer(path_s);
|
||||||
serde_json::to_writer_pretty(writer, ovr_paths).expect("Unable to save openvrpaths");
|
serde_json::to_writer_pretty(writer, ovr_paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dump_current_openvrpaths(ovr_paths: &OpenVrPaths) {
|
pub fn dump_current_openvrpaths(ovr_paths: &OpenVrPaths) -> Result<(), serde_json::Error> {
|
||||||
dump_openvrpaths_to_path(ovr_paths, &get_openvrpaths_vrpath_path())
|
dump_openvrpaths_to_path(ovr_paths, &get_openvrpaths_vrpath_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,9 +100,10 @@ fn build_steam_openvrpaths() -> OpenVrPaths {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_current_openvrpaths_to_steam() {
|
pub fn set_current_openvrpaths_to_steam() -> Result<(), ()> {
|
||||||
set_file_readonly(&get_openvrpaths_vrpath_path(), false);
|
checkerr!(set_file_readonly(&get_openvrpaths_vrpath_path(), false));
|
||||||
dump_current_openvrpaths(&build_steam_openvrpaths())
|
checkerr!(dump_current_openvrpaths(&build_steam_openvrpaths()));
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_profile_openvrpaths(profile: &Profile) -> OpenVrPaths {
|
pub fn build_profile_openvrpaths(profile: &Profile) -> OpenVrPaths {
|
||||||
|
@ -116,12 +121,13 @@ pub fn build_profile_openvrpaths(profile: &Profile) -> OpenVrPaths {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_current_openvrpaths_to_profile(profile: &Profile) {
|
pub fn set_current_openvrpaths_to_profile(profile: &Profile) -> Result<(), ()> {
|
||||||
let dest = get_openvrpaths_vrpath_path();
|
let dest = get_openvrpaths_vrpath_path();
|
||||||
set_file_readonly(&dest, false);
|
checkerr!(set_file_readonly(&dest, false));
|
||||||
backup_steam_openvrpaths();
|
backup_steam_openvrpaths();
|
||||||
dump_current_openvrpaths(&build_profile_openvrpaths(profile));
|
checkerr!(dump_current_openvrpaths(&build_profile_openvrpaths(profile)));
|
||||||
set_file_readonly(&dest, true);
|
checkerr!(set_file_readonly(&dest, true));
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -152,5 +158,6 @@ mod tests {
|
||||||
version: 1,
|
version: 1,
|
||||||
};
|
};
|
||||||
dump_openvrpaths_to_path(&ovrp, &"./target/testout/openvrpaths.vrpath".into())
|
dump_openvrpaths_to_path(&ovrp, &"./target/testout/openvrpaths.vrpath".into())
|
||||||
|
.expect("could not dump openvrpaths to path");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,17 +52,17 @@ pub fn deserialize_file<T: serde::de::DeserializeOwned>(path_s: &String) -> Opti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_file_readonly(path_s: &String, readonly: bool) {
|
pub fn set_file_readonly(path_s: &String, readonly: bool) -> Result<(), std::io::Error> {
|
||||||
let path = Path::new(&path_s);
|
let path = Path::new(&path_s);
|
||||||
if !path.is_file() {
|
if !path.is_file() {
|
||||||
println!("WARN: trying to set readonly on a file that does not exist");
|
println!("WARN: trying to set readonly on a file that does not exist");
|
||||||
return;
|
return Ok(());
|
||||||
}
|
}
|
||||||
let mut perms = fs::metadata(path)
|
let mut perms = fs::metadata(path)
|
||||||
.expect("Could not get metadata for file")
|
.expect("Could not get metadata for file")
|
||||||
.permissions();
|
.permissions();
|
||||||
perms.set_readonly(readonly);
|
perms.set_readonly(readonly);
|
||||||
fs::set_permissions(path, perms).expect("Could not set permissions for file")
|
fs::set_permissions(path, perms)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setcap_cap_sys_nice_eip(file: String) {
|
pub fn setcap_cap_sys_nice_eip(file: String) {
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub mod runner_pipeline;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod xr_devices;
|
pub mod xr_devices;
|
||||||
pub mod build_tools;
|
pub mod build_tools;
|
||||||
|
pub mod checkerr;
|
||||||
|
|
||||||
fn restore_steam_xr_files() {
|
fn restore_steam_xr_files() {
|
||||||
let active_runtime = get_current_active_runtime();
|
let active_runtime = get_current_active_runtime();
|
||||||
|
|
|
@ -126,10 +126,23 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_xrservice(&mut self) {
|
pub fn start_xrservice(&mut self) {
|
||||||
self.set_inhibit_session(true);
|
|
||||||
let prof = self.get_selected_profile();
|
let prof = self.get_selected_profile();
|
||||||
set_current_active_runtime_to_profile(&prof);
|
if set_current_active_runtime_to_profile(&prof).is_err() {
|
||||||
set_current_openvrpaths_to_profile(&prof);
|
alert(
|
||||||
|
"Failed to start XR Service",
|
||||||
|
Some("Error setting current active runtime to profile"),
|
||||||
|
Some(&self.app_win.clone().upcast::<gtk::Window>()),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if set_current_openvrpaths_to_profile(&prof).is_err() {
|
||||||
|
alert(
|
||||||
|
"Failed to start XR Service",
|
||||||
|
Some("Error setting current openvrpaths file to profile"),
|
||||||
|
Some(&self.app_win.clone().upcast::<gtk::Window>()),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
};
|
||||||
self.devices_processed = match prof.xrservice_type {
|
self.devices_processed = match prof.xrservice_type {
|
||||||
XRServiceType::Monado => false,
|
XRServiceType::Monado => false,
|
||||||
XRServiceType::Wivrn => true, // no device from log in wivrn
|
XRServiceType::Wivrn => true, // no device from log in wivrn
|
||||||
|
@ -145,6 +158,7 @@ impl App {
|
||||||
true,
|
true,
|
||||||
Some(self.get_selected_profile()),
|
Some(self.get_selected_profile()),
|
||||||
));
|
));
|
||||||
|
self.set_inhibit_session(true);
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
alert(
|
alert(
|
||||||
|
@ -159,15 +173,31 @@ impl App {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn restore_openxr_openvr_files(&self) {
|
||||||
|
if set_current_active_runtime_to_steam().is_err() {
|
||||||
|
alert(
|
||||||
|
"Could not restore Steam active runtime",
|
||||||
|
None,
|
||||||
|
Some(&self.app_win.clone().upcast::<gtk::Window>()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if set_current_openvrpaths_to_steam().is_err() {
|
||||||
|
alert(
|
||||||
|
"Could not restore Steam openvrpaths",
|
||||||
|
None,
|
||||||
|
Some(&self.app_win.clone().upcast::<gtk::Window>()),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn shutdown_xrservice(&mut self) {
|
pub fn shutdown_xrservice(&mut self) {
|
||||||
|
self.set_inhibit_session(false);
|
||||||
if self.xrservice_runner.is_some() {
|
if self.xrservice_runner.is_some() {
|
||||||
if self.xrservice_runner.as_mut().unwrap().status() == RunnerStatus::Running {
|
if self.xrservice_runner.as_mut().unwrap().status() == RunnerStatus::Running {
|
||||||
self.xrservice_runner.as_mut().unwrap().terminate();
|
self.xrservice_runner.as_mut().unwrap().terminate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_current_active_runtime_to_steam();
|
self.restore_openxr_openvr_files();
|
||||||
set_current_openvrpaths_to_steam();
|
|
||||||
self.set_inhibit_session(false);
|
|
||||||
self.main_view
|
self.main_view
|
||||||
.sender()
|
.sender()
|
||||||
.emit(MainViewMsg::XRServiceActiveChanged(false, None));
|
.emit(MainViewMsg::XRServiceActiveChanged(false, None));
|
||||||
|
@ -231,8 +261,7 @@ impl SimpleComponent for App {
|
||||||
self.xrservice_runner.as_mut().unwrap().terminate();
|
self.xrservice_runner.as_mut().unwrap().terminate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_current_active_runtime_to_steam();
|
self.restore_openxr_openvr_files();
|
||||||
set_current_openvrpaths_to_steam();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) {
|
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue