openvr manifest installer

This commit is contained in:
galister
2024-02-05 00:34:42 +01:00
parent 6bc708714c
commit dddd4db9ef
5 changed files with 133 additions and 23 deletions

View File

@@ -0,0 +1,72 @@
use std::{fs::File, io::Read};
use json::{array, object};
use ovr_overlay::applications::ApplicationsManager;
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();
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();
if manifest["applications"][0]["binary_path_linux"] == executable_path {
log::info!("Manifest already up to date");
return;
}
}
}
}
let manifest = object! {
source: "builtin",
applications: array![
object! {
app_key: APP_KEY,
launch_type: "binary",
binary_path_linux: executable_path,
is_dashboard_overlay: true,
strings: object!{
"en_us": object!{
name: "WlxOverlay-S",
description: "A lightweight Wayland desktop overlay for OpenVR/OpenXR",
},
},
},
],
};
let Ok(mut file) = File::create(&manifest_path) else {
log::error!("Failed to create manifest file at {:?}", manifest_path);
return;
};
let Ok(()) = manifest.write(&mut file) else {
log::error!("Failed to write manifest file at {:?}", manifest_path);
return;
};
let Ok(()) = app_mgr.add_application_manifest(&manifest_path, false) else {
log::error!("Failed to add manifest to OpenVR");
return;
};
}
pub(super) fn uninstall_manifest(app_mgr: &mut ApplicationsManager) {
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;
};
log::info!("Uninstalled manifest");
}
}

View File

@@ -20,22 +20,34 @@ use vulkano::{
use crate::{
backend::{
input::interact,
openvr::{input::OpenVrInputSource, lines::LinePool},
openvr::{input::OpenVrInputSource, lines::LinePool, manifest::install_manifest},
},
graphics::WlxGraphics,
state::AppState,
};
use self::{input::action_manifest_path, overlay::OpenVrOverlayData};
use self::{input::action_manifest_path, manifest::uninstall_manifest, overlay::OpenVrOverlayData};
use super::common::{BackendError, OverlayContainer, TaskType};
pub mod helpers;
pub mod input;
pub mod lines;
pub mod manifest;
pub mod overlay;
pub mod playspace;
pub fn openvr_uninstall() {
let app_type = EVRApplicationType::VRApplication_Overlay;
let Ok(context) = ovr_overlay::Context::init(app_type) else {
log::error!("Uninstall failed: could not reach OpenVR");
return;
};
let mut app_mgr = context.applications_mngr();
uninstall_manifest(&mut app_mgr);
}
pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
let app_type = EVRApplicationType::VRApplication_Overlay;
let Ok(context) = ovr_overlay::Context::init(app_type) else {
@@ -47,6 +59,7 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
let mut overlay_mngr = context.overlay_mngr();
//let mut settings_mngr = context.settings_mngr();
let mut app_mgr = context.applications_mngr();
let mut input_mngr = context.input_mngr();
let mut system_mngr = context.system_mngr();
let mut chaperone_mgr = context.chaperone_setup_mngr();
@@ -69,6 +82,8 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
AppState::from_graphics(graphics)
};
install_manifest(&mut app_mgr);
let mut overlays = OverlayContainer::<OpenVrOverlayData>::new(&mut state);
let mut space_mover = playspace::PlayspaceMover::new();
@@ -210,7 +225,7 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
let mut seconds_since_vsync = 0f32;
std::thread::sleep(Duration::from_secs_f32(
if system_mngr.get_time_since_last_vsync(&mut seconds_since_vsync, &mut 0u64) {
frame_time - (seconds_since_vsync % frame_time)
(frame_time - seconds_since_vsync).max(0.0)
} else {
frame_time
},

View File

@@ -24,6 +24,12 @@ fn main() {
env!("CARGO_PKG_VERSION")
);
#[cfg(feature = "openvr")]
if std::env::args().any(|arg| arg == "--uninstall") {
crate::backend::openvr::openvr_uninstall();
return;
}
let running = Arc::new(AtomicBool::new(true));
let _ = ctrlc::set_handler({
let running = running.clone();