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
+15
-8
No files matched your search
@@ -168,6 +168,7 @@ type Model struct {
|
|||||||
cacheDirty bool
|
cacheDirty bool
|
||||||
sourcesAt map[string]time.Time
|
sourcesAt map[string]time.Time
|
||||||
placeDir string
|
placeDir string
|
||||||
|
savedPlace string // the link last saved as the place
|
||||||
now func() time.Time
|
now func() time.Time
|
||||||
|
|
||||||
// A pending clear of a copied value, counted down in the footer.
|
// 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 {
|
func (m Model) Init() tea.Cmd {
|
||||||
cmds := []tea.Cmd{m.sourcesCmd(), m.spin.Tick, m.checkClipboard()}
|
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{} }))
|
cmds = append(cmds, tea.Tick(persistEvery, func(time.Time) tea.Msg { return persistTickMsg{} }))
|
||||||
}
|
}
|
||||||
if m.fetchOnStart {
|
if m.fetchOnStart {
|
||||||
|
|||||||
@@ -164,15 +164,21 @@ func writeCacheFile(path string, f cacheFile) error {
|
|||||||
return os.Rename(tmp.Name(), path)
|
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 {
|
func (m *Model) persistTick() tea.Cmd {
|
||||||
next := tea.Tick(persistEvery, func(time.Time) tea.Msg { return persistTickMsg{} })
|
cmds := []tea.Cmd{tea.Tick(persistEvery, func(time.Time) tea.Msg { return persistTickMsg{} })}
|
||||||
if !m.cacheDirty {
|
if m.cacheDirty && m.cachePath != "" {
|
||||||
return next
|
|
||||||
}
|
|
||||||
m.cacheDirty = false
|
m.cacheDirty = false
|
||||||
f, path := m.cacheSnapshot(), m.cachePath
|
f, path := m.cacheSnapshot(), m.cachePath
|
||||||
return tea.Batch(next, func() tea.Msg { return persistedMsg{writeCacheFile(path, f)} })
|
cmds = append(cmds, 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
|
// 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) {
|
func (m *Model) handlePersisted(msg persistedMsg) {
|
||||||
if msg.err != nil {
|
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