From 9787f78dd8fc9521a6767cbf0255edeebc0ea8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl-Einar=20Bergstr=C3=B8m?= Date: Sun, 11 Oct 2026 09:33:29 +0200 Subject: [PATCH] feat: save the place on the periodic tick too Co-Authored-By: Claude Opus 5.5 (1M context) --- internal/ui/app/app.go | 3 ++- internal/ui/app/persist.go | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/internal/ui/app/app.go b/internal/ui/app/app.go index cb2f331..5bb248e 100644 --- a/internal/ui/app/app.go +++ b/internal/ui/app/app.go @@ -168,6 +168,7 @@ type Model struct { cacheDirty bool sourcesAt map[string]time.Time placeDir string + savedPlace string // the link last saved as the place now func() time.Time // A pending clear of a copied value, counted down in the footer. @@ -456,7 +457,7 @@ func (m *Model) setVersions(items []provider.Object) { func (m Model) Init() tea.Cmd { cmds := []tea.Cmd{m.sourcesCmd(), m.spin.Tick, m.checkClipboard()} - if m.cachePath != "" { + if m.cachePath != "" || m.placeDir != "" { cmds = append(cmds, tea.Tick(persistEvery, func(time.Time) tea.Msg { return persistTickMsg{} })) } if m.fetchOnStart { diff --git a/internal/ui/app/persist.go b/internal/ui/app/persist.go index 8363079..78f3a6f 100644 --- a/internal/ui/app/persist.go +++ b/internal/ui/app/persist.go @@ -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)) } }