Skip to content

Conversation

themg95
Copy link

@themg95 themg95 commented Sep 11, 2025

Changes:

  • Added CPU and Memory usage modules.
  • Added ButtonType enum and made the code rely on it instead of ButtonImage

Caveats:

  • Both use the same icon since MDI doesn't have different computer part icons
  • I'm pretty new to Rust, so my code might suck

Copy link
Collaborator

@WhatAmISupposedToPutHere WhatAmISupposedToPutHere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding new features, please document them by providing examples in the template config file. Also, missing sign-off

}
}
ButtonType::Memory(memory_mode) => {
let memory_usage = get_memory_usage();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make a common function for "button with percentage and optional icon", there seems to be a lot of duplication for Battery/Memory/Cpu


fn new_memory(action: Key, memory_mode: String, theme: Option<impl AsRef<str>>) -> Button {
let image = Self::load_image("memory", theme.as_ref());
let memory_mode = match memory_mode.as_str() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common parser for all of them? also all panic messages refer to battery

}

fn new_memory(action: Key, memory_mode: String, theme: Option<impl AsRef<str>>) -> Button {
let image = Self::load_image("memory", theme.as_ref());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using the "memory" icon for cpu, and "memory alt" for memory?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find a memory alt icon in material design icons

Copy link
Collaborator

freedesktop-icons = "0.4.0"
chrono = { version = "0.4", features = ["unstable-locales"] }
udev = "0.9"
sysinfo = "0.36.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are linux-only, and this is not expected to change ever, so why not just read /proc directly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that would take extra work, especially for the CPU, but I could do that

fn get_cpu_usage() -> u32 {
let mut s = System::new();
s.refresh_cpu_usage();
std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably will be changed for other reasons, but in general - absolutely not. The app is structured around an event loop, and you should not do blocking sleeps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants