feat: better software page

This commit is contained in:
Ilya Zlobintsev
2023-01-07 20:50:59 +02:00
parent 6b8a7fd74b
commit e98e0e06cc
7 changed files with 72 additions and 93 deletions

5
Cargo.lock generated
View File

@@ -774,14 +774,9 @@ version = "0.2.0"
dependencies = [
"anyhow",
"gtk4",
"indexmap",
"lact-client",
"lact-daemon",
"nix",
"once_cell",
"serde",
"serde_json",
"tokio",
"tracing",
"tracing-subscriber",
]

View File

@@ -7,7 +7,7 @@ use anyhow::{anyhow, Context};
use nix::unistd::getuid;
use schema::{
ClocksInfo, DeviceInfo, DeviceListEntry, DeviceStats, FanCurveMap, PerformanceLevel, Request,
Response,
Response, SystemInfo,
};
use serde::Deserialize;
use std::{
@@ -86,6 +86,7 @@ impl DaemonClient {
self.make_request(Request::SetPowerCap { id, cap })?.inner()
}
request_plain!(get_system_info, SystemInfo, SystemInfo);
request_with_id!(get_device_info, DeviceInfo, DeviceInfo);
request_with_id!(get_device_stats, DeviceStats, DeviceStats);
request_with_id!(get_device_clocks_info, DeviceClocksInfo, ClocksInfo);

View File

@@ -5,3 +5,11 @@ macro_rules! request_with_id {
}
};
}
macro_rules! request_plain {
($name:ident, $variant:ident, $response:ty) => {
pub fn $name(&self) -> anyhow::Result<ResponseBuffer<$response>> {
self.make_request(Request::$variant)
}
};
}

View File

@@ -9,12 +9,6 @@ lact-client = { path = "../lact-client" }
lact-daemon = { path = "../lact-daemon" }
gtk = { version = "0.5", package = "gtk4" }
once_cell = "1.17.0"
# pango = "0.16"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
nix = "0.26"
anyhow = "1.0"
serde_json = "1.0"
serde = "1.0"
indexmap = "1.9.2"
tokio = { version = "1", features = ["net"] }

View File

@@ -48,7 +48,11 @@ impl App {
// Inhibit(false)
// });
let root_stack = RootStack::new(daemon_client.embedded);
let system_info_buf = daemon_client
.get_system_info()
.expect("Could not fetch system info");
let system_info = system_info_buf.inner().expect("Invalid system info buffer");
let root_stack = RootStack::new(system_info, daemon_client.embedded);
header.set_switcher_stack(&root_stack.container);

View File

@@ -5,9 +5,10 @@ mod thermals_page;
use gtk::*;
use self::software_page::software_page;
use info_page::InformationPage;
use lact_client::schema::SystemInfo;
use oc_page::OcPage;
use software_page::SoftwarePage;
use thermals_page::ThermalsPage;
#[derive(Clone)]
@@ -15,12 +16,11 @@ pub struct RootStack {
pub container: Stack,
pub info_page: InformationPage,
pub thermals_page: ThermalsPage,
pub software_page: SoftwarePage,
pub oc_page: OcPage,
}
impl RootStack {
pub fn new(embedded_daemon: bool) -> Self {
pub fn new(system_info: SystemInfo, embedded_daemon: bool) -> Self {
let container = Stack::builder().vexpand(true).build();
let info_page = InformationPage::new();
@@ -35,16 +35,14 @@ impl RootStack {
container.add_titled(&thermals_page.container, Some("thermals_page"), "Thermals");
let software_page = SoftwarePage::new(embedded_daemon);
container.add_titled(&software_page.container, Some("software_page"), "Software");
let software_page = software_page(system_info, embedded_daemon);
container.add_titled(&software_page, Some("software_page"), "Software");
Self {
container,
info_page,
thermals_page,
oc_page,
software_page,
}
}
}

View File

@@ -1,82 +1,61 @@
use gtk::prelude::*;
use gtk::*;
use std::process::Command;
use lact_client::schema::SystemInfo;
#[derive(Debug, Clone)]
pub struct SoftwarePage {
pub container: Grid,
}
pub fn software_page(system_info: SystemInfo, embedded: bool) -> Grid {
let container = Grid::new();
impl SoftwarePage {
pub fn new(embedded_daemon: bool) -> Self {
let container = Grid::new();
container.set_margin_start(5);
container.set_margin_end(5);
container.set_margin_bottom(5);
container.set_margin_top(5);
container.set_margin_start(5);
container.set_margin_end(5);
container.set_margin_bottom(5);
container.set_margin_top(5);
container.set_column_spacing(5);
container.set_column_spacing(5);
container.attach(
&{
let label = Label::new(None);
label.set_markup("LACT Version:");
label.set_halign(Align::End);
label.set_hexpand(true);
label
},
0,
0,
1,
1,
);
let lact_version_label = Label::new(None);
let lact_version = env!("CARGO_PKG_VERSION");
let lact_release_type = match cfg!(debug_assertions) {
true => "debug",
false => "release",
};
let mut version_text = format!("{lact_version}-{lact_release_type}");
if embedded_daemon {
version_text.push_str(" (embedded)");
}
lact_version_label.set_markup(&format!("<b>{version_text}</b>"));
lact_version_label.set_hexpand(true);
lact_version_label.set_halign(Align::Start);
container.attach(&lact_version_label, 1, 0, 1, 1);
container.attach(
&Label::builder()
.label("Kernel version:")
.halign(Align::End)
.hexpand(true)
.build(),
0,
1,
1,
1,
);
let kernel_version_label = Label::builder()
.use_markup(true)
.label(&format!("<b>{}</b>", get_kernel_version().trim()))
.hexpand(true)
.halign(Align::Start)
.build();
container.attach(&kernel_version_label, 1, 1, 1, 1);
Self { container }
container.attach(
&{
let label = Label::new(None);
label.set_markup("LACT Daemon:");
label.set_halign(Align::End);
label.set_hexpand(true);
label
},
0,
0,
1,
1,
);
let mut daemon_version = format!("{}-{}", system_info.version, system_info.profile);
if embedded {
daemon_version.push_str("-embedded");
}
}
let version_label = Label::builder()
.use_markup(true)
.label(&format!("<b>{daemon_version}</b>"))
.hexpand(true)
.halign(Align::Start)
.build();
fn get_kernel_version() -> String {
let output = Command::new("uname")
.arg("-r")
.output()
.expect("Could not run uname");
String::from_utf8(output.stdout).expect("Invalid uname output")
container.attach(&version_label, 1, 0, 1, 1);
container.attach(
&Label::builder()
.label("Kernel version:")
.halign(Align::End)
.hexpand(true)
.build(),
0,
1,
1,
1,
);
let kernel_version_label = Label::builder()
.use_markup(true)
.label(&format!("<b>{}</b>", system_info.kernel_version))
.hexpand(true)
.halign(Align::Start)
.build();
container.attach(&kernel_version_label, 1, 1, 1, 1);
container
}