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 1 commit
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
45 changes: 45 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,7 @@ pub struct AppModel {
nav: nav_bar::Model,
key_binds: HashMap<menu::KeyBind, MenuAction>,
config: Config,
dmidecode: Option<String>,
lscpu: Option<String>,
lspci: Option<String>,
lsusb: Option<String>,
Expand Down Expand Up @@ -62,6 +64,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 +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();
edfloreshz marked this conversation as resolved.
Show resolved Hide resolved
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());
Expand Down Expand Up @@ -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();
edfloreshz marked this conversation as resolved.
Show resolved Hide resolved
settings::item(prefix, widget::text::body(suffix)).into()
ahoneybun marked this conversation as resolved.
Show resolved Hide resolved
})
.collect::<Vec<Element<Message>>>();

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