From 4e5e2c4d801978ab0c8e8453e1bc7bd14356bc19 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Thu, 8 Jun 2023 21:11:34 +0200 Subject: [PATCH] feat: can build monado from gui --- Cargo.toml | 2 +- src/builders/build_monado.rs | 12 ++++++ src/builders/mod.rs | 3 ++ src/main.rs | 1 + src/runner.rs | 18 ++++++--- src/ui/main_win.rs | 78 +++++++++++++++++++++++++++++++++--- 6 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 src/builders/build_monado.rs create mode 100644 src/builders/mod.rs diff --git a/Cargo.toml b/Cargo.toml index 436174c..e35f7a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = [ diff --git a/src/builders/build_monado.rs b/src/builders/build_monado.rs new file mode 100644 index 0000000..dd0f31a --- /dev/null +++ b/src/builders/build_monado.rs @@ -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 +} diff --git a/src/builders/mod.rs b/src/builders/mod.rs new file mode 100644 index 0000000..eca56f2 --- /dev/null +++ b/src/builders/mod.rs @@ -0,0 +1,3 @@ + +pub mod build_monado; + diff --git a/src/main.rs b/src/main.rs index f57115c..bc4bb2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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()); diff --git a/src/runner.rs b/src/runner.rs index 72b65ec..02b1f13 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -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, command: String, args: Vec) -> Self { + pub fn new(environment: Option>, command: String, args: Vec) -> 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()], ); diff --git a/src/ui/main_win.rs b/src/ui/main_win.rs index 349d915..1656319 100644 --- a/src/ui/main_win.rs +++ b/src/ui/main_win.rs @@ -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, monado_active: bool, monado_log: String, + build_monado_runner: Option, + 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) { - 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 {