update ui

This commit is contained in:
Simon Vieille 2022-09-12 14:00:24 +02:00
parent 0ae13b5030
commit a526d6a8e6
Signed by: deblan
GPG key ID: 579388D585F70417
2 changed files with 22 additions and 9 deletions

31
main.go
View file

@ -23,7 +23,15 @@ type Config struct {
File string File string
} }
var red color.RGBA
var green color.RGBA
var orange color.RGBA
func main() { func main() {
red = color.RGBA{R: 156, G: 21, B: 21}
green = color.RGBA{R: 47, G: 156, B: 17}
orange = color.RGBA{R: 156, G: 106, B: 25}
application := app.New() application := app.New()
window := application.NewWindow("Wireguard GUI (deblan)") window := application.NewWindow("Wireguard GUI (deblan)")
configs := []Config{} configs := []Config{}
@ -86,13 +94,13 @@ func main() {
func WgUp(config Config, notice *canvas.Text) { func WgUp(config Config, notice *canvas.Text) {
notice.Hidden = false notice.Hidden = false
notice.Text = fmt.Sprintf("Interface is starting") notice.Text = fmt.Sprintf("Interface is starting")
notice.Color = color.RGBA{R: 200, G: 165, B: 76} notice.Color = orange
notice.Refresh() notice.Refresh()
exec.Command("wg-quick", "up", config.Name).Output() exec.Command("wg-quick", "up", config.Name).Output()
notice.Text = fmt.Sprintf("Interface is up") notice.Text = fmt.Sprintf("Interface is up")
notice.Color = color.RGBA{R: 111, G: 200, B: 72} notice.Color = green
notice.Refresh() notice.Refresh()
go func() { go func() {
@ -107,13 +115,13 @@ func WgDown(config Config, notice *canvas.Text) {
notice.Hidden = false notice.Hidden = false
notice.Text = fmt.Sprintf("Interface is stopping") notice.Text = fmt.Sprintf("Interface is stopping")
notice.Color = color.RGBA{R: 200, G: 165, B: 76} notice.Color = orange
notice.Refresh() notice.Refresh()
exec.Command("wg-quick", "down", config.Name).Output() exec.Command("wg-quick", "down", config.Name).Output()
notice.Text = fmt.Sprintf("Interface is down") notice.Text = fmt.Sprintf("Interface is down")
notice.Color = color.RGBA{R: 111, G: 200, B: 72} notice.Color = green
notice.Refresh() notice.Refresh()
go func() { go func() {
@ -155,15 +163,20 @@ func createTab(config Config) *fyne.Container {
WgRestart(config, notice) WgRestart(config, notice)
}) })
buttonStartWrapper := container.NewMax(canvas.NewRectangle(green), buttonStart)
buttonStopWrapper := container.NewMax(canvas.NewRectangle(red), buttonStop)
buttonRestartWrapper := container.NewMax(canvas.NewRectangle(orange), buttonRestart)
top := container.New( top := container.New(
layout.NewVBoxLayout(), layout.NewVBoxLayout(),
r1, r1,
container.New( container.New(
layout.NewHBoxLayout(), layout.NewHBoxLayout(),
buttonStart,
buttonStop,
buttonRestart,
notice, notice,
layout.NewSpacer(),
buttonStartWrapper,
buttonStopWrapper,
buttonRestartWrapper,
), ),
r2, r2,
) )
@ -194,11 +207,11 @@ func createTab(config Config) *fyne.Container {
if err != nil { if err != nil {
log.Println(err) log.Println(err)
notice.Text = fmt.Sprintf("Error while updating: %s", err) notice.Text = fmt.Sprintf("Error while updating: %s", err)
notice.Color = color.RGBA{R: 200, G: 68, B: 68} notice.Color = red
notice.Refresh() notice.Refresh()
} else { } else {
notice.Text = fmt.Sprintf("Configuration updated") notice.Text = fmt.Sprintf("Configuration updated")
notice.Color = color.RGBA{R: 111, G: 200, B: 72} notice.Color = green
go func() { go func() {
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)

Binary file not shown.