The site now offers Stable's downloads, but the app's Update channel is Every version until changed, so a Stable install was offered the newest at its first check. Before that check, a fresh install (no version run before and magpie's folder new, from whatsNew.start) asks the feed for Stable's version and the newest; when it is Stable's and a newer one is out, settings take "updateChannel": "stable" (settings.TakeStable, under the file lock, keeping a channel already set). A feed that can't be read is unknown and asked again at the next check. A version that is both Stable's and the newest stays on Every version: its download can't be told apart. update.LatestStable never falls back to GitHub. docs/reference.md and the privacy pages (en, zh, ja, llms-full.txt) say a fresh install asks ?channel=stable once. Old installs: nothing changes for them. Until a release with this becomes Stable, a Stable download (0.1.3078 today) is still offered the newest unless Settings → Update channel is set to Stable. Run at 936c70756, on mote: gofmt -l internal/ clean; go vet (darwin), GOOS=linux and GOOS=windows go vet of internal/gui, update, settings ok; go test -count=1 ./internal/update ./internal/settings ./internal/gui ok (gui 99.9s). TestFreshStableInstallStaysOnStable goes red (2 subtests) with the takeStable call removed (broken by hand, on mica). llms-full.txt regenerated and current. Not run: the full go test ./... (mote and mica each had several suites queued on the lock); not tried with a real Stable install.
65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
package gui
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"sync/atomic"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
"github.com/yetone/magpie/internal/update"
|
|
)
|
|
|
|
// A fresh install of the Stable channel's version stays on Stable
|
|
// (fishmagic80 on X). usemagpie.ai offers Stable's downloads beside the
|
|
// newest's, and Settings' Update channel is every version until changed,
|
|
// so an app put in from a Stable download was offered the newest at its
|
|
// first check. Before that check, a fresh install (whatsNew.start: no
|
|
// version run before, and magpie's folder new) asks the feed for Stable's
|
|
// version; when it is this one and a newer one is out, the channel becomes
|
|
// Stable. A channel already set is kept, and so is every version when
|
|
// this one is also the newest, where the download can't be told apart.
|
|
|
|
// freshInstall: this run is magpie's first here, and the channel isn't
|
|
// settled yet. A feed that can't be read leaves it for the next check.
|
|
var freshInstall atomic.Bool
|
|
|
|
// latestStable and latestEvery are update's; tests stand in for them.
|
|
var (
|
|
latestStable = update.LatestStable
|
|
latestEvery = func(ctx context.Context) (*update.Release, error) { return update.LatestEvery(ctx, "") }
|
|
)
|
|
|
|
// takeStable runs before an update check reads the channel.
|
|
func takeStable(ctx context.Context) {
|
|
if !freshInstall.Load() {
|
|
return
|
|
}
|
|
if !update.Released(Version) || settings.Load().UpdateChannel != "" {
|
|
freshInstall.Store(false)
|
|
return
|
|
}
|
|
st, err := latestStable(ctx)
|
|
if err != nil {
|
|
log.Println("stable on a fresh install:", err) // unknown: asked again next check
|
|
return
|
|
}
|
|
if st.Version != Version {
|
|
freshInstall.Store(false)
|
|
return
|
|
}
|
|
every, err := latestEvery(ctx)
|
|
if err != nil {
|
|
log.Println("stable on a fresh install:", err)
|
|
return
|
|
}
|
|
freshInstall.Store(false)
|
|
if !update.Newer(every.Version, Version) {
|
|
return
|
|
}
|
|
if took, err := settings.TakeStable(); err != nil {
|
|
log.Println("stable on a fresh install:", err)
|
|
} else if took {
|
|
log.Printf("a fresh install of Stable's %s: the update channel is Stable", Version)
|
|
}
|
|
}
|