fix widgets according to updates
This commit is contained in:
parent
b50f9cbbd6
commit
e2262c998f
52
main.go
52
main.go
|
@ -20,9 +20,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
red color.RGBA
|
|
||||||
green color.RGBA
|
|
||||||
orange color.RGBA
|
|
||||||
directory string
|
directory string
|
||||||
configs []Config
|
configs []Config
|
||||||
application fyne.App
|
application fyne.App
|
||||||
|
@ -38,10 +35,6 @@ type Config struct {
|
||||||
type ButtonCallback func()
|
type ButtonCallback func()
|
||||||
|
|
||||||
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")
|
window = application.NewWindow("Wireguard GUI")
|
||||||
directory = "/etc/wireguard/"
|
directory = "/etc/wireguard/"
|
||||||
|
@ -109,14 +102,14 @@ func initConfigs() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func toggleNotice(notice *canvas.Text, isVisible bool) {
|
func toggleNotice(notice *widget.Label, isVisible bool) {
|
||||||
notice.Hidden = !isVisible
|
notice.Hidden = !isVisible
|
||||||
notice.Refresh()
|
notice.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateNotice(notice *canvas.Text, text string, c color.Color, isVisible, isFlash bool) {
|
func updateNotice(notice *widget.Label, text string, importance widget.Importance, isVisible, isFlash bool) {
|
||||||
notice.Text = text
|
notice.Text = text
|
||||||
notice.Color = c
|
notice.Importance = importance
|
||||||
notice.Hidden = !isVisible
|
notice.Hidden = !isVisible
|
||||||
notice.Refresh()
|
notice.Refresh()
|
||||||
|
|
||||||
|
@ -130,16 +123,16 @@ func updateNotice(notice *canvas.Text, text string, c color.Color, isVisible, is
|
||||||
log.Println(text)
|
log.Println(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func wgUp(config Config, notice *canvas.Text) {
|
func wgUp(config Config, notice *widget.Label) {
|
||||||
updateNotice(notice, fmt.Sprintf("Interface is starting"), orange, true, false)
|
updateNotice(notice, fmt.Sprintf("Interface is starting"), widget.WarningImportance, true, false)
|
||||||
exec.Command("wg-quick", "up", config.Name).Output()
|
exec.Command("wg-quick", "up", config.Name).Output()
|
||||||
updateNotice(notice, fmt.Sprintf("Interface is up"), green, true, true)
|
updateNotice(notice, fmt.Sprintf("Interface is up"), widget.SuccessImportance, true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func wgDown(config Config, notice *canvas.Text) {
|
func wgDown(config Config, notice *widget.Label) {
|
||||||
updateNotice(notice, fmt.Sprintf("Interface is stopping"), orange, true, false)
|
updateNotice(notice, fmt.Sprintf("Interface is stopping"), widget.WarningImportance, true, false)
|
||||||
exec.Command("wg-quick", "down", config.Name).Output()
|
exec.Command("wg-quick", "down", config.Name).Output()
|
||||||
updateNotice(notice, fmt.Sprintf("Interface is down"), green, true, true)
|
updateNotice(notice, fmt.Sprintf("Interface is down"), widget.SuccessImportance, true, true)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
|
@ -148,7 +141,7 @@ func wgDown(config Config, notice *canvas.Text) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func wgRestart(config Config, notice *canvas.Text) {
|
func wgRestart(config Config, notice *widget.Label) {
|
||||||
wgDown(config, notice)
|
wgDown(config, notice)
|
||||||
wgUp(config, notice)
|
wgUp(config, notice)
|
||||||
}
|
}
|
||||||
|
@ -180,16 +173,17 @@ func createTextarea() *widget.Entry {
|
||||||
return textarea
|
return textarea
|
||||||
}
|
}
|
||||||
|
|
||||||
func createColoredButton(label string, c color.Color, callback ButtonCallback) *fyne.Container {
|
func createColoredButton(label string, importance widget.Importance, callback ButtonCallback) *fyne.Container {
|
||||||
return container.NewMax(
|
button := widget.NewButton(label, callback)
|
||||||
canvas.NewRectangle(c),
|
button.Importance = importance
|
||||||
widget.NewButton(label, callback),
|
|
||||||
)
|
return container.NewMax(button)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNotice() *canvas.Text {
|
func createNotice() *widget.Label {
|
||||||
notice := canvas.NewText("", color.White)
|
notice := widget.NewLabel("")
|
||||||
notice.TextStyle.Bold = true
|
notice.TextStyle.Bold = true
|
||||||
|
notice.Importance = widget.LowImportance
|
||||||
|
|
||||||
return notice
|
return notice
|
||||||
}
|
}
|
||||||
|
@ -209,15 +203,15 @@ func createTab(config Config) *fyne.Container {
|
||||||
|
|
||||||
notice := createNotice()
|
notice := createNotice()
|
||||||
|
|
||||||
buttonStart := createColoredButton("Start", green, func() {
|
buttonStart := createColoredButton("Start", widget.SuccessImportance, func() {
|
||||||
wgUp(config, notice)
|
wgUp(config, notice)
|
||||||
})
|
})
|
||||||
|
|
||||||
buttonStop := createColoredButton("Stop", red, func() {
|
buttonStop := createColoredButton("Stop", widget.DangerImportance, func() {
|
||||||
wgDown(config, notice)
|
wgDown(config, notice)
|
||||||
})
|
})
|
||||||
|
|
||||||
buttonRestart := createColoredButton("Restart", orange, func() {
|
buttonRestart := createColoredButton("Restart", widget.WarningImportance, func() {
|
||||||
wgRestart(config, notice)
|
wgRestart(config, notice)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -255,9 +249,9 @@ func createTab(config Config) *fyne.Container {
|
||||||
log.Println("Configuration of", config.Name)
|
log.Println("Configuration of", config.Name)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
updateNotice(notice, fmt.Sprintf("Error while updating: %s", err), red, true, false)
|
updateNotice(notice, fmt.Sprintf("Error while updating: %s", err), widget.DangerImportance, true, false)
|
||||||
} else {
|
} else {
|
||||||
updateNotice(notice, fmt.Sprintf("Configuration updated"), green, true, true)
|
updateNotice(notice, fmt.Sprintf("Configuration updated"), widget.SuccessImportance, true, true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SubmitText: "Save",
|
SubmitText: "Save",
|
||||||
|
|
Loading…
Reference in a new issue