error handling lol
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
use std::{fs::File, io::Read};
|
use std::{fs::File, io::Read};
|
||||||
|
|
||||||
|
use anyhow::bail;
|
||||||
use json::{array, object};
|
use json::{array, object};
|
||||||
use ovr_overlay::applications::ApplicationsManager;
|
use ovr_overlay::applications::ApplicationsManager;
|
||||||
|
|
||||||
@@ -7,19 +8,21 @@ use crate::config_io::CONFIG_ROOT_PATH;
|
|||||||
|
|
||||||
const APP_KEY: &str = "galister.wlxoverlay-s";
|
const APP_KEY: &str = "galister.wlxoverlay-s";
|
||||||
|
|
||||||
pub(super) fn install_manifest(app_mgr: &mut ApplicationsManager) {
|
pub(super) fn install_manifest(app_mgr: &mut ApplicationsManager) -> anyhow::Result<()> {
|
||||||
let executable_pathbuf = std::env::current_exe().unwrap();
|
let executable_pathbuf = std::env::current_exe()?;
|
||||||
let executable_path = executable_pathbuf.to_str().unwrap();
|
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");
|
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(true) = app_mgr.is_application_installed(APP_KEY) {
|
||||||
if let Ok(mut file) = File::open(&manifest_path) {
|
if let Ok(mut file) = File::open(&manifest_path) {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Ok(_) = file.read_to_string(&mut buf) {
|
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 {
|
if manifest["applications"][0]["binary_path_linux"] == executable_path {
|
||||||
log::info!("Manifest already up to date");
|
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 {
|
let Ok(mut file) = File::create(&manifest_path) else {
|
||||||
log::error!("Failed to create manifest file at {:?}", manifest_path);
|
bail!("Failed to create manifest file at {:?}", manifest_path);
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let Ok(()) = manifest.write(&mut file) else {
|
let Ok(()) = manifest.write(&mut file) else {
|
||||||
log::error!("Failed to write manifest file at {:?}", manifest_path);
|
bail!("Failed to write manifest file at {:?}", manifest_path);
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let Ok(()) = app_mgr.add_application_manifest(&manifest_path, false) else {
|
let Ok(()) = app_mgr.add_application_manifest(&manifest_path, false) else {
|
||||||
log::error!("Failed to add manifest to OpenVR");
|
bail!("Failed to add manifest to OpenVR");
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let Ok(()) = app_mgr.set_application_auto_launch(APP_KEY, true) else {
|
let Ok(()) = app_mgr.set_application_auto_launch(APP_KEY, true) else {
|
||||||
log::error!("Failed to set auto launch");
|
bail!("Failed to set auto launch");
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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");
|
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(true) = app_mgr.is_application_installed(APP_KEY) {
|
||||||
let Ok(()) = app_mgr.remove_application_manifest(&manifest_path) else {
|
let Ok(()) = app_mgr.remove_application_manifest(&manifest_path) else {
|
||||||
log::error!("Failed to remove manifest from OpenVR");
|
bail!("Failed to remove manifest from OpenVR");
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
log::info!("Uninstalled manifest");
|
log::info!("Uninstalled manifest");
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ pub fn openvr_uninstall() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut app_mgr = context.applications_mngr();
|
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> {
|
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)?
|
AppState::from_graphics(graphics)?
|
||||||
};
|
};
|
||||||
|
|
||||||
install_manifest(&mut app_mgr);
|
let _ = install_manifest(&mut app_mgr);
|
||||||
|
|
||||||
let mut overlays = OverlayContainer::<OpenVrOverlayData>::new(&mut state)?;
|
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);
|
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 frame_time = (1000.0 / refresh_rate).floor() * 0.001;
|
||||||
let mut next_device_update = Instant::now();
|
let mut next_device_update = Instant::now();
|
||||||
@@ -181,7 +181,7 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
|
|||||||
.iter_mut()
|
.iter_mut()
|
||||||
.for_each(|o| o.state.auto_movement(&mut state));
|
.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);
|
space_mover.update(&mut chaperone_mgr, &mut overlays, &state);
|
||||||
|
|
||||||
let lengths_haptics = interact(&mut overlays, &mut state);
|
let lengths_haptics = interact(&mut overlays, &mut state);
|
||||||
|
|||||||
@@ -128,10 +128,11 @@ pub fn load_general() -> GeneralConfig {
|
|||||||
let path_conf_d = get_conf_d_path();
|
let path_conf_d = get_conf_d_path();
|
||||||
if let Ok(paths_unsorted) = std::fs::read_dir(path_conf_d) {
|
if let Ok(paths_unsorted) = std::fs::read_dir(path_conf_d) {
|
||||||
// Sort paths alphabetically
|
// Sort paths alphabetically
|
||||||
let mut paths: Vec<_> = paths_unsorted.map(|r| r.unwrap()).collect();
|
let mut paths: Vec<_> = paths_unsorted.map(|r| r.unwrap()).collect(); // TODO safe unwrap?
|
||||||
paths.sort_by_key(|dir| dir.path());
|
paths.sort_by_key(|dir| dir.path());
|
||||||
for path in paths {
|
for path in paths {
|
||||||
if !path.file_type().unwrap().is_file() {
|
if !path.file_type().unwrap().is_file() {
|
||||||
|
// TODO safe unwrap?
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -668,7 +668,7 @@ impl<D, S> Control<D, S> {
|
|||||||
)?;
|
)?;
|
||||||
let set0 = canvas.pipeline_fg_glyph.uniform_sampler(
|
let set0 = canvas.pipeline_fg_glyph.uniform_sampler(
|
||||||
0,
|
0,
|
||||||
ImageView::new_default(tex).unwrap(),
|
ImageView::new_default(tex)?,
|
||||||
Filter::Linear,
|
Filter::Linear,
|
||||||
)?;
|
)?;
|
||||||
let set1 = canvas.pipeline_fg_glyph.uniform_buffer(
|
let set1 = canvas.pipeline_fg_glyph.uniform_buffer(
|
||||||
@@ -717,7 +717,7 @@ impl<D, S> Control<D, S> {
|
|||||||
)?;
|
)?;
|
||||||
let set0 = canvas.pipeline_fg_glyph.uniform_sampler(
|
let set0 = canvas.pipeline_fg_glyph.uniform_sampler(
|
||||||
0,
|
0,
|
||||||
ImageView::new_default(tex).unwrap(),
|
ImageView::new_default(tex)?,
|
||||||
Filter::Linear,
|
Filter::Linear,
|
||||||
)?;
|
)?;
|
||||||
let set1 = canvas.pipeline_fg_glyph.uniform_buffer(
|
let set1 = canvas.pipeline_fg_glyph.uniform_buffer(
|
||||||
|
|||||||
@@ -417,7 +417,7 @@ impl OverlayRenderer for ScreenRenderer {
|
|||||||
let mut pipeline = None;
|
let mut pipeline = None;
|
||||||
if mouse.is_some() {
|
if mouse.is_some() {
|
||||||
let new_pipeline = self.pipeline.get_or_insert_with(|| {
|
let new_pipeline = self.pipeline.get_or_insert_with(|| {
|
||||||
let mut pipeline = ScreenPipeline::new(&self.extent, app).unwrap();
|
let mut pipeline = ScreenPipeline::new(&self.extent, app).unwrap(); // TODO
|
||||||
self.last_view = Some(pipeline.view.clone());
|
self.last_view = Some(pipeline.view.clone());
|
||||||
pipeline.ensure_mouse_initialized(&mut upload).unwrap(); // TODO
|
pipeline.ensure_mouse_initialized(&mut upload).unwrap(); // TODO
|
||||||
pipeline
|
pipeline
|
||||||
@@ -430,7 +430,7 @@ impl OverlayRenderer for ScreenRenderer {
|
|||||||
if let Some(pipeline) = pipeline {
|
if let Some(pipeline) = pipeline {
|
||||||
pipeline.render(image, mouse.as_ref(), app)?;
|
pipeline.render(image, mouse.as_ref(), app)?;
|
||||||
} else {
|
} else {
|
||||||
let view = ImageView::new_default(image).unwrap();
|
let view = ImageView::new_default(image)?;
|
||||||
self.last_view = Some(view);
|
self.last_view = Some(view);
|
||||||
}
|
}
|
||||||
self.capture.request_new_frame();
|
self.capture.request_new_frame();
|
||||||
@@ -459,6 +459,7 @@ impl OverlayRenderer for ScreenRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
|
/// Panics if id is not a valid output id
|
||||||
fn try_create_screen<O>(
|
fn try_create_screen<O>(
|
||||||
wl: &WlxClient,
|
wl: &WlxClient,
|
||||||
id: u32,
|
id: u32,
|
||||||
@@ -468,7 +469,7 @@ fn try_create_screen<O>(
|
|||||||
where
|
where
|
||||||
O: Default,
|
O: Default,
|
||||||
{
|
{
|
||||||
let output = &wl.outputs.get(id).unwrap();
|
let output = &wl.outputs.get(id).unwrap(); // safe due to contract
|
||||||
log::info!(
|
log::info!(
|
||||||
"{}: Res {}x{} Size {:?} Pos {:?}",
|
"{}: Res {}x{} Size {:?} Pos {:?}",
|
||||||
output.name,
|
output.name,
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ fn btn_func_dn(
|
|||||||
func_right,
|
func_right,
|
||||||
func_middle,
|
func_middle,
|
||||||
} = control.state.as_ref().unwrap()
|
} = control.state.as_ref().unwrap()
|
||||||
// want to panic if state not found
|
// want panic
|
||||||
else {
|
else {
|
||||||
log::error!("FuncButton state not found");
|
log::error!("FuncButton state not found");
|
||||||
return;
|
return;
|
||||||
@@ -403,7 +403,7 @@ fn battery_update(control: &mut Control<(), ElemState>, _: &mut (), app: &mut Ap
|
|||||||
fg_color_low,
|
fg_color_low,
|
||||||
fg_color_charging,
|
fg_color_charging,
|
||||||
} = control.state.as_ref().unwrap()
|
} = control.state.as_ref().unwrap()
|
||||||
// want to panic if state not found
|
// want panic
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -449,7 +449,7 @@ fn exec_button(
|
|||||||
ref mut child,
|
ref mut child,
|
||||||
..
|
..
|
||||||
} = control.state.as_mut().unwrap()
|
} = control.state.as_mut().unwrap()
|
||||||
// want to panic if state not found
|
// want panic
|
||||||
else {
|
else {
|
||||||
log::error!("ExecButton state not found");
|
log::error!("ExecButton state not found");
|
||||||
return;
|
return;
|
||||||
@@ -490,7 +490,7 @@ fn exec_label_update(control: &mut Control<(), ElemState>, _: &mut (), _: &mut A
|
|||||||
exec,
|
exec,
|
||||||
ref mut child,
|
ref mut child,
|
||||||
} = control.state.as_mut().unwrap()
|
} = control.state.as_mut().unwrap()
|
||||||
// want to panic if state not found
|
// want panic
|
||||||
else {
|
else {
|
||||||
log::error!("AutoExec state not found");
|
log::error!("AutoExec state not found");
|
||||||
return;
|
return;
|
||||||
@@ -553,7 +553,7 @@ fn exec_label_update(control: &mut Control<(), ElemState>, _: &mut (), _: &mut A
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clock_update(control: &mut Control<(), ElemState>, _: &mut (), _: &mut AppState) {
|
fn clock_update(control: &mut Control<(), ElemState>, _: &mut (), _: &mut AppState) {
|
||||||
// want to panic if state not found
|
// want panic
|
||||||
let ElemState::Clock { timezone, format } = control.state.as_ref().unwrap() else {
|
let ElemState::Clock { timezone, format } = control.state.as_ref().unwrap() else {
|
||||||
log::error!("Clock state not found");
|
log::error!("Clock state not found");
|
||||||
return;
|
return;
|
||||||
@@ -574,7 +574,7 @@ fn overlay_button_scroll(
|
|||||||
app: &mut AppState,
|
app: &mut AppState,
|
||||||
delta: f32,
|
delta: f32,
|
||||||
) {
|
) {
|
||||||
// want to panic if state not found
|
// want panic
|
||||||
let ElemState::OverlayButton { overlay, .. } = control.state.as_mut().unwrap() else {
|
let ElemState::OverlayButton { overlay, .. } = control.state.as_mut().unwrap() else {
|
||||||
log::error!("OverlayButton state not found");
|
log::error!("OverlayButton state not found");
|
||||||
return;
|
return;
|
||||||
@@ -612,7 +612,7 @@ fn overlay_button_dn(
|
|||||||
ref mut mode,
|
ref mut mode,
|
||||||
..
|
..
|
||||||
} = control.state.as_mut().unwrap()
|
} = control.state.as_mut().unwrap()
|
||||||
// want to panic if state not found
|
// want panic
|
||||||
else {
|
else {
|
||||||
log::error!("OverlayButton state not found");
|
log::error!("OverlayButton state not found");
|
||||||
return;
|
return;
|
||||||
@@ -627,7 +627,7 @@ fn overlay_button_up(control: &mut Control<(), ElemState>, _: &mut (), app: &mut
|
|||||||
mode,
|
mode,
|
||||||
overlay,
|
overlay,
|
||||||
} = control.state.as_ref().unwrap()
|
} = control.state.as_ref().unwrap()
|
||||||
// want to panic if state not found
|
// want panic
|
||||||
else {
|
else {
|
||||||
log::error!("OverlayButton state not found");
|
log::error!("OverlayButton state not found");
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user