Skip to content

Commit

Permalink
Check for errors after getting a response for all components
Browse files Browse the repository at this point in the history
Some components were failing without internet connecttion and thus,
crashing the whole bar.
  • Loading branch information
aonemd committed Mar 29, 2018
1 parent c8cb080 commit 6bc4332
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion components/battery_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const (
)

func main() {
response, _ := exec.Command("acpi", "-b", " | ", "grep", "Battery ", battery).Output()
response, err := exec.Command("acpi", "-b", " | ", "grep", "Battery ", battery).Output()
if err != nil {
return
}

iconPattern, _ := regexp.Compile("Full|Charging|Discharging")
powerPattern, _ := regexp.Compile("[0-9]+%")
Expand Down
5 changes: 4 additions & 1 deletion components/cmus.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
)

func main() {
response, _ := exec.Command("cmus-remote", "-Q").Output()
response, err := exec.Command("cmus-remote", "-Q").Output()
if err != nil {
return
}

artistPattern, _ := regexp.Compile("tag artist .*")
titlePattern, _ := regexp.Compile("tag title .*")
Expand Down
6 changes: 5 additions & 1 deletion components/dark_sky_weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ const (

func main() {
api_uri := fmt.Sprintf("https://api.darksky.net/forecast/%s/%s?exclude=minutely,hourly,daily,alerts,flags&units=%s", api_key, lon_lat, units)
response, _ := http.Get(api_uri)
response, err := http.Get(api_uri)
if err != nil {
return
}

data, _ := ioutil.ReadAll(response.Body)

var forecast interface{}
Expand Down
6 changes: 5 additions & 1 deletion components/keyboard_layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (
)

func main() {
response, _ := exec.Command("setxkbmap", "-query").Output()
response, err := exec.Command("setxkbmap", "-query").Output()
if err != nil {
return
}

layoutPattern, _ := regexp.Compile("layout:\\s+[a-z]+")
layout := strings.TrimSpace(strings.Split(layoutPattern.FindString(string(response)), ":")[1])

Expand Down
5 changes: 4 additions & 1 deletion components/volume_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const (
)

func main() {
response, _ := exec.Command("amixer", "sget", "Master").Output()
response, err := exec.Command("amixer", "sget", "Master").Output()
if err != nil {
return
}

levelPattern, _ := regexp.Compile("[0-9]+%")
statusPattern, _ := regexp.Compile("\\[(on|off)\\]")
Expand Down

0 comments on commit 6bc4332

Please sign in to comment.