forked from retoor/devplacepy
20 lines
350 B
Go
20 lines
350 B
Go
//go:build darwin
|
|||
|
|
|
||
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"os/exec"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
func systemBattery() (bool, error) {
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
out, err := exec.CommandContext(ctx, "pmset", "-g", "batt").Output()
|
||
|
|
if err != nil {
|
||
|
|
return false, err
|
||
|
|
}
|
||
|
|
return parsePmset(string(out)), nil
|
||
|
|
}
|