error handling lol
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use std::{fs::File, io::Read};
|
||||
|
||||
use anyhow::bail;
|
||||
use json::{array, object};
|
||||
use ovr_overlay::applications::ApplicationsManager;
|
||||
|
||||
@@ -7,19 +8,21 @@ use crate::config_io::CONFIG_ROOT_PATH;
|
||||
|
||||
const APP_KEY: &str = "galister.wlxoverlay-s";
|
||||
|
||||
pub(super) fn install_manifest(app_mgr: &mut ApplicationsManager) {
|
||||
let executable_pathbuf = std::env::current_exe().unwrap();
|
||||
let executable_path = executable_pathbuf.to_str().unwrap();
|
||||
pub(super) fn install_manifest(app_mgr: &mut ApplicationsManager) -> anyhow::Result<()> {
|
||||
let executable_pathbuf = std::env::current_exe()?;
|
||||
let executable_path = executable_pathbuf
|
||||
.to_str()
|
||||
.ok_or_else(|| anyhow::anyhow!("Invalid executable path"))?;
|
||||
let manifest_path = CONFIG_ROOT_PATH.join("wlx-overlay-s.vrmanifest");
|
||||
|
||||
if let Ok(true) = app_mgr.is_application_installed(APP_KEY) {
|
||||
if let Ok(mut file) = File::open(&manifest_path) {
|
||||
let mut buf = String::new();
|
||||
if let Ok(_) = file.read_to_string(&mut buf) {
|
||||
let manifest: json::JsonValue = json::parse(&buf).unwrap();
|
||||
let manifest: json::JsonValue = json::parse(&buf)?;
|
||||
if manifest["applications"][0]["binary_path_linux"] == executable_path {
|
||||
log::info!("Manifest already up to date");
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,34 +47,32 @@ pub(super) fn install_manifest(app_mgr: &mut ApplicationsManager) {
|
||||
};
|
||||
|
||||
let Ok(mut file) = File::create(&manifest_path) else {
|
||||
log::error!("Failed to create manifest file at {:?}", manifest_path);
|
||||
return;
|
||||
bail!("Failed to create manifest file at {:?}", manifest_path);
|
||||
};
|
||||
|
||||
let Ok(()) = manifest.write(&mut file) else {
|
||||
log::error!("Failed to write manifest file at {:?}", manifest_path);
|
||||
return;
|
||||
bail!("Failed to write manifest file at {:?}", manifest_path);
|
||||
};
|
||||
|
||||
let Ok(()) = app_mgr.add_application_manifest(&manifest_path, false) else {
|
||||
log::error!("Failed to add manifest to OpenVR");
|
||||
return;
|
||||
bail!("Failed to add manifest to OpenVR");
|
||||
};
|
||||
|
||||
let Ok(()) = app_mgr.set_application_auto_launch(APP_KEY, true) else {
|
||||
log::error!("Failed to set auto launch");
|
||||
return;
|
||||
bail!("Failed to set auto launch");
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn uninstall_manifest(app_mgr: &mut ApplicationsManager) {
|
||||
pub(super) fn uninstall_manifest(app_mgr: &mut ApplicationsManager) -> anyhow::Result<()> {
|
||||
let manifest_path = CONFIG_ROOT_PATH.join("wlx-overlay-s.vrmanifest");
|
||||
|
||||
if let Ok(true) = app_mgr.is_application_installed(APP_KEY) {
|
||||
let Ok(()) = app_mgr.remove_application_manifest(&manifest_path) else {
|
||||
log::error!("Failed to remove manifest from OpenVR");
|
||||
return;
|
||||
bail!("Failed to remove manifest from OpenVR");
|
||||
};
|
||||
log::info!("Uninstalled manifest");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ pub fn openvr_uninstall() {
|
||||
};
|
||||
|
||||
let mut app_mgr = context.applications_mngr();
|
||||
uninstall_manifest(&mut app_mgr);
|
||||
let _ = uninstall_manifest(&mut app_mgr);
|
||||
}
|
||||
|
||||
pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
|
||||
@@ -87,7 +87,7 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
|
||||
AppState::from_graphics(graphics)?
|
||||
};
|
||||
|
||||
install_manifest(&mut app_mgr);
|
||||
let _ = install_manifest(&mut app_mgr);
|
||||
|
||||
let mut overlays = OverlayContainer::<OpenVrOverlayData>::new(&mut state)?;
|
||||
|
||||
@@ -113,7 +113,7 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
|
||||
|
||||
log::info!("HMD running @ {} Hz", refresh_rate);
|
||||
|
||||
let watch_id = overlays.get_by_name(WATCH_NAME).unwrap().state.id;
|
||||
let watch_id = overlays.get_by_name(WATCH_NAME).unwrap().state.id; // want panic
|
||||
|
||||
let frame_time = (1000.0 / refresh_rate).floor() * 0.001;
|
||||
let mut next_device_update = Instant::now();
|
||||
@@ -181,7 +181,7 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
|
||||
.iter_mut()
|
||||
.for_each(|o| o.state.auto_movement(&mut state));
|
||||
|
||||
watch_fade(&mut state, overlays.mut_by_id(watch_id).unwrap());
|
||||
watch_fade(&mut state, overlays.mut_by_id(watch_id).unwrap()); // want panic
|
||||
space_mover.update(&mut chaperone_mgr, &mut overlays, &state);
|
||||
|
||||
let lengths_haptics = interact(&mut overlays, &mut state);
|
||||
|
||||
Reference in New Issue
Block a user