mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-09-03 16:15:46 +00:00
feat: can build monado from gui
This commit is contained in:
parent
c24bb2eecd
commit
4e5e2c4d80
6 changed files with 102 additions and 12 deletions
|
@ -10,7 +10,7 @@ iced = { version = "0.9.0", features = [
|
|||
"smol"
|
||||
] }
|
||||
iced_aw = { version = "0.5.2", default-features = false, features = [
|
||||
"tab_bar", "tabs", "quad"
|
||||
"tab_bar", "tabs", "quad", "modal", "card"
|
||||
] }
|
||||
nix = "0.26.2"
|
||||
serde = { version = "1.0.163", features = [
|
||||
|
|
12
src/builders/build_monado.rs
Normal file
12
src/builders/build_monado.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::{runner::Runner, profile::Profile};
|
||||
|
||||
pub fn get_build_monado_runner(profile: Profile) -> Runner {
|
||||
let mut runner = Runner::new(
|
||||
None,
|
||||
"./scripts/build_monado.sh".into(),
|
||||
vec![
|
||||
profile.monado_path
|
||||
]
|
||||
);
|
||||
runner
|
||||
}
|
3
src/builders/mod.rs
Normal file
3
src/builders/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
pub mod build_monado;
|
||||
|
|
@ -10,6 +10,7 @@ pub mod file_utils;
|
|||
pub mod profiles;
|
||||
pub mod depcheck;
|
||||
pub mod dependencies;
|
||||
pub mod builders;
|
||||
|
||||
fn main() {
|
||||
MainWin::run(Settings::default());
|
||||
|
|
|
@ -43,7 +43,6 @@ macro_rules! logger_thread {
|
|||
match reader.read_line(&mut buf) {
|
||||
Err(_) => return,
|
||||
Ok(bytes_read) => {
|
||||
println!("{}", bytes_read);
|
||||
if bytes_read == 0 {
|
||||
return;
|
||||
}
|
||||
|
@ -62,10 +61,13 @@ macro_rules! logger_thread {
|
|||
}
|
||||
|
||||
impl Runner {
|
||||
pub fn new(environment: HashMap<String, String>, command: String, args: Vec<String>) -> Self {
|
||||
pub fn new(environment: Option<HashMap<String, String>>, command: String, args: Vec<String>) -> Self {
|
||||
let (sender, receiver) = sync_channel(64000);
|
||||
Self {
|
||||
environment,
|
||||
environment: match environment {
|
||||
None => HashMap::new(),
|
||||
Some(e) => e.clone(),
|
||||
},
|
||||
command,
|
||||
args,
|
||||
output: Vec::new(),
|
||||
|
@ -77,7 +79,11 @@ impl Runner {
|
|||
}
|
||||
|
||||
pub fn monado_runner_from_profile(profile: Profile) -> Self {
|
||||
Self::new(profile.environment, profile.monado_path, vec![])
|
||||
let mut path = profile.monado_path;
|
||||
if !path.starts_with("/usr") {
|
||||
path += "/build/src/xrt/targets/service/monado-service";
|
||||
}
|
||||
Self::new(Some(profile.environment), path, vec![])
|
||||
}
|
||||
|
||||
pub fn start(&mut self) {
|
||||
|
@ -164,7 +170,7 @@ mod tests {
|
|||
let mut env = HashMap::new();
|
||||
env.insert("REX2TEST".to_string(), "Lorem ipsum dolor".to_string());
|
||||
let mut runner = Runner::new(
|
||||
env,
|
||||
Some(env),
|
||||
"bash".into(),
|
||||
vec!["-c".into(), "echo \"REX2TEST: $REX2TEST\"".into()],
|
||||
);
|
||||
|
@ -182,7 +188,7 @@ mod tests {
|
|||
#[test]
|
||||
fn can_save_log() {
|
||||
let mut runner = Runner::new(
|
||||
HashMap::new(),
|
||||
None,
|
||||
"bash".into(),
|
||||
vec!["-c".into(), "echo \"Lorem ipsum dolor sit amet\"".into()],
|
||||
);
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use super::{styles::bordered_container::BorderedContainer, widgets::widgets::hspacer};
|
||||
use crate::{
|
||||
builders::build_monado::get_build_monado_runner,
|
||||
config::{get_config, save_config, Config},
|
||||
constants::APP_NAME,
|
||||
profile::{load_profile, Profile},
|
||||
profile::{self, load_profile, Profile},
|
||||
profiles::valve_index::valve_index_profile,
|
||||
runner::{Runner, RunnerStatus},
|
||||
ui::widgets::widgets::vseparator,
|
||||
};
|
||||
|
@ -13,6 +15,7 @@ use iced::{
|
|||
widget::{button, checkbox, column, container, pick_list, row, scrollable, text, text_input},
|
||||
Alignment, Application, Command, Element, Length, Padding, Subscription, Theme,
|
||||
};
|
||||
use iced_aw::{Card, Modal};
|
||||
use std::{
|
||||
cell::Cell,
|
||||
time::{Duration, Instant},
|
||||
|
@ -25,6 +28,9 @@ pub struct MainWin {
|
|||
monado_runner: Cell<Runner>,
|
||||
monado_active: bool,
|
||||
monado_log: String,
|
||||
build_monado_runner: Option<Runner>,
|
||||
show_build_monado_modal: bool,
|
||||
build_monado_log: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -38,6 +44,8 @@ pub enum Message {
|
|||
LogLevelChanged(String),
|
||||
DebugSearchChanged(String),
|
||||
LogUpdate(Instant),
|
||||
InstallMonado,
|
||||
CloseBuildMonadoModal,
|
||||
}
|
||||
|
||||
impl MainWin {
|
||||
|
@ -71,6 +79,20 @@ impl MainWin {
|
|||
RunnerStatus::Stopped => "Monado service inactive".into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn install_monado(&mut self) {
|
||||
self.build_monado_log = String::new();
|
||||
let profile = match self.get_selected_profile() {
|
||||
None => {
|
||||
return;
|
||||
}
|
||||
Some(p) => p,
|
||||
};
|
||||
self.build_monado_runner = Some(get_build_monado_runner(profile.clone()));
|
||||
self.build_monado_runner.as_mut().unwrap().start();
|
||||
self.show_build_monado_modal = true;
|
||||
self.build_monado_log = self.build_monado_runner.as_mut().unwrap().get_output();
|
||||
}
|
||||
}
|
||||
|
||||
impl Application for MainWin {
|
||||
|
@ -80,7 +102,7 @@ impl Application for MainWin {
|
|||
type Theme = Theme;
|
||||
|
||||
fn new(_flags: Self::Flags) -> (Self, Command<Message>) {
|
||||
let profiles = vec![load_profile(&"./test/files/profile.json".to_string()).unwrap()];
|
||||
let profiles = vec![valve_index_profile()];
|
||||
let monado_runner = Cell::new(Runner::monado_runner_from_profile(
|
||||
profiles.get(0).cloned().unwrap(),
|
||||
));
|
||||
|
@ -93,6 +115,9 @@ impl Application for MainWin {
|
|||
monado_runner,
|
||||
monado_active: false,
|
||||
monado_log: "".into(),
|
||||
build_monado_runner: None,
|
||||
show_build_monado_modal: false,
|
||||
build_monado_log: String::new(),
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
|
@ -124,12 +149,37 @@ impl Application for MainWin {
|
|||
save_config(&self.config);
|
||||
}
|
||||
Message::DebugSearchChanged(term) => self.debug_search_term = term,
|
||||
Message::InstallMonado => {
|
||||
self.install_monado();
|
||||
}
|
||||
Message::CloseBuildMonadoModal => match &mut self.build_monado_runner {
|
||||
None => {
|
||||
self.show_build_monado_modal = false;
|
||||
}
|
||||
Some(runner) => match runner.status() {
|
||||
RunnerStatus::Running => {}
|
||||
RunnerStatus::Stopped => {
|
||||
self.show_build_monado_modal = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
Message::LogUpdate(_) => {
|
||||
self.monado_active = match self.monado_runner.get_mut().status() {
|
||||
RunnerStatus::Running => true,
|
||||
RunnerStatus::Stopped => false,
|
||||
};
|
||||
self.get_monado_log();
|
||||
if self.show_build_monado_modal {
|
||||
match &mut self.build_monado_runner {
|
||||
None => {}
|
||||
Some(runner) => match runner.status() {
|
||||
RunnerStatus::Running => {
|
||||
self.build_monado_log = runner.get_output();
|
||||
}
|
||||
RunnerStatus::Stopped => {}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => println!("unhandled"),
|
||||
};
|
||||
|
@ -206,7 +256,9 @@ impl Application for MainWin {
|
|||
false => button("Start").on_press(Message::Start),
|
||||
}
|
||||
.padding(Padding::from([6, 24])),
|
||||
scrollable(column![]) // device info goes here
|
||||
scrollable(column![
|
||||
button("DEBUG: install monado").on_press(Message::InstallMonado),
|
||||
]) // device info goes here
|
||||
]
|
||||
.height(Length::Fill)
|
||||
.padding(12)
|
||||
|
@ -216,7 +268,23 @@ impl Application for MainWin {
|
|||
.width(Length::FillPortion(1))
|
||||
.height(Length::Fill);
|
||||
|
||||
row![main_view, debug_view,].into()
|
||||
let win_content = row![main_view, debug_view,];
|
||||
|
||||
Modal::new(self.show_build_monado_modal, win_content, || {
|
||||
Card::new(
|
||||
text("Installing Monado..."),
|
||||
column![
|
||||
scrollable(text(self.build_monado_log.clone())),
|
||||
]
|
||||
.spacing(12),
|
||||
).foot(row![
|
||||
button("Close").on_press(Message::CloseBuildMonadoModal),
|
||||
])
|
||||
.max_width(600.0)
|
||||
.max_height(400.0)
|
||||
.into()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
||||
fn theme(&self) -> Self::Theme {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue