feat: save the place on the periodic tick too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d6c4b33d1d
commit
9787f78dd8
2 files changed
+16
-9
No files matched your search
@@ -164,15 +164,21 @@ func writeCacheFile(path string, f cacheFile) error {
|
||||
return os.Rename(tmp.Name(), path)
|
||||
}
|
||||
|
||||
// persistTick saves the cache in the background when it changed.
|
||||
// persistTick saves the cache, and where lazysecrets is, in the
|
||||
// background when they changed.
|
||||
func (m *Model) persistTick() tea.Cmd {
|
||||
next := tea.Tick(persistEvery, func(time.Time) tea.Msg { return persistTickMsg{} })
|
||||
if !m.cacheDirty {
|
||||
return next
|
||||
cmds := []tea.Cmd{tea.Tick(persistEvery, func(time.Time) tea.Msg { return persistTickMsg{} })}
|
||||
if m.cacheDirty && m.cachePath != "" {
|
||||
m.cacheDirty = false
|
||||
f, path := m.cacheSnapshot(), m.cachePath
|
||||
cmds = append(cmds, func() tea.Msg { return persistedMsg{writeCacheFile(path, f)} })
|
||||
}
|
||||
m.cacheDirty = false
|
||||
f, path := m.cacheSnapshot(), m.cachePath
|
||||
return tea.Batch(next, func() tea.Msg { return persistedMsg{writeCacheFile(path, f)} })
|
||||
if p, ok := m.place(); ok && m.placeDir != "" && p.Link != m.savedPlace {
|
||||
m.savedPlace = p.Link
|
||||
st, dir := m.store, m.placeDir
|
||||
cmds = append(cmds, func() tea.Msg { return persistedMsg{st.SetPlace(dir, p)} })
|
||||
}
|
||||
return tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
// Persist saves the cache and where lazysecrets was left; run it after
|
||||
@@ -238,6 +244,6 @@ func (m *Model) restorePlace() {
|
||||
|
||||
func (m *Model) handlePersisted(msg persistedMsg) {
|
||||
if msg.err != nil {
|
||||
m.noteErr(fmt.Errorf("saving the cache: %w", msg.err))
|
||||
m.noteErr(fmt.Errorf("saving the cache or place: %w", msg.err))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user