every file
This commit is contained in:
commit
54d0046c88
38
main.go
Normal file
38
main.go
Normal file
@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/0xAX/notificator"
|
||||
"github.com/distatus/battery"
|
||||
"time"
|
||||
)
|
||||
|
||||
var notify *notificator.Notificator
|
||||
|
||||
func main() {
|
||||
warning := false
|
||||
for {
|
||||
battery, er := battery.Get(0)
|
||||
if er != nil {
|
||||
fmt.Println(er)
|
||||
continue
|
||||
}
|
||||
|
||||
percentage := battery.Current / battery.Full * 100
|
||||
if !warning && percentage <= 15 && string(battery.State) != "Charging" {
|
||||
warning = true
|
||||
notify = notificator.New(notificator.Options{
|
||||
DefaultIcon: "/home/trac/Go/src/github.com/0xAX/notificatior/icon/golang.png",
|
||||
AppName: "Low Battery",
|
||||
})
|
||||
|
||||
err := notify.Push("Battery LOW", "Plug in a charger", "/home/trac/Go/src/github.com/0xAX/notificator/icon/golang.png", notificator.UR_CRITICAL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else if percentage > 15 || string(battery.State) == "Charging" {
|
||||
warning = true
|
||||
}
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user