Make icon a bit more dynamic
This commit is contained in:
parent
9549e88149
commit
871356d3bb
21
icons.go
21
icons.go
@ -24,11 +24,11 @@ func parseHexColor(s string) (*color.RGBA, error) {
|
||||
}
|
||||
|
||||
func isEdge(x, y int) bool {
|
||||
if x == 0 || x == width {
|
||||
if x == 0 || x == width-1 {
|
||||
return true
|
||||
}
|
||||
|
||||
if y == 0 || y == height {
|
||||
if y == 0 || y == height-1 {
|
||||
return true
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ func (m *myIcon) Content() []byte {
|
||||
func buildImage(xin *xinStatus) *myIcon {
|
||||
i := &myIcon{}
|
||||
|
||||
u2d, err := parseHexColor("#46d700")
|
||||
on, err := parseHexColor("#46d700")
|
||||
off, err := parseHexColor("#c1c1c1")
|
||||
|
||||
if err != nil {
|
||||
@ -67,13 +67,20 @@ func buildImage(xin *xinStatus) *myIcon {
|
||||
A: 0xff,
|
||||
}
|
||||
|
||||
for y := 0; y < width; y++ {
|
||||
for x := 0; x < height; x++ {
|
||||
aliveCount := int(xin.aliveCount())
|
||||
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) {
|
||||
i.data.Set(x, y, border)
|
||||
} else {
|
||||
if xin.uptodate() {
|
||||
i.data.Set(x, y, u2d)
|
||||
if aliveCount > 0 && y < gridMark*utdCount {
|
||||
i.data.Set(x, y, on)
|
||||
} else {
|
||||
i.data.Set(x, y, off)
|
||||
}
|
||||
|
16
main.go
16
main.go
@ -48,6 +48,7 @@ type Status struct {
|
||||
commit commit
|
||||
client *ssh.Client
|
||||
clientEstablished bool
|
||||
upToDate bool
|
||||
|
||||
ConfigurationRevision string `json:"configurationRevision"`
|
||||
NeedsRestart bool `json:"needs_restart"`
|
||||
@ -110,6 +111,16 @@ func (x *xinStatus) aliveCount() float64 {
|
||||
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 {
|
||||
return x.upgradeProgress.Value == x.aliveCount()
|
||||
}
|
||||
@ -233,6 +244,11 @@ func (x *xinStatus) updateHostInfo() error {
|
||||
continue
|
||||
}
|
||||
s.commit = *commit
|
||||
|
||||
s.upToDate = false
|
||||
if s.commit == x.repoCommit {
|
||||
s.upToDate = true
|
||||
}
|
||||
}
|
||||
|
||||
x.upgradeProgress.SetValue(float64(upToDateCount))
|
||||
|
Loading…
Reference in New Issue
Block a user