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