feat: persist chub settings and instances
This commit is contained in:
+32
-3
@@ -25,6 +25,14 @@ type InstanceRow struct {
|
||||
Status string
|
||||
}
|
||||
|
||||
type SettingsState struct {
|
||||
ChromePath string
|
||||
EdgePath string
|
||||
DefaultDir string
|
||||
LogDir string
|
||||
CloseOnExit bool
|
||||
}
|
||||
|
||||
// Shell owns every interactive Gio widget. Keeping this state outside Layout
|
||||
// prevents focus, editor content, and list scroll position from resetting.
|
||||
type Shell struct {
|
||||
@@ -44,8 +52,9 @@ type Shell struct {
|
||||
logDir widget.Editor
|
||||
closeOnExit widget.Bool
|
||||
|
||||
list widget.List
|
||||
rows []InstanceRow
|
||||
list widget.List
|
||||
rows []InstanceRow
|
||||
onSave func(SettingsState)
|
||||
}
|
||||
|
||||
func NewShell(theme *material.Theme) *Shell {
|
||||
@@ -63,6 +72,23 @@ func NewShell(theme *material.Theme) *Shell {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Shell) SetInstances(rows []InstanceRow) {
|
||||
if len(rows) == 0 {
|
||||
return
|
||||
}
|
||||
s.rows = append([]InstanceRow(nil), rows...)
|
||||
}
|
||||
|
||||
func (s *Shell) SetSettings(value SettingsState) {
|
||||
s.chromePath.SetText(value.ChromePath)
|
||||
s.edgePath.SetText(value.EdgePath)
|
||||
s.dataDir.SetText(value.DefaultDir)
|
||||
s.logDir.SetText(value.LogDir)
|
||||
s.closeOnExit.Value = value.CloseOnExit
|
||||
}
|
||||
|
||||
func (s *Shell) OnSave(fn func(SettingsState)) { s.onSave = fn }
|
||||
|
||||
func (s *Shell) Layout(gtx layout.Context) layout.Dimensions {
|
||||
for s.instancesClick.Clicked(gtx) {
|
||||
s.page = pageInstances
|
||||
@@ -136,7 +162,10 @@ func statusLabel(theme *material.Theme, status string) layout.Widget {
|
||||
}
|
||||
|
||||
func (s *Shell) settings(gtx layout.Context) layout.Dimensions {
|
||||
for s.saveClick.Clicked(gtx) { /* persistence is T-202; retain edited values for now */
|
||||
for s.saveClick.Clicked(gtx) {
|
||||
if s.onSave != nil {
|
||||
s.onSave(SettingsState{ChromePath: s.chromePath.Text(), EdgePath: s.edgePath.Text(), DefaultDir: s.dataDir.Text(), LogDir: s.logDir.Text(), CloseOnExit: s.closeOnExit.Value})
|
||||
}
|
||||
}
|
||||
for s.cancelClick.Clicked(gtx) {
|
||||
s.resetSettings()
|
||||
|
||||
Reference in New Issue
Block a user