Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Mainboard page #14

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/en/examine.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct AppModel {
nav: nav_bar::Model,
key_binds: HashMap<menu::KeyBind, MenuAction>,
config: Config,
hostnamectl: Option<String>,
lscpu: Option<String>,
lspci: Option<String>,
lsusb: Option<String>,
Expand Down Expand Up @@ -62,6 +63,12 @@ impl Application for AppModel {
.icon(icon::from_name("applications-system-symbolic"))
.activate();

nav.insert()
.text(fl!("motherboard"))
.data::<Page>(Page::Motherboard)
.icon(icon::from_name("applications-system-symbolic"))
.activate();

nav.insert()
.text(fl!("processor"))
.data::<Page>(Page::Processor)
Expand All @@ -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());
Expand Down Expand Up @@ -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();
edfloreshz marked this conversation as resolved.
Show resolved Hide resolved
settings::item(prefix.trim(), widget::text::body(suffix)).into()
})
.collect::<Vec<Element<Message>>>();

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();
Expand Down Expand Up @@ -548,6 +591,7 @@ impl AppModel {
/// The page to display in the application.
pub enum Page {
Distribution,
Motherboard,
Processor,
PCIs,
USBs,
Expand Down