1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-20 05:19:24 +02:00

Extract a SaveAppStateAndLogError function

It seems that most actions that change a state option and resave the state want
to just log the error.
This commit is contained in:
Stefan Haller 2023-08-28 13:18:58 +02:00
parent 1dac4158e9
commit 1106981827
4 changed files with 9 additions and 6 deletions

View File

@ -24,9 +24,7 @@ func (self *ToggleWhitespaceAction) Call() error {
}
self.c.GetAppState().IgnoreWhitespaceInDiffView = !self.c.GetAppState().IgnoreWhitespaceInDiffView
if err := self.c.SaveAppState(); err != nil {
self.c.Log.Errorf("error when saving app state: %v", err)
}
self.c.SaveAppStateAndLogError()
return self.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{})
}

View File

@ -24,9 +24,7 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
show := !gui.c.State().GetShowExtrasWindow()
gui.c.State().SetShowExtrasWindow(show)
gui.c.GetAppState().HideCommandLog = !show
if err := gui.c.SaveAppState(); err != nil {
gui.c.Log.Errorf("error when saving app state: %v", err)
}
gui.c.SaveAppStateAndLogError()
return nil
},
},

View File

@ -92,6 +92,12 @@ func (self *guiCommon) SaveAppState() error {
return self.gui.Config.SaveAppState()
}
func (self *guiCommon) SaveAppStateAndLogError() {
if err := self.gui.Config.SaveAppState(); err != nil {
self.gui.Log.Errorf("error when saving app state: %v", err)
}
}
func (self *guiCommon) GetConfig() config.AppConfigurer {
return self.gui.Config
}

View File

@ -73,6 +73,7 @@ type IGuiCommon interface {
GetConfig() config.AppConfigurer
GetAppState() *config.AppState
SaveAppState() error
SaveAppStateAndLogError()
// Runs the given function on the UI thread (this is for things like showing a popup asking a user for input).
// Only necessary to call if you're not already on the UI thread i.e. you're inside a goroutine.