-
Notifications
You must be signed in to change notification settings - Fork 36
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
implement upower module #83
Conversation
@JakeStanger pinging you because I don't think you get notified of draft prs |
I do get notified actually :)
I appreciate that's fairly involved, so give me a heads up if you get stuck - super appreciate you taking this on |
The name of the icon is an actual icon in adwaita so I wanted to just pick that icon instead of making it configurable, this is what waybar does as well |
Ah okay, that's handy. I think most of the above still applies. You can use |
Is there anything blocking the merge of this? If help is needed, I can help out. I would love to see this in ironbar! |
@yavko I can't get icons to work |
Feel free to push your latest version up (might be wise to rebase onto master to get the latest changes) and I can have a look :) |
The conflict is in Cargo.lock which I'm not sure how to handle, I haven't worked on this after the last push |
So long as the cargo.toml is fine, you can do whatever with the merge, then just delete cargo.lock and regen to ensure it generates a new valid lock. I'm not sure if that's necessarily best practise but it's the easy way lol - I'll just double check it when we get to review stage. |
@JakeStanger done |
oh sorry it doesn't compile |
fixed it |
Now I'm looking at it, using What you should able to do here instead is create an image widget and add it to your container: let icon = gtk::Image::new();
// ...set up/add widget... Then inside your callback where you get the icon name, you can pass it (still in the if let Err(err) = ImageProvider::parse(input, icon_theme, size)
.and_then(|provider| provider.load_into_image(icon) {
error!("{err:?}");
} I'd advise caching the previous icon name to avoid re-loading the same image over and over, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the work so far, it's really appreciated. This is looking generally very good so far :)
Most of the bits I've raised are trivial pedantic bits, but there's a couple of more complex issues so do let me know if you need a hand with any of those.
The build is failing currently due to compiler errors when --no-default-features
is set. One of the reasons is because regex
is behind a feature flag, but it looks like that's not actually needed here anyway. The other is due to the incomplete icon code, so that should resolve itself in time.
I don't have a device with a battery that I can test this against, but on my desktop the correct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more little bits, but looking like it's nearly there! Let me know when you've got these, and the few changes leftover from yesterday sorted, thanks!
should i retry if connecting to the system bus (or anything in the dbus initialization portion) fails? |
the icon was fine, it was just black on black. |
I don't think so. I think if DBus ever fails to connect, that's a much greater problem that retrying probably won't fix, so the best action is probably to just log the error and exit (expect is probably fine in that case) |
src/modules/upower.rs
Outdated
|
||
rx.attach(None, move |properties| { | ||
let mut format = String::new(); | ||
let state: BatteryState = u32_to_batterystate(properties.state).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace this unwrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of tiny bits left, then I think it's just about there :)
I just wanted to comment, I see you are using the icon from fn get_icon_name(status: BatteryState, capacity: u64) -> String {
let suffix = if status == BatteryState::Charging {
"-charging"
} else {
""
};
let cap: u8 = match capacity {
0..=9 => 0,
10..=19 => 10,
20..=29 => 20,
30..=39 => 30,
40..=49 => 40,
50..=59 => 50,
60..=69 => 60,
70..=79 => 70,
80..=89 => 80,
90..=99 => 90,
100 => 100,
_ => 0,
};
format!("battery-level-{cap}{suffix}-symbolic")
} |
@p00f Thanks for all your work. I'm gonna complete the last few bits & add the docs, then get this merged. @yavko That sounds good to me. I'll merge the current implementation for now, but if you want to follow up with a PR that adds your icon method, falling back to the upower icon if it's not present in the theme, that would be fantastic (if not that's cool too ofc, I'll add it to the todo list) |
There are a couple of issues:
I want to use the popup to show additional details like time to empty/full and battery levels of other connected devices like bluetooth headphones. I've hardcoded the function for now but nothing happens when I click the module
upower will tell me what icon to use depending on battery level and whether it is plugged in, how do I implement this? I did
format: "icon:{icon} {percentage}%"
in config.yaml but that doesn't seem to workBroadly it seems to work fine