Cleanup config UI further, fix some save bugs
This commit is contained in:
parent
15dfaa31f9
commit
728c281ad3
53
ui/config.go
53
ui/config.go
|
@ -38,6 +38,17 @@ const (
|
|||
PAGE_POWEROFF = "PAGE_POWEROFF"
|
||||
)
|
||||
|
||||
// Housekeeping
|
||||
var app *tview.Application
|
||||
var main *tview.Flex
|
||||
var menu *tview.List
|
||||
|
||||
// Function to reset the main input area that's used all over the place
|
||||
func resetMain() {
|
||||
main.Clear()
|
||||
app.SetFocus(menu)
|
||||
}
|
||||
|
||||
func ConfigGui(pfconfig *koanf.Koanf) {
|
||||
// Memory info for status panel
|
||||
meminfo := &procmeminfo.MemInfo{}
|
||||
|
@ -91,7 +102,7 @@ func ConfigGui(pfconfig *koanf.Koanf) {
|
|||
}
|
||||
|
||||
// Run config UI when slideshow stops
|
||||
app := tview.NewApplication()
|
||||
app = tview.NewApplication()
|
||||
|
||||
// Header
|
||||
headerTitle := tview.NewTextView().
|
||||
|
@ -148,7 +159,7 @@ func ConfigGui(pfconfig *koanf.Koanf) {
|
|||
AddItem(rebootButton, 0, 1, false).
|
||||
AddItem(powerOffButton, 0, 1, false)
|
||||
// Setup menu
|
||||
menu := tview.NewList()
|
||||
menu = tview.NewList()
|
||||
menu.SetBorder(true).
|
||||
SetTitle("Menu").
|
||||
SetTitleColor(tcell.ColorAqua)
|
||||
|
@ -159,7 +170,7 @@ func ConfigGui(pfconfig *koanf.Koanf) {
|
|||
menu.AddItem("Advanced", "", '6', nil)
|
||||
|
||||
// Setup base var for main column so the menu setup is easier to manage
|
||||
main := tview.NewFlex().
|
||||
main = tview.NewFlex().
|
||||
SetDirection(tview.FlexRow)
|
||||
|
||||
// Setup main panel (Center column)
|
||||
|
@ -182,11 +193,8 @@ func ConfigGui(pfconfig *koanf.Koanf) {
|
|||
}
|
||||
selectAlbumsForm.AddCheckbox(album, albumSelected, nil)
|
||||
}
|
||||
selectAlbumsForm.AddButton("Apply", nil)
|
||||
selectAlbumsForm.AddButton("Cancel", func() {
|
||||
main.Clear()
|
||||
app.SetFocus(menu)
|
||||
})
|
||||
selectAlbumsForm.AddButton("Apply", resetMain)
|
||||
selectAlbumsForm.AddButton("Cancel", resetMain)
|
||||
|
||||
// Slide Interval Form
|
||||
intervalsForm := tview.NewForm()
|
||||
|
@ -198,11 +206,8 @@ func ConfigGui(pfconfig *koanf.Koanf) {
|
|||
intervalsForm.AddInputField("Restart/Reshuffle", configRestartInterval, 0, nil, func(value string) {
|
||||
configRestartInterval = value
|
||||
})
|
||||
intervalsForm.AddButton("Apply", nil)
|
||||
intervalsForm.AddButton("Cancel", func() {
|
||||
main.Clear()
|
||||
app.SetFocus(menu)
|
||||
})
|
||||
intervalsForm.AddButton("Apply", resetMain)
|
||||
intervalsForm.AddButton("Cancel", resetMain)
|
||||
|
||||
// WiFi Config Form
|
||||
wifiConfigForm := tview.NewForm()
|
||||
|
@ -218,11 +223,9 @@ func ConfigGui(pfconfig *koanf.Koanf) {
|
|||
// Cleanup old wifi configs and apply new one
|
||||
nmWifi := wifi.New(wifiConfigAccessPoint, wifiConfigPassword)
|
||||
nmWifi.ApplyConfig()
|
||||
resetMain()
|
||||
})
|
||||
wifiConfigForm.AddButton("Cancel", func() {
|
||||
main.Clear()
|
||||
app.SetFocus(menu)
|
||||
})
|
||||
wifiConfigForm.AddButton("Cancel", resetMain)
|
||||
|
||||
// HDMI On/Off Form
|
||||
hdmiForm := tview.NewForm()
|
||||
|
@ -234,18 +237,12 @@ func ConfigGui(pfconfig *koanf.Koanf) {
|
|||
hdmiForm.AddInputField("HDMI On Schedule", configHDMIOn, 0, nil, func(value string) {
|
||||
configHDMIOn = value
|
||||
})
|
||||
hdmiForm.AddButton("Apply", nil)
|
||||
hdmiForm.AddButton("Cancel", func() {
|
||||
main.Clear()
|
||||
app.SetFocus(menu)
|
||||
})
|
||||
hdmiForm.AddButton("Apply", resetMain)
|
||||
hdmiForm.AddButton("Cancel", resetMain)
|
||||
|
||||
// Advanced config form
|
||||
advancedForm := tview.NewForm()
|
||||
advancedForm.AddButton("Go Back", func() {
|
||||
main.Clear()
|
||||
app.SetFocus(menu)
|
||||
})
|
||||
advancedForm.AddButton("Go Back", resetMain)
|
||||
|
||||
// Setup menu selection handler
|
||||
menu.SetSelectedFunc(func(index int, title string, desc string, shortcut rune) {
|
||||
|
@ -412,8 +409,8 @@ func ConfigGui(pfconfig *koanf.Koanf) {
|
|||
|
||||
// Apply configuration updates to main config manager prior to saving
|
||||
pfconfig.Load(confmap.Provider(map[string]interface{}{
|
||||
config.DEFAULT_HDMI_ON: configHDMIOn,
|
||||
config.DEFAULT_HDMI_OFF: configHDMIOff,
|
||||
config.CONFIG_KEY_HDMI_ON: configHDMIOn,
|
||||
config.CONFIG_KEY_HDMI_OFF: configHDMIOff,
|
||||
}, "."), nil)
|
||||
|
||||
// Save configuration
|
||||
|
|
Loading…
Reference in a new issue