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