mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-03 06:38:52 +00:00
fix: stop user from importing survive calibration if survive-cli for profile isn't found
This commit is contained in:
parent
6068263d9d
commit
4b95a22045
2 changed files with 59 additions and 24 deletions
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
paths::{data_monado_path, data_opencomposite_path, BWRAP_SYSTEM_PREFIX, SYSTEM_PREFIX},
|
paths::{data_monado_path, data_opencomposite_path, BWRAP_SYSTEM_PREFIX, SYSTEM_PREFIX},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader, slice::Iter};
|
use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader, slice::Iter, path::Path};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
@ -200,6 +200,17 @@ impl Profile {
|
||||||
.join(" ")
|
.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_survive_cli_path(&self) -> Option<String> {
|
||||||
|
let path_s = format!(
|
||||||
|
"{pfx}/bin/survive-cli",
|
||||||
|
pfx = self.prefix
|
||||||
|
);
|
||||||
|
if Path::new(&path_s).is_file() {
|
||||||
|
return Some(path_s);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_profile(path: &String) -> Self {
|
pub fn load_profile(path: &String) -> Self {
|
||||||
let file = File::open(path).expect("Unable to open profile");
|
let file = File::open(path).expect("Unable to open profile");
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{profile::Profile, runner::Runner};
|
use crate::{profile::Profile, runner::Runner};
|
||||||
use gtk::{glib, prelude::*};
|
use gtk::{glib, prelude::*};
|
||||||
use relm4::prelude::*;
|
use relm4::prelude::*;
|
||||||
|
use adw::prelude::*;
|
||||||
use std::{cell::Cell, collections::HashMap, path::Path, rc::Rc, time::Duration};
|
use std::{cell::Cell, collections::HashMap, path::Path, rc::Rc, time::Duration};
|
||||||
|
|
||||||
const NO_FILE_MSG: &str = "(No file selected)";
|
const NO_FILE_MSG: &str = "(No file selected)";
|
||||||
|
@ -27,6 +28,9 @@ pub struct LibsurviveSetupWindow {
|
||||||
#[tracker::do_not_track]
|
#[tracker::do_not_track]
|
||||||
filefilter_listmodel: gtk::gio::ListStore,
|
filefilter_listmodel: gtk::gio::ListStore,
|
||||||
|
|
||||||
|
#[tracker::do_not_track]
|
||||||
|
survive_cli_not_found_dialog: adw::MessageDialog,
|
||||||
|
|
||||||
#[tracker::do_not_track]
|
#[tracker::do_not_track]
|
||||||
calibration_running: Rc<Cell<bool>>,
|
calibration_running: Rc<Cell<bool>>,
|
||||||
#[tracker::do_not_track]
|
#[tracker::do_not_track]
|
||||||
|
@ -51,7 +55,7 @@ pub enum LibsurviveSetupMsg {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LibsurviveSetupWindow {
|
impl LibsurviveSetupWindow {
|
||||||
fn create_calibration_runner(&mut self) -> Runner {
|
fn create_calibration_runner(&mut self, survive_cli_path: String) -> Runner {
|
||||||
let lh_path = self.steam_lighthouse_path.clone();
|
let lh_path = self.steam_lighthouse_path.clone();
|
||||||
let mut env = HashMap::new();
|
let mut env = HashMap::new();
|
||||||
env.insert(
|
env.insert(
|
||||||
|
@ -60,10 +64,7 @@ impl LibsurviveSetupWindow {
|
||||||
);
|
);
|
||||||
Runner::new(
|
Runner::new(
|
||||||
Some(env),
|
Some(env),
|
||||||
format!(
|
survive_cli_path,
|
||||||
"{pfx}/bin/survive-cli",
|
|
||||||
pfx = self.profile.as_ref().unwrap().prefix
|
|
||||||
),
|
|
||||||
vec!["--steamvr-calibration".into(), lh_path],
|
vec!["--steamvr-calibration".into(), lh_path],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -366,24 +367,29 @@ impl SimpleComponent for LibsurviveSetupWindow {
|
||||||
let path_s = self.steam_lighthouse_path.clone();
|
let path_s = self.steam_lighthouse_path.clone();
|
||||||
let lh_path = Path::new(&path_s);
|
let lh_path = Path::new(&path_s);
|
||||||
if lh_path.is_file() {
|
if lh_path.is_file() {
|
||||||
let mut runner = self.create_calibration_runner();
|
let survive_cli_path = self.profile.as_ref().unwrap().get_survive_cli_path();
|
||||||
self.calibration_running.set(true);
|
if survive_cli_path.is_some() {
|
||||||
self.first_run_done = false;
|
let mut runner = self.create_calibration_runner(survive_cli_path.unwrap());
|
||||||
self.calibration_seconds_elapsed = 0.0;
|
self.calibration_running.set(true);
|
||||||
runner.start();
|
self.first_run_done = false;
|
||||||
{
|
self.calibration_seconds_elapsed = 0.0;
|
||||||
let timer_sender = sender.clone();
|
runner.start();
|
||||||
let cont = self.calibration_running.clone();
|
{
|
||||||
glib::timeout_add_local(Duration::from_millis(1000), move || {
|
let timer_sender = sender.clone();
|
||||||
timer_sender.input(LibsurviveSetupMsg::TickCalibrationRunner);
|
let cont = self.calibration_running.clone();
|
||||||
return glib::Continue(cont.get());
|
glib::timeout_add_local(Duration::from_millis(1000), move || {
|
||||||
});
|
timer_sender.input(LibsurviveSetupMsg::TickCalibrationRunner);
|
||||||
|
return glib::Continue(cont.get());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
self.calibration_runner = Some(runner);
|
||||||
|
self.carousel
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.scroll_to(self.loading_page.as_ref().unwrap(), true);
|
||||||
|
} else {
|
||||||
|
self.survive_cli_not_found_dialog.present();
|
||||||
}
|
}
|
||||||
self.calibration_runner = Some(runner);
|
|
||||||
self.carousel
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.scroll_to(self.loading_page.as_ref().unwrap(), true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::Input::SetSteamLighthousePath(n_path) => {
|
Self::Input::SetSteamLighthousePath(n_path) => {
|
||||||
|
@ -427,7 +433,9 @@ impl SimpleComponent for LibsurviveSetupWindow {
|
||||||
self.first_run_done = true;
|
self.first_run_done = true;
|
||||||
let runner = self.calibration_runner.as_mut().unwrap();
|
let runner = self.calibration_runner.as_mut().unwrap();
|
||||||
runner.terminate();
|
runner.terminate();
|
||||||
let mut n_runner = self.create_calibration_runner();
|
let mut n_runner = self.create_calibration_runner(
|
||||||
|
self.profile.as_ref().unwrap().get_survive_cli_path().unwrap(),
|
||||||
|
);
|
||||||
n_runner.start();
|
n_runner.start();
|
||||||
self.calibration_runner = Some(n_runner);
|
self.calibration_runner = Some(n_runner);
|
||||||
}
|
}
|
||||||
|
@ -469,6 +477,18 @@ impl SimpleComponent for LibsurviveSetupWindow {
|
||||||
) -> relm4::ComponentParts<Self> {
|
) -> relm4::ComponentParts<Self> {
|
||||||
let json_filter = gtk::FileFilter::new();
|
let json_filter = gtk::FileFilter::new();
|
||||||
json_filter.add_mime_type("application/json");
|
json_filter.add_mime_type("application/json");
|
||||||
|
|
||||||
|
let survive_cli_not_found_dialog = adw::MessageDialog::builder()
|
||||||
|
.modal(true)
|
||||||
|
.hide_on_close(true)
|
||||||
|
.heading("Survive CLI not found")
|
||||||
|
.body(concat!(
|
||||||
|
"You might need to build this profile first, ",
|
||||||
|
"or maybe Libsurvive isn't enabled for this profile"
|
||||||
|
))
|
||||||
|
.build();
|
||||||
|
survive_cli_not_found_dialog.add_response("ok", "_Ok");
|
||||||
|
|
||||||
let mut model = LibsurviveSetupWindow {
|
let mut model = LibsurviveSetupWindow {
|
||||||
win: None,
|
win: None,
|
||||||
progressbar: None,
|
progressbar: None,
|
||||||
|
@ -486,6 +506,7 @@ impl SimpleComponent for LibsurviveSetupWindow {
|
||||||
calibration_running: Rc::new(Cell::new(false)),
|
calibration_running: Rc::new(Cell::new(false)),
|
||||||
first_run_done: false,
|
first_run_done: false,
|
||||||
calibration_seconds_elapsed: 0.0,
|
calibration_seconds_elapsed: 0.0,
|
||||||
|
survive_cli_not_found_dialog,
|
||||||
tracker: 0,
|
tracker: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -494,6 +515,9 @@ impl SimpleComponent for LibsurviveSetupWindow {
|
||||||
let widgets = view_output!();
|
let widgets = view_output!();
|
||||||
|
|
||||||
model.win = Some(widgets.win.clone());
|
model.win = Some(widgets.win.clone());
|
||||||
|
model
|
||||||
|
.survive_cli_not_found_dialog
|
||||||
|
.set_transient_for(Some(model.win.as_ref().unwrap()));
|
||||||
model.progressbar = Some(widgets.progressbar.clone());
|
model.progressbar = Some(widgets.progressbar.clone());
|
||||||
model.carousel = Some(widgets.carousel.clone());
|
model.carousel = Some(widgets.carousel.clone());
|
||||||
model.loading_page = Some(widgets.loading_page.clone());
|
model.loading_page = Some(widgets.loading_page.clone());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue