Make icon a bit more dynamic

This commit is contained in:
Aaron Bieber 2022-11-21 19:54:29 -07:00
parent 9549e88149
commit 871356d3bb
No known key found for this signature in database
2 changed files with 30 additions and 7 deletions

View File

@ -24,11 +24,11 @@ func parseHexColor(s string) (*color.RGBA, error) {
} }
func isEdge(x, y int) bool { func isEdge(x, y int) bool {
if x == 0 || x == width { if x == 0 || x == width-1 {
return true return true
} }
if y == 0 || y == height { if y == 0 || y == height-1 {
return true return true
} }
@ -52,7 +52,7 @@ func (m *myIcon) Content() []byte {
func buildImage(xin *xinStatus) *myIcon { func buildImage(xin *xinStatus) *myIcon {
i := &myIcon{} i := &myIcon{}
u2d, err := parseHexColor("#46d700") on, err := parseHexColor("#46d700")
off, err := parseHexColor("#c1c1c1") off, err := parseHexColor("#c1c1c1")
if err != nil { if err != nil {
@ -67,13 +67,20 @@ func buildImage(xin *xinStatus) *myIcon {
A: 0xff, A: 0xff,
} }
for y := 0; y < width; y++ { aliveCount := int(xin.aliveCount())
for x := 0; x < height; x++ { utdCount := int(xin.uptodateCount())
gridMark := 1
if aliveCount > 0 {
gridMark = int(height / aliveCount)
}
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
if isEdge(x, y) { if isEdge(x, y) {
i.data.Set(x, y, border) i.data.Set(x, y, border)
} else { } else {
if xin.uptodate() { if aliveCount > 0 && y < gridMark*utdCount {
i.data.Set(x, y, u2d) i.data.Set(x, y, on)
} else { } else {
i.data.Set(x, y, off) i.data.Set(x, y, off)
} }

16
main.go
View File

@ -48,6 +48,7 @@ type Status struct {
commit commit commit commit
client *ssh.Client client *ssh.Client
clientEstablished bool clientEstablished bool
upToDate bool
ConfigurationRevision string `json:"configurationRevision"` ConfigurationRevision string `json:"configurationRevision"`
NeedsRestart bool `json:"needs_restart"` NeedsRestart bool `json:"needs_restart"`
@ -110,6 +111,16 @@ func (x *xinStatus) aliveCount() float64 {
return float64(alive) return float64(alive)
} }
func (x *xinStatus) uptodateCount() float64 {
utd := 0
for _, s := range x.config.Statuses {
if s.upToDate {
utd = utd + 1
}
}
return float64(utd)
}
func (x *xinStatus) uptodate() bool { func (x *xinStatus) uptodate() bool {
return x.upgradeProgress.Value == x.aliveCount() return x.upgradeProgress.Value == x.aliveCount()
} }
@ -233,6 +244,11 @@ func (x *xinStatus) updateHostInfo() error {
continue continue
} }
s.commit = *commit s.commit = *commit
s.upToDate = false
if s.commit == x.repoCommit {
s.upToDate = true
}
} }
x.upgradeProgress.SetValue(float64(upToDateCount)) x.upgradeProgress.SetValue(float64(upToDateCount))