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

Add BatteryStatus #4172

Open
Uzlopak opened this issue Oct 18, 2023 · 8 comments
Open

Add BatteryStatus #4172

Uzlopak opened this issue Oct 18, 2023 · 8 comments

Comments

@Uzlopak
Copy link

Uzlopak commented Oct 18, 2023

Well. How about providing the battery status, as described in mdn for navigator.getBattery()
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getBattery

Win:
https://learn.microsoft.com/en-us/windows/win32/power/battery-information

Mac:
https://developer.apple.com/documentation/iokit/iopowersources_h#topics

Linux:
Read the status from /sys/class/power_supply/

@bnoordhuis
Copy link
Member

I guess? PR welcome.

macOS note: IOKit.framework should be loaded dynamically with dlopen, not linked against with -framework IOKit. See src/unix/darwin-proctitle.c for an example how to.

@juanarbol
Copy link
Contributor

I can work on the macOS part :)

@juanarbol
Copy link
Contributor

I can work on the linux for arm64, as well but I need a bit more time for it :)

@oluan
Copy link
Contributor

oluan commented Dec 24, 2023

I can work on Windows implementation soon

@juanarbol To ensure we're aligned, could you specify the features you're working on?

I've seen your PR and I'll use it to start my branch.

Specifically, are you planning to implement the BatteryManager browser interface as outlined here:

https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager ?

@juanarbol
Copy link
Contributor

Yes, once we have everything landed in libuv, I can implement the battery thing in Node.js

juanarbol added a commit to juanarbol/libuv that referenced this issue Jan 17, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Jan 17, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Jan 17, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Jan 17, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Jan 17, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
@juanarbol
Copy link
Contributor

Are we sure about Linux? I tried reading from the power_supply folder, empty from a Raspberry Pi and from a AWS machine as well:

ubuntu@ip-172-31-11-139:~$ cat /sys/class/power_supply/
cat: /sys/class/power_supply/: Is a directory
ubuntu@ip-172-31-11-139:~$ cat /sys/class/power_supply/
cat: /sys/class/power_supply/: Is a directory
ubuntu@ip-172-31-11-139:~$ ls /sys/class/power_supply/
ubuntu@ip-172-31-11-139:~$ uname -a
Linux ip-172-31-11-139 6.2.0-1017-aws #17~22.04.1-Ubuntu SMP Fri Nov 17 21:07:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

@Uzlopak
Copy link
Author

Uzlopak commented Jan 17, 2024

aras@aras-Lenovo-Legion-5-17ARH05H:~$ cat /sys/class/power_supply/BAT0/capacity
100

@juanarbol
Copy link
Contributor

That works on laptops; for servers, it is empty; the same happens with macOS, I will propose returning a UV_EPERM when no resources available

juanarbol added a commit to juanarbol/libuv that referenced this issue Jan 18, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Jan 21, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Jan 21, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Jan 21, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Feb 22, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Feb 22, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Feb 22, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
juanarbol added a commit to juanarbol/libuv that referenced this issue Feb 27, 2024
Refs: libuv#4172
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants