forked from ptrcnull/bat-alert
Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
|
d230d84e91 | ||
|
cc129b9387 |
2 changed files with 4 additions and 3 deletions
6
main.go
6
main.go
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func notify(msg string) {
|
func notify(msg string) {
|
||||||
cmd := exec.Command("notify-send", "-t", "5000", "bat-alert", msg)
|
cmd := exec.Command("notify-send", "-t", "5000", "-u", "critical", "bat-alert", msg)
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
@ -20,6 +20,8 @@ func notify(msg string) {
|
||||||
|
|
||||||
var targetFlag = flag.Int("target", 15, "when to send the alert")
|
var targetFlag = flag.Int("target", 15, "when to send the alert")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
sent := false
|
sent := false
|
||||||
for {
|
for {
|
||||||
capacity, err := os.ReadFile("/sys/class/power_supply/BAT0/capacity")
|
capacity, err := os.ReadFile("/sys/class/power_supply/BAT0/capacity")
|
||||||
|
@ -32,7 +34,7 @@ var targetFlag = flag.Int("target", 15, "when to send the alert")
|
||||||
notify("error: " + err.Error())
|
notify("error: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if numCap < 15 {
|
if numCap <= *targetFlag {
|
||||||
if !sent {
|
if !sent {
|
||||||
sent = true
|
sent = true
|
||||||
notify("battery running low!")
|
notify("battery running low!")
|
||||||
|
|
1
test.txt
1
test.txt
|
@ -1 +0,0 @@
|
||||||
|
|
Loading…
Reference in a new issue