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

feat: use relm4 #375

Merged
merged 10 commits into from
Sep 20, 2024
Prev Previous commit
feat: use relm for the software page
  • Loading branch information
ilya-zlobintsev committed Sep 20, 2024
commit ad6b120710e42570cdf2ec74a665cba20f24ec02
10 changes: 6 additions & 4 deletions lact-daemon/src/server/system.rs
Original file line number Diff line number Diff line change
@@ -14,13 +14,15 @@ const PP_OVERDRIVE_MASK: u64 = 0x4000;
pub const PP_FEATURE_MASK_PATH: &str = "/sys/module/amdgpu/parameters/ppfeaturemask";
pub const MODULE_CONF_PATH: &str = "/etc/modprobe.d/99-amdgpu-overdrive.conf";

pub async fn info() -> anyhow::Result<SystemInfo<'static>> {
let version = env!("CARGO_PKG_VERSION");
pub async fn info() -> anyhow::Result<SystemInfo> {
let version = env!("CARGO_PKG_VERSION").to_owned();
let profile = if cfg!(debug_assertions) {
"debug"
} else {
"release"
};
}
.to_owned();

let kernel_output = Command::new("uname")
.arg("-r")
.output()
@@ -42,7 +44,7 @@ pub async fn info() -> anyhow::Result<SystemInfo<'static>> {
profile,
kernel_version,
amdgpu_overdrive_enabled,
commit: Some(GIT_COMMIT),
commit: Some(GIT_COMMIT.to_owned()),
})
}

8 changes: 8 additions & 0 deletions lact-gui/src/app/info_row.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,14 @@ impl InfoRow {
.property("value", value)
.build()
}

pub fn new_selectable(name: &str, value: &str) -> Self {
Object::builder()
.property("name", name)
.property("value", value)
.property("selectable", true)
.build()
}
}

mod imp {
4 changes: 2 additions & 2 deletions lact-gui/src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -96,8 +96,8 @@ impl Component for AppModel {
.expect("Could not list devices");
let devices = devices_buf.inner().expect("Could not access devices");

if system_info.version != GUI_VERSION || system_info.commit != Some(GIT_COMMIT) {
let err = anyhow!("Version mismatch between GUI and daemon ({GUI_VERSION}-{GIT_COMMIT} vs {}-{})! Make sure you have restarted the service if you have updated LACT.", system_info.version, system_info.commit.unwrap_or_default());
if system_info.version != GUI_VERSION || system_info.commit.as_deref() != Some(GIT_COMMIT) {
let err = anyhow!("Version mismatch between GUI and daemon ({GUI_VERSION}-{GIT_COMMIT} vs {}-{})! Make sure you have restarted the service if you have updated LACT.", system_info.version, system_info.commit.as_deref().unwrap_or_default());
sender.input(AppMsg::Error(err.into()));
}

8 changes: 6 additions & 2 deletions lact-gui/src/app/root_stack/mod.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ mod software_page;
mod thermals_page;

use gtk::{prelude::*, *};
use relm4::{Component, ComponentController};

use self::software_page::SoftwarePage;
use info_page::InformationPage;
@@ -41,8 +42,11 @@ impl RootStack {

container.add_titled(&thermals_page.container, Some("thermals_page"), "Thermals");

let software_page = SoftwarePage::new(system_info, embedded_daemon);
container.add_titled(&software_page, Some("software_page"), "Software");
let mut software_page = SoftwarePage::builder()
.launch((system_info, embedded_daemon))
.detach();
container.add_titled(software_page.widget(), Some("software_page"), "Software");
software_page.detach_runtime();

Self {
container,
99 changes: 34 additions & 65 deletions lact-gui/src/app/root_stack/software_page.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
use crate::GUI_VERSION;
use gtk::glib::{self, Object};
use crate::{app::info_row::InfoRow, GUI_VERSION};
use gtk::prelude::*;
use lact_client::schema::{SystemInfo, GIT_COMMIT};
use relm4::{ComponentParts, ComponentSender, SimpleComponent};
use std::fmt::Write;

glib::wrapper! {
pub struct SoftwarePage(ObjectSubclass<imp::SoftwarePage>)
@extends gtk::Box, gtk::Widget,
@implements gtk::Orientable, gtk::Accessible, gtk::Buildable;
}
pub struct SoftwarePage {}

#[relm4::component(pub)]
impl SimpleComponent for SoftwarePage {
type Init = (SystemInfo, bool);
type Input = ();
type Output = ();

view! {
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 10,
set_margin_start: 5,
set_margin_end: 5,
set_margin_top: 5,
set_margin_bottom: 5,

append = &InfoRow::new_selectable("LACT Daemon:", &daemon_version),
append = &InfoRow::new_selectable("LACT GUI:", &gui_version),
append = &InfoRow::new_selectable("Kernel Version:", &system_info.kernel_version),
}
}

fn init(
(system_info, embedded): Self::Init,
root: Self::Root,
_sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = Self {};

impl SoftwarePage {
pub fn new(system_info: SystemInfo, embedded: bool) -> Self {
let mut daemon_version = format!("{}-{}", system_info.version, system_info.profile);
if embedded {
daemon_version.push_str("-embedded");
@@ -26,62 +49,8 @@ impl SoftwarePage {
};
let gui_version = format!("{GUI_VERSION}-{gui_profile} (commit {GIT_COMMIT})");

Object::builder()
.property("daemon-version", daemon_version)
.property("gui-version", gui_version)
.property("kernel-version", system_info.kernel_version)
.build()
}
}

mod imp {
#![allow(clippy::enum_variant_names)]
use crate::app::{info_row::InfoRow, page_section::PageSection};
use glib::Properties;
use gtk::{
glib::{self, subclass::InitializingObject},
prelude::*,
subclass::{
prelude::*,
widget::{CompositeTemplateClass, WidgetImpl},
},
CompositeTemplate,
};
use std::cell::RefCell;

#[derive(CompositeTemplate, Default, Properties)]
#[properties(wrapper_type = super::SoftwarePage)]
#[template(file = "ui/software_page.blp")]
pub struct SoftwarePage {
#[property(get, set)]
daemon_version: RefCell<String>,
#[property(get, set)]
gui_version: RefCell<String>,
#[property(get, set)]
kernel_version: RefCell<String>,
}

#[glib::object_subclass]
impl ObjectSubclass for SoftwarePage {
const NAME: &'static str = "SoftwarePage";
type Type = super::SoftwarePage;
type ParentType = gtk::Box;

fn class_init(class: &mut Self::Class) {
InfoRow::ensure_type();
PageSection::ensure_type();

class.bind_template();
}
let widgets = view_output!();

fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template();
}
ComponentParts { model, widgets }
}

#[glib::derived_properties]
impl ObjectImpl for SoftwarePage {}

impl WidgetImpl for SoftwarePage {}
impl BoxImpl for SoftwarePage {}
}
28 changes: 0 additions & 28 deletions lact-gui/ui/software_page.blp

This file was deleted.

8 changes: 4 additions & 4 deletions lact-schema/src/lib.rs
Original file line number Diff line number Diff line change
@@ -59,10 +59,10 @@ pub fn default_fan_curve() -> FanCurveMap {
pub struct Pong;

#[derive(Serialize, Deserialize, Debug)]
pub struct SystemInfo<'a> {
pub version: &'a str,
pub commit: Option<&'a str>,
pub profile: &'a str,
pub struct SystemInfo {
pub version: String,
pub commit: Option<String>,
pub profile: String,
pub kernel_version: String,
pub amdgpu_overdrive_enabled: Option<bool>,
}
Loading