diff --git a/wtf.go b/wtf.go index ad739a99..b128c149 100644 --- a/wtf.go +++ b/wtf.go @@ -122,6 +122,8 @@ func watchForConfigChanges(app *tview.Application, configFlag string, grid *tvie select { case <-watch.Event: loadConfig(configFlag) + // Disable all widgets to stop scheduler goroutines and rmeove widgets from memory. + disableAllWidgets() makeWidgets(app, pages) grid = buildGrid(Widgets) pages.AddPage("grid", grid, true, true) @@ -156,6 +158,12 @@ var ( version = "dev" ) +func disableAllWidgets() { + for _, widget := range Widgets { + widget.Disable() + } +} + func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) { // Always in alphabetical order switch widgetName { diff --git a/wtf/enabler.go b/wtf/enabler.go index 26ec5a21..c7a5b973 100644 --- a/wtf/enabler.go +++ b/wtf/enabler.go @@ -3,4 +3,5 @@ package wtf type Enabler interface { Disabled() bool Enabled() bool + Disable() } diff --git a/wtf/text_widget.go b/wtf/text_widget.go index 8c7f864d..b62868ef 100644 --- a/wtf/text_widget.go +++ b/wtf/text_widget.go @@ -61,6 +61,10 @@ func (widget *TextWidget) Enabled() bool { return widget.enabled } +func (widget *TextWidget) Disable() { + widget.enabled = false +} + func (widget *TextWidget) Focusable() bool { return widget.enabled && widget.focusable }