Macchina-CLI / macchina

A system information frontend with an emphasis on performance.
https://crates.io/crates/macchina
MIT License
1.41k stars 51 forks source link

Does Macchina support two batteries? #295

Open mohabmetwalli opened 1 year ago

mohabmetwalli commented 1 year ago

I wasn't sure if I should open this issue as a bug or a feature request, so I thought I should ask this question first.

My laptop has two batteries, and I suspect this is the reason macchina cannot read battery percentage.

macchina --doctor output:

Let's check your system for errors... Here's a summary:

We've collected 9 readouts, including 1 failed read(s) and 0 read(s) which resulted in a warning.
Readout "Battery" failed with message: No such file or directory (os error 2)

ls /sys/class/power_supply --all output:

.  ..  AC  BAT0  BAT1  ucsi-source-psy-USBC000:001  ucsi-source-psy-USBC000:002
grtcdr commented 1 year ago

Hi.

It can't. I don't really know how to tackle this problem, either. I also don't have the hardware to try and write an implementation. It would be very appreciated if you or others alike could give us a hand with this problem.

FantasyTeddy commented 4 months ago

Even if multiple batteries are present, shouldn't macchina just report the status of the first one?

@mohabmetwalli: Can you show the directory listing of /sys/class/power_supply/BAT0?

grtcdr commented 4 months ago

Even if multiple batteries are present, shouldn't macchina just report the status of the first one?

Yes, indeed. I'll see what I can do to fix this. Adding support for this could prove to be a lot of work in libmacchina — dual-battery friends, if you really want to see support for multi-battery reports, please contribute your patches to libmacchina seeing as I don't have the hardware to do any meaningful tests.

naguam commented 3 weeks ago

Hi,

Regarding batteries, this library might be helpful,

https://crates.io/crates/starship-battery

It has one API which lists batteries and their info and works with most major operating systems (including NetBSD thanks to my port) except OpenBSD for now. (I wanted to do it but the Rust ecosystem was broken on OpenBSD when I tried and I did not want to fight with segfaults and resource over use / stalls with the LSP).

If I make this proposal despite macchina having already some battery reading features is because, this library basically provide an iterator with all available batteries + update methods, and this would ease the process of reading multiple batteries on any operating system with a single implementation on macchina's side.

The example directory in that library shows how to use the library, iterate over batteries and so on.

grtcdr commented 3 weeks ago

When we fetch things, we like to call libmacchina, that's the only backend we wish to use. So it would be best if we wrote our own implementation, we're already borrowing quite a few things from other libraries in libmacchina and I don't like that we do that.

naguam commented 3 weeks ago

It was just a proposal to make things simpler and use the systems' APIs instead of running shell commands. (At least in the netbsd's case).

To be fair it would not make sense to make a rewrite at it would mostly be about making a clone. The entire library's purpose is to provide battery info, and nothing else. It's not a "do it all" library.

And of course it would be used in libmacchina, I though this repo and issue feed was for the project overall.