diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-03-22 19:51:20 +0200 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-03-22 19:54:31 +0200 |
commit | 702a75a8c0355737e3e62735b59fe30bee7e42f4 (patch) | |
tree | 538b2acd579eabf893fd1f63bc7093b65b620f28 /gomuks.go | |
parent | 232f7fe1be917bf91f6342946f6d001948b8559e (diff) |
Save history to disk. Fixes #1
Diffstat (limited to 'gomuks.go')
-rw-r--r-- | gomuks.go | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -38,12 +38,14 @@ type Gomuks struct { debug *debug.Pane debugMode bool config *config.Config + stop chan bool } func NewGomuks(enableDebug bool) *Gomuks { configDir := filepath.Join(os.Getenv("HOME"), ".config/gomuks") gmx := &Gomuks{ - app: tview.NewApplication(), + app: tview.NewApplication(), + stop: make(chan bool, 1), } gmx.debug = debug.NewPane() @@ -79,11 +81,33 @@ func (gmx *Gomuks) Stop() { gmx.matrix.Stop() gmx.debug.Print("Cleaning up UI...") gmx.app.Stop() + gmx.stop <- true + gmx.Save() + os.Exit(0) +} + +func (gmx *Gomuks) Save() { if gmx.config.Session != nil { gmx.debug.Print("Saving session...") gmx.config.Session.Save() } - os.Exit(0) + gmx.debug.Print("Saving history...") + gmx.ui.MainView().SaveAllHistory() +} + +func (gmx *Gomuks) StartAutosave() { + defer gmx.Recover() + ticker := time.NewTicker(time.Minute) + for { + select { + case <-ticker.C: + gmx.Save() + case val := <-gmx.stop: + if val { + return + } + } + } } func (gmx *Gomuks) Recover() { @@ -101,6 +125,7 @@ func (gmx *Gomuks) Recover() { func (gmx *Gomuks) Start() { defer gmx.Recover() + go gmx.StartAutosave() if err := gmx.app.Run(); err != nil { panic(err) } |