diff --git a/i18n/en/examine.ftl b/i18n/en/examine.ftl index e094ad5..08f59a8 100644 --- a/i18n/en/examine.ftl +++ b/i18n/en/examine.ftl @@ -5,6 +5,7 @@ git-description = Git commit {$hash} on {$date} view = View no-page = Select a Page distribution = Distribution +motherboard = Motherboard processor = Processor pci-devices = PCIs usb-devices = USBs diff --git a/src/app.rs b/src/app.rs index 9af32be..4c13af2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -23,6 +23,7 @@ pub struct AppModel { nav: nav_bar::Model, key_binds: HashMap, config: Config, + hostnamectl: Option, lscpu: Option, lspci: Option, lsusb: Option, @@ -62,6 +63,12 @@ impl Application for AppModel { .icon(icon::from_name("applications-system-symbolic")) .activate(); + nav.insert() + .text(fl!("motherboard")) + .data::(Page::Motherboard) + .icon(icon::from_name("applications-system-symbolic")) + .activate(); + nav.insert() .text(fl!("processor")) .data::(Page::Processor) @@ -88,11 +95,20 @@ impl Application for AppModel { Err((_errors, config)) => config, }) .unwrap_or_default(), + hostnamectl: None, lscpu: None, lspci: None, lsusb: None, }; + let hostnamectl_cmd = std::process::Command::new("hostnamectl").output(); + if hostnamectl_cmd.is_ok() { + app.hostnamectl = Some(String::from_utf8(hostnamectl_cmd.unwrap().stdout).unwrap()); + } else if let Err(e) = hostnamectl_cmd { + app.hostnamectl = Some(fl!("error-occurred-with-msg", error = e.to_string())); + error!("hostnamectl command failed: {}", e); + } + let lscpu_cmd = std::process::Command::new("lscpu").output(); if lscpu_cmd.is_ok() { app.lscpu = Some(String::from_utf8(lscpu_cmd.unwrap().stdout).unwrap()); @@ -355,6 +371,33 @@ impl Application for AppModel { .height(Length::Fill) .into() } + Some(Page::Motherboard) => { + let Some(hostnamectl) = &self.hostnamectl else { + return widget::text::title1(fl!("error-occurred")).into(); + }; + + if let Some(hostnamectl_str) = &self.hostnamectl { + if hostnamectl_str.starts_with(fl!("error-occurred").as_str()) { + return widget::text::title1(hostnamectl_str).into(); + } else { + let hostnamectl = hostnamectl + .lines() + .map(|line: &str| { + let (prefix, suffix) = line.split_once(':').unwrap(); + settings::item(prefix.trim(), widget::text::body(suffix)).into() + }) + .collect::>>(); + + let mut section = list_column(); + for item in hostnamectl { + section = section.add(item); + } + return section.apply(widget::scrollable).into() + } + } else { + return widget::text::title1(fl!("error-occurred")).into(); + } + } Some(Page::Processor) => { let Some(lscpu) = &self.lscpu else { return widget::text::title1(fl!("error-occurred")).into(); @@ -548,6 +591,7 @@ impl AppModel { /// The page to display in the application. pub enum Page { Distribution, + Motherboard, Processor, PCIs, USBs,