A release comes every few minutes, so a downloaded update was always
waiting and the pill (window and tray panel) never went out. /api/update
now says "quiet" while this version has been behind for less than 3 days
(update.Quiet, the Stable channel's soak; counted from the first newer
version seen, kept in update-behind.json for the version running), and the
pill stays away. An urgent release ("**Urgent release:**" in the latest's
notes or any release between, fetched once per check) lights it at once and
a dismissal does not hide it. The x dismissal now also starts the quiet over,
so the pill is not back with the next release. Settings > Version, the tray's
Restart to update, quit and Restart automatically are unchanged. Plugins'
dot is for plugins that do not update by themselves; left alone.
Run (mote): go test ./internal/update (ok), go test -run Update|Asset|Budget|Script ./internal/gui (ok),
gofmt, go vet darwin / linux nogui / windows clean, update-quiet.test.cjs 21/21 in chromium and
webkit across en, zh, zh-TW, ja, de, panel and window. Broken by hand: dropping
!u.quiet in app.js (11 red), forcing Quiet=false in jsonIn (TestUpdateQuietUntilBehindAWhile red).
Not tried: a real 3-day wait, and the urgent range lookup against the live site.
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package gui
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/update"
|
|
)
|
|
|
|
// "红点都快焊死了" (certhon520 and others on X): with a release every few
|
|
// minutes, a downloaded update was always there and the header's pill was
|
|
// always lit. /api/update says quiet for a version not behind for long,
|
|
// and not quiet for an urgent one.
|
|
func TestUpdateQuietUntilBehindAWhile(t *testing.T) {
|
|
h := t.TempDir()
|
|
t.Setenv("HOME", h)
|
|
t.Setenv("USERPROFILE", h)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
|
t.Setenv("APPDATA", filepath.Join(h, "AppData"))
|
|
was := Version
|
|
Version = "0.1.100"
|
|
t.Cleanup(func() { Version = was })
|
|
now := time.Now()
|
|
for _, c := range []struct {
|
|
name string
|
|
b update.Behind
|
|
state string
|
|
quiet bool
|
|
}{
|
|
{"just found", update.Behind{Base: "0.1.100", Since: now.Add(-time.Hour)}, "ready", true},
|
|
{"behind for days", update.Behind{Base: "0.1.100", Since: now.Add(-update.Quiet - time.Minute)}, "ready", false},
|
|
{"urgent at once", update.Behind{Base: "0.1.100", Since: now, Urgent: "0.1.104"}, "ready", false},
|
|
{"found, held download", update.Behind{Base: "0.1.100", Since: now}, "found", true},
|
|
{"up to date says nothing", update.Behind{Base: "0.1.100", Since: now}, "latest", false},
|
|
} {
|
|
u := &updater{state: c.state, behind: c.b, latest: &update.Release{Version: "0.1.105"}}
|
|
if got := u.json().Quiet; got != c.quiet {
|
|
t.Errorf("%s: quiet %v, want %v", c.name, got, c.quiet)
|
|
}
|
|
}
|
|
}
|