feat: update settings move under updates, with an interval
updates.autoCheck (was updateCheck) and updates.updateSources (was releases) sit together with updates.autoCheckInterval, a duration (24h by default) for how often lazysecrets looks for a newer release on its own.
This commit is contained in:
9 files changed
+66
-34
No files matched your search
@@ -117,9 +117,11 @@ type Options struct {
|
||||
// Keys, if set, replaces the default keymap (keys.Map.Apply).
|
||||
Keys *keys.Map
|
||||
// Updater, if set, finds and installs newer releases (U); with
|
||||
// UpdateCheck, lazysecrets also looks once a day on its own.
|
||||
// UpdateCheck, lazysecrets also looks on its own at startup, at most
|
||||
// once per UpdateEvery (0 for a day).
|
||||
Updater *Updater
|
||||
UpdateCheck bool
|
||||
UpdateEvery time.Duration
|
||||
// HandlerSetup, if set, offers to set up the link handler at startup.
|
||||
HandlerSetup *HandlerSetup
|
||||
// NoHistory stops counting uses of items for the Recent list.
|
||||
@@ -236,6 +238,7 @@ type Model struct {
|
||||
|
||||
updater *Updater
|
||||
updateCheck bool
|
||||
updateEvery time.Duration
|
||||
fetchOnStart bool // look for a newer release in Init
|
||||
newer *update.Release // a newer release to offer
|
||||
updated string // the release installed, waiting for a restart
|
||||
@@ -427,7 +430,10 @@ func New(providers []provider.Provider, opts Options) Model {
|
||||
m.revealTimeout, m.hideOnBlur = opts.RevealTimeout, opts.HideOnBlur
|
||||
m.expiryWarning = opts.ExpiryWarning
|
||||
m.handlerSetup = opts.HandlerSetup
|
||||
m.updater, m.updateCheck = opts.Updater, opts.UpdateCheck
|
||||
m.updater, m.updateCheck, m.updateEvery = opts.Updater, opts.UpdateCheck, opts.UpdateEvery
|
||||
if m.updateEvery == 0 {
|
||||
m.updateEvery = updateEvery
|
||||
}
|
||||
m.startUpdateCheck()
|
||||
m.askHandler = opts.HandlerSetup != nil && !m.store.Flag(flagNoHandlerPrompt)
|
||||
m.settle = opts.LoadDelay
|
||||
|
||||
@@ -20,7 +20,8 @@ type Updater struct {
|
||||
}
|
||||
|
||||
// updateEvery is how often lazysecrets looks for a newer release on its
|
||||
// own; within that, the last answer (in the state file) is used.
|
||||
// own unless the config says otherwise; within that, the last answer (in
|
||||
// the state file) is used.
|
||||
const updateEvery = 24 * time.Hour
|
||||
|
||||
type updateMsg struct {
|
||||
@@ -35,14 +36,14 @@ type installedMsg struct {
|
||||
}
|
||||
|
||||
// startUpdateCheck sets up the startup look for a newer release: the
|
||||
// state file's answer when it looked less than a day ago, else a quiet
|
||||
// state file's answer when it looked within updateEvery, else a quiet
|
||||
// look at the server (fetchOnStart, for Init).
|
||||
func (m *Model) startUpdateCheck() {
|
||||
if m.updater == nil || !m.updateCheck {
|
||||
return
|
||||
}
|
||||
last := m.store.UpdateCheck()
|
||||
if m.now().Sub(last.At) < updateEvery {
|
||||
if m.now().Sub(last.At) < m.updateEvery {
|
||||
m.offer(update.Release{Tag: last.Tag, Body: last.Notes, URL: last.URL})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -83,6 +83,12 @@ func TestUpdate(t *testing.T) {
|
||||
if f2.asked != 1 {
|
||||
t.Errorf("asked %d times a day later", f2.asked)
|
||||
}
|
||||
// With autoCheckInterval: 1h, two hours on is long enough.
|
||||
mem.SetUpdateCheck(store.UpdateCheck{At: time.Now().Add(-2 * time.Hour), Tag: "v0.2.0"})
|
||||
newDriverOpts(t, Options{Version: "0.1.1", Updater: f2.updater(), UpdateCheck: true, UpdateEvery: time.Hour, Store: mem})
|
||||
if f2.asked != 2 {
|
||||
t.Errorf("asked %d times, want a look after the hour", f2.asked)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateAsked(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user