diff --git a/mako/config b/mako/config index 7158cb5..795d88b 100644 --- a/mako/config +++ b/mako/config @@ -6,6 +6,6 @@ text-color=#d8dee9 border-color=#434c5e border-radius=7 max-icon-size=32 -default-timeout=0 +default-timeout=30000 anchor=top-right margin=20 diff --git a/waybar/config b/waybar/config index 11f5cc2..8ded0db 100644 --- a/waybar/config +++ b/waybar/config @@ -122,7 +122,7 @@ "format": " {}", "return-type": "json", "interval": 3600, // every 30 minutes - "exec": "~/.config/waybar/modules/update-check.sh", + "exec": "go run ~/.config/waybar/modules/update-check.go", "exec-if": "exit 0", "on-click": "~/.config/waybar/modules/update-system.sh; pkill -RTMIN+8 waybar", // update system "signal": 8, diff --git a/waybar/modules/update-check.go b/waybar/modules/update-check.go new file mode 100644 index 0000000..8ff87e2 --- /dev/null +++ b/waybar/modules/update-check.go @@ -0,0 +1,60 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + "os" + "os/exec" + "strings" +) + +type jsonOutput struct { + Text string `json:"text,omitempty"` + Alt string `json:"alt,omitempty"` + Tooltip string `json:"tooltip,omitempty"` + Class string `json:"class,omitempty"` + Percentage int `json:"percentage,omitempty"` +} + +func main() { + pac, err := exec.Command("checkupdates").CombinedOutput() + if err != nil { + log.Fatal("could not get pacman updates: ", string(pac)) + } + + aur, err := exec.Command("yay", "--devel", "-Qu").CombinedOutput() + if err != nil { + log.Fatal("could not get aur updates: ", string(aur)) + } + + updates := []string{} + for _, line := range strings.Split(string(pac), "\n") { + if len(line) > 0 { + updates = append(updates, line) + } + } + + for _, line := range strings.Split(string(aur), "\n") { + if len(line) > 0 { + updates = append(updates, line) + } + } + + n := len(updates) + + class := "no-updates" + if n > 0 { + class = "updates" + } + + o := jsonOutput{ + Text: fmt.Sprintf("%d", n), + Alt: fmt.Sprintf("%d", n), + Tooltip: strings.Join(updates, "\n"), + Class: class, + Percentage: n, + } + + json.NewEncoder(os.Stdout).Encode(o) +} diff --git a/waybar/modules/update-check.sh b/waybar/modules/update-check.sh deleted file mode 100755 index 7599f36..0000000 --- a/waybar/modules/update-check.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -aur_updates=$(yay --devel -Qqmu) -pac_updates=$(checkupdates | awk '{print $1}') -text=$(printf "${aur_updates}${pac_updates}" | wc -l) -alt=$text -tooltip=$(printf "${pac_updates}${aur_updates}" | sed ':a;N;$!ba;s/\n/\\n/g') -percentage=$text -class="no-updates" - -if [[ $text -gt 0 ]]; then - class="updates" -fi - -echo "{\"text\": \"$text\", \"alt\": \"$alt\", \"tooltip\": \"$tooltip\", \"class\": \"$class\", \"percentage\": $percentage }" diff --git a/waybar/style.css b/waybar/style.css index 3605cf0..5103e15 100644 --- a/waybar/style.css +++ b/waybar/style.css @@ -66,9 +66,11 @@ window#waybar { border-bottom-right-radius: 7px; } +/* #tray { background: rgba(76, 86, 106, 0.75); } +*/ #custom-pacman.no-updates { background: rgba(163, 190, 140, 0.75);