From e3008a6d431a2b05c197c2d5d1b644d7fe27f50d Mon Sep 17 00:00:00 2001 From: KemoNine Date: Tue, 1 Sep 2020 20:11:27 -0400 Subject: [PATCH] Add code to apply the wifi config in the main ui --- cmd/ui/ui.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/ui/ui.go b/cmd/ui/ui.go index 03d93fa..81cd4cc 100644 --- a/cmd/ui/ui.go +++ b/cmd/ui/ui.go @@ -13,6 +13,8 @@ import ( "github.com/gdamore/tcell" "github.com/guillermo/go.procmeminfo" "github.com/rivo/tview" + + "git.kemonine.info/PiFrame/wifi" ) const ( @@ -130,9 +132,19 @@ func main() { // WiFi Config Form wifiConfigForm := tview.NewForm() - wifiConfigForm.AddInputField("Access Point", "", 0, nil, nil) - wifiConfigForm.AddPasswordField("Password", "", 0, '*', nil) - wifiConfigForm.AddButton("Apply", nil) + wifiConfigAccessPoint := "" + wifiConfigPassword := "" + wifiConfigForm.AddInputField("Access Point", "", 0, nil, func(value string) { + wifiConfigAccessPoint = value + }) + wifiConfigForm.AddPasswordField("Password", "", 0, '*', func(value string) { + wifiConfigPassword = value + }) + wifiConfigForm.AddButton("Apply", func() { + // Cleanup old wifi configs and apply new one + nmWifi := wifi.New(wifiConfigAccessPoint, wifiConfigPassword) + nmWifi.ApplyConfig() + }) wifiConfigForm.AddButton("Cancel", func() { main.Clear() app.SetFocus(menu) @@ -318,7 +330,7 @@ func main() { // We use this as a bit of a cheat to figure out if we're inside of a form that needs better nav options for users (ie. tab doesn't exist on a remote) wifiField, wifiButton := wifiConfigForm.GetFocusedItemIndex() albumField, albumButton := selectAlbumsForm.GetFocusedItemIndex() - if wifiField != -1 || wifiButton != -1 || albumField != -1 || albumButton != -1 { + if wifiField != -1 || wifiButton != -1 || albumField != -1 || albumButton != -1 { switch event.Key() { case tcell.KeyUp: return tcell.NewEventKey(tcell.KeyBacktab, 0, event.Modifiers())