blob: d4593ff8103d8dcdbc7af14c7c757420e776291a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package modules
import (
"io/ioutil"
)
// TODO: Move this to a central spot, like a config.h
const (
batteryPath = "/sys/class/power_supply/BAT0/capacity"
)
// BatteryModule is the module that controls finding out the battery
// percentage, mainly useful in laptops
type BatteryModule struct {
}
func (_ BatteryModule) GetInfo() (string, error) {
return readBatteryLevel(batteryPath)
}
func readBatteryLevel(path string) (string, error) {
dat, err := ioutil.ReadFile(path)
if err != nil {
return "NULL", err
}
return (string(dat[:len(dat)-1]) + "%"), nil
}
|