From 1057e4854355a0ddac83c3de7b1506293b28fc4d Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Tue, 8 Oct 2024 09:12:05 -0600 Subject: [PATCH 1/3] init work --- i18n/en/examine.ftl | 1 + src/app.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) 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 437e1e5..d1853d7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,6 +5,7 @@ use crate::fl; use cosmic::app::{Command, Core}; use cosmic::cosmic_config::{self, CosmicConfigEntry}; use cosmic::iced::{Alignment, Length, Subscription}; +use cosmic::iced_winit::winit::window::WindowId; use cosmic::widget::{self, icon, list_column, menu, nav_bar, row, settings}; use cosmic::{cosmic_theme, theme, Application, ApplicationExt, Apply, Element}; use etc_os_release::OsRelease; @@ -23,6 +24,7 @@ pub struct AppModel { nav: nav_bar::Model, key_binds: HashMap, config: Config, + dmidecode: Option, lscpu: Option, lspci: Option, lsusb: Option, @@ -62,6 +64,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 +96,20 @@ impl Application for AppModel { Err((_errors, config)) => config, }) .unwrap_or_default(), + dmidecode: None, lscpu: None, lspci: None, lsusb: None, }; + let dmidecode_cmd = std::process::Command::new("dmidecode -t baseboard").output(); + if dmidecode_cmd.is_ok() { + app.dmidecode = Some(String::from_utf8(dmidecode_cmd.unwrap().stdout).unwrap()); + } else if let Err(e) = dmidecode_cmd { + app.dmidecode = Some(fl!("error-occurred-with-msg", error = e.to_string())); + error!("dmidecode 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 +372,33 @@ impl Application for AppModel { .height(Length::Fill) .into() } + Some(Page::Motherboard) => { + let Some(dmidecode) = &self.dmidecode else { + return widget::text::title1(fl!("error-occurred")).into(); + }; + + if let Some(dmidecode_str) = &self.dmidecode { + if dmidecode_str.starts_with(fl!("error-occurred").as_str()) { + return widget::text::title1(dmidecode_str).into(); + } else { + let dmidecode = dmidecode + .lines() + .map(|line: &str| { + let (prefix, suffix) = line.split_once(':').unwrap(); + settings::item(prefix, widget::text::body(suffix)).into() + }) + .collect::>>(); + + let mut section = list_column(); + for item in dmidecode { + 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(); @@ -549,6 +593,7 @@ impl AppModel { /// The page to display in the application. pub enum Page { Distribution, + Motherboard, Processor, PCIs, USBs, From 83df52dd33962406db75ebccda05e04d4e6fa136 Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Sat, 2 Nov 2024 20:33:02 -0600 Subject: [PATCH 2/3] swap to hostnamectl from dmidecode --- src/app.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/app.rs b/src/app.rs index 92752df..bff96f5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -23,7 +23,7 @@ pub struct AppModel { nav: nav_bar::Model, key_binds: HashMap, config: Config, - dmidecode: Option, + hostnamectl: Option, lscpu: Option, lspci: Option, lsusb: Option, @@ -95,18 +95,18 @@ impl Application for AppModel { Err((_errors, config)) => config, }) .unwrap_or_default(), - dmidecode: None, + hostnamectl: None, lscpu: None, lspci: None, lsusb: None, }; - let dmidecode_cmd = std::process::Command::new("dmidecode -t baseboard").output(); - if dmidecode_cmd.is_ok() { - app.dmidecode = Some(String::from_utf8(dmidecode_cmd.unwrap().stdout).unwrap()); - } else if let Err(e) = dmidecode_cmd { - app.dmidecode = Some(fl!("error-occurred-with-msg", error = e.to_string())); - error!("dmidecode command failed: {}", e); + 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(); @@ -372,15 +372,15 @@ impl Application for AppModel { .into() } Some(Page::Motherboard) => { - let Some(dmidecode) = &self.dmidecode else { + let Some(hostnamectl) = &self.hostnamectl else { return widget::text::title1(fl!("error-occurred")).into(); }; - if let Some(dmidecode_str) = &self.dmidecode { - if dmidecode_str.starts_with(fl!("error-occurred").as_str()) { - return widget::text::title1(dmidecode_str).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 dmidecode = dmidecode + let hostnamectl = hostnamectl .lines() .map(|line: &str| { let (prefix, suffix) = line.split_once(':').unwrap(); @@ -389,7 +389,7 @@ impl Application for AppModel { .collect::>>(); let mut section = list_column(); - for item in dmidecode { + for item in hostnamectl { section = section.add(item); } return section.apply(widget::scrollable).into() From 60339a2128e4b5ef8caa21824ae8524200362e24 Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Sun, 3 Nov 2024 08:15:45 -0700 Subject: [PATCH 3/3] Update src/app.rs Co-authored-by: Dexter Reed --- src/app.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index bff96f5..4c13af2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -384,7 +384,7 @@ impl Application for AppModel { .lines() .map(|line: &str| { let (prefix, suffix) = line.split_once(':').unwrap(); - settings::item(prefix, widget::text::body(suffix)).into() + settings::item(prefix.trim(), widget::text::body(suffix)).into() }) .collect::>>();