create gomu.quit() method

This commit is contained in:
raziman 2020-08-02 16:02:07 +08:00
parent 8069c1c8a2
commit ebbb3d89ce
2 changed files with 16 additions and 9 deletions

15
gomu.go
View File

@ -6,6 +6,7 @@ import (
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/spf13/viper"
"github.com/ztrue/tracerr"
)
const VERSION = "v1.4.0"
@ -33,7 +34,7 @@ type Gomu struct {
func newGomu() *Gomu {
gomu := &Gomu{
popupBg: tcell.GetColor(viper.GetString("color.popup")),
popupBg: tcell.GetColor("#0A0F14"),
textColor: tcell.GetColor(viper.GetString("color.foreground")),
accentColor: tcell.GetColor(viper.GetString("color.accent")),
}
@ -137,3 +138,15 @@ func (g *Gomu) setUnfocusPanel(panel Panel) {
g.prevPanel.SetBorderColor(g.textColor)
g.prevPanel.SetTitleColor((g.textColor))
}
// Quit the application and do the neccessary clean up
func (g *Gomu) quit() error {
if err := gomu.queue.saveQueue(); err != nil {
return tracerr.Wrap(err)
}
gomu.app.Stop()
return nil
}

View File

@ -344,15 +344,9 @@ func exitConfirmation() {
return
}
if err := gomu.queue.saveQueue(); err != nil {
err := gomu.quit()
if err != nil {
logError(err)
}
if err := viper.WriteConfig(); err != nil {
logError(err)
}
gomu.app.Stop()
})
}