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 (
|
||||
red color.RGBA
|
||||
green color.RGBA
|
||||
orange color.RGBA
|
||||
directory string
|
||||
configs []Config
|
||||
application fyne.App
|
||||
|
@ -38,10 +35,6 @@ type Config struct {
|
|||
type ButtonCallback func()
|
||||
|
||||
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()
|
||||
window = application.NewWindow("Wireguard GUI")
|
||||
directory = "/etc/wireguard/"
|
||||
|
@ -109,14 +102,14 @@ func initConfigs() error {
|
|||
return err
|
||||
}
|
||||
|
||||
func toggleNotice(notice *canvas.Text, isVisible bool) {
|
||||
func toggleNotice(notice *widget.Label, isVisible bool) {
|
||||
notice.Hidden = !isVisible
|
||||
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.Color = c
|
||||
notice.Importance = importance
|
||||
notice.Hidden = !isVisible
|
||||
notice.Refresh()
|
||||
|
||||
|
@ -130,16 +123,16 @@ func updateNotice(notice *canvas.Text, text string, c color.Color, isVisible, is
|
|||
log.Println(text)
|
||||
}
|
||||
|
||||
func wgUp(config Config, notice *canvas.Text) {
|
||||
updateNotice(notice, fmt.Sprintf("Interface is starting"), orange, true, false)
|
||||
func wgUp(config Config, notice *widget.Label) {
|
||||
updateNotice(notice, fmt.Sprintf("Interface is starting"), widget.WarningImportance, true, false)
|
||||
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) {
|
||||
updateNotice(notice, fmt.Sprintf("Interface is stopping"), orange, true, false)
|
||||
func wgDown(config Config, notice *widget.Label) {
|
||||
updateNotice(notice, fmt.Sprintf("Interface is stopping"), widget.WarningImportance, true, false)
|
||||
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() {
|
||||
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)
|
||||
wgUp(config, notice)
|
||||
}
|
||||
|
@ -180,16 +173,17 @@ func createTextarea() *widget.Entry {
|
|||
return textarea
|
||||
}
|
||||
|
||||
func createColoredButton(label string, c color.Color, callback ButtonCallback) *fyne.Container {
|
||||
return container.NewMax(
|
||||
canvas.NewRectangle(c),
|
||||
widget.NewButton(label, callback),
|
||||
)
|
||||
func createColoredButton(label string, importance widget.Importance, callback ButtonCallback) *fyne.Container {
|
||||
button := widget.NewButton(label, callback)
|
||||
button.Importance = importance
|
||||
|
||||
return container.NewMax(button)
|
||||
}
|
||||
|
||||
func createNotice() *canvas.Text {
|
||||
notice := canvas.NewText("", color.White)
|
||||
func createNotice() *widget.Label {
|
||||
notice := widget.NewLabel("")
|
||||
notice.TextStyle.Bold = true
|
||||
notice.Importance = widget.LowImportance
|
||||
|
||||
return notice
|
||||
}
|
||||
|
@ -209,15 +203,15 @@ func createTab(config Config) *fyne.Container {
|
|||
|
||||
notice := createNotice()
|
||||
|
||||
buttonStart := createColoredButton("Start", green, func() {
|
||||
buttonStart := createColoredButton("Start", widget.SuccessImportance, func() {
|
||||
wgUp(config, notice)
|
||||
})
|
||||
|
||||
buttonStop := createColoredButton("Stop", red, func() {
|
||||
buttonStop := createColoredButton("Stop", widget.DangerImportance, func() {
|
||||
wgDown(config, notice)
|
||||
})
|
||||
|
||||
buttonRestart := createColoredButton("Restart", orange, func() {
|
||||
buttonRestart := createColoredButton("Restart", widget.WarningImportance, func() {
|
||||
wgRestart(config, notice)
|
||||
})
|
||||
|
||||
|
@ -255,9 +249,9 @@ func createTab(config Config) *fyne.Container {
|
|||
log.Println("Configuration of", config.Name)
|
||||
|
||||
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 {
|
||||
updateNotice(notice, fmt.Sprintf("Configuration updated"), green, true, true)
|
||||
updateNotice(notice, fmt.Sprintf("Configuration updated"), widget.SuccessImportance, true, true)
|
||||
}
|
||||
},
|
||||
SubmitText: "Save",
|
||||
|
|
Loading…
Reference in a new issue