update: a fresh install of Stable's version stays on Stable (fishmagic80 on X)
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.
This commit is contained in:
@@ -3513,6 +3513,14 @@ keeps it and waits until Stable passes it. While it waits, the Version
|
||||
row says *Up to date on Stable*, names the newest version out on Every
|
||||
version, and offers to switch to Every version.
|
||||
|
||||
The site's downloads offer Stable's version beside the newest
|
||||
(`usemagpie.ai/download/stable/<platform>`). A fresh install of it (no
|
||||
magpie run on this computer before) takes Stable before its first update
|
||||
check, so it isn't offered the newest at once: it asks the feed for
|
||||
Stable's version and the newest, and when it is Stable's and a newer one
|
||||
is out, sets `"updateChannel": "stable"`. A channel you set is kept, and a
|
||||
version that is both Stable's and the newest stays on Every version.
|
||||
|
||||
The update feed works this out from the release list
|
||||
(`https://usemagpie.ai/api/latest?channel=stable`); nothing is promoted
|
||||
by hand. A release is urgent when its notes have a line that starts with
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/update"
|
||||
)
|
||||
|
||||
// A fresh install of Stable's version stays on Stable (fishmagic80 on X):
|
||||
// usemagpie.ai's Stable download, 0.1.11, put in where magpie never ran,
|
||||
// takes Settings' Update channel Stable before its first check, so that
|
||||
// check finds nothing newer and 0.1.12 isn't offered. The newest's
|
||||
// download, an install magpie ran in before, a version that is both
|
||||
// Stable's and the newest, and a feed that can't be read leave the
|
||||
// channel on every version.
|
||||
func TestFreshStableInstallStaysOnStable(t *testing.T) {
|
||||
stableV, newest := "0.1.11", "0.1.12"
|
||||
var down atomic.Bool
|
||||
var asked atomic.Int32
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
asked.Add(1)
|
||||
if down.Load() {
|
||||
http.Error(w, "down", 502)
|
||||
return
|
||||
}
|
||||
v := newest
|
||||
if r.URL.Query().Get("channel") == "stable" {
|
||||
v = stableV
|
||||
}
|
||||
json.NewEncoder(w).Encode(update.Release{Version: v})
|
||||
}))
|
||||
defer srv.Close()
|
||||
t.Setenv("MAGPIE_UPDATE_FEED", srv.URL)
|
||||
oldV := Version
|
||||
defer func() { Version = oldV }()
|
||||
o := updates
|
||||
defer func() { updates = o }()
|
||||
defer freshInstall.Store(false)
|
||||
|
||||
// start is a first run of version in a new magpie folder, or (used)
|
||||
// one that held settings before this run; then the first check
|
||||
run := func(t *testing.T, version string, used bool) updateJSON {
|
||||
t.Helper()
|
||||
sandboxHome(t)
|
||||
Version = version
|
||||
if used {
|
||||
s := settings.Load()
|
||||
s.Theme = "dark"
|
||||
if err := settings.Save(s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
old := started.Add(-time.Hour)
|
||||
if err := os.Chtimes(filepath.Join(settings.Dir(), "settings.json"), old, old); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
(&whatsNew{}).start()
|
||||
updates = &updater{}
|
||||
updates.check()
|
||||
return updates.json()
|
||||
}
|
||||
|
||||
t.Run("the Stable download", func(t *testing.T) {
|
||||
j := run(t, "0.1.11", false)
|
||||
if got := settings.Load().UpdateChannel; got != settings.UpdateStable {
|
||||
t.Fatalf("channel %q", got)
|
||||
}
|
||||
if j.State != "latest" || j.Latest == newest {
|
||||
t.Fatalf("offered the newest: %+v", j)
|
||||
}
|
||||
if freshInstall.Load() {
|
||||
t.Fatal("still asks at the next check")
|
||||
}
|
||||
})
|
||||
t.Run("the newest's download", func(t *testing.T) {
|
||||
run(t, "0.1.12", false)
|
||||
if got := settings.Load().UpdateChannel; got != "" {
|
||||
t.Fatalf("channel %q", got)
|
||||
}
|
||||
})
|
||||
t.Run("magpie ran here before", func(t *testing.T) {
|
||||
before := asked.Load()
|
||||
run(t, "0.1.11", true)
|
||||
if got := settings.Load().UpdateChannel; got != "" {
|
||||
t.Fatalf("channel %q", got)
|
||||
}
|
||||
if n := asked.Load() - before; n != 1 {
|
||||
t.Fatalf("the feed was asked %d times, not once for the check itself", n)
|
||||
}
|
||||
})
|
||||
t.Run("Stable's is the newest too", func(t *testing.T) {
|
||||
stableV = newest
|
||||
defer func() { stableV = "0.1.11" }()
|
||||
run(t, newest, false)
|
||||
if got := settings.Load().UpdateChannel; got != "" {
|
||||
t.Fatalf("channel %q", got)
|
||||
}
|
||||
})
|
||||
t.Run("the feed down is unknown, asked again", func(t *testing.T) {
|
||||
down.Store(true)
|
||||
run(t, "0.1.11", false)
|
||||
if got := settings.Load().UpdateChannel; got != "" {
|
||||
t.Fatalf("channel %q on a failed read", got)
|
||||
}
|
||||
if !freshInstall.Load() {
|
||||
t.Fatal("a failed read settled it")
|
||||
}
|
||||
down.Store(false)
|
||||
updates.check()
|
||||
if got := settings.Load().UpdateChannel; got != settings.UpdateStable {
|
||||
t.Fatalf("the next check: channel %q", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -491,6 +491,7 @@ func (u *updater) run() {
|
||||
ctx := context.Background()
|
||||
cctx, cancel := context.WithTimeout(ctx, checkWait)
|
||||
defer cancel()
|
||||
takeStable(cctx) // a fresh install of Stable's version stays on Stable
|
||||
s := settings.Load()
|
||||
u.mu.Lock()
|
||||
lang := u.lang
|
||||
|
||||
@@ -154,7 +154,9 @@ func (n *whatsNew) start() {
|
||||
dir := settings.Dir()
|
||||
b, _ := os.ReadFile(filepath.Join(dir, lastRunFile))
|
||||
last := strings.TrimSpace(string(b))
|
||||
after, show := update.ShowNotes(last, Version, last == "" && usedBefore(dir))
|
||||
used := usedBefore(dir)
|
||||
after, show := update.ShowNotes(last, Version, last == "" && used)
|
||||
freshInstall.Store(last == "" && !used) // takeStable
|
||||
// a restart to update into this version: its notes wait in Settings
|
||||
mark := filepath.Join(dir, updatedInAppFile)
|
||||
m, err := os.ReadFile(mark)
|
||||
|
||||
@@ -2360,6 +2360,24 @@ func SetRouterAllTools(on bool) error {
|
||||
return save(s, true)
|
||||
}
|
||||
|
||||
// TakeStable puts UpdateChannel on Stable when no channel is set, from
|
||||
// what the file holds now: a fresh install of the Stable version (the
|
||||
// site's Stable download) stays on Stable. A channel already set is the
|
||||
// user's, and is kept. It says whether it changed the channel. A settings
|
||||
// file that can't be read is left as it is, with the error.
|
||||
func TakeStable() (bool, error) {
|
||||
defer lockFile()()
|
||||
s, err := loadChecked()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if s.UpdateChannel != "" {
|
||||
return false, nil
|
||||
}
|
||||
s.UpdateChannel = UpdateStable
|
||||
return true, save(s, false)
|
||||
}
|
||||
|
||||
// EditCheckinOff changes CheckinOff alone, as edit returns it from what the
|
||||
// file holds now, so a save elsewhere from an older snapshot isn't undone.
|
||||
// A settings file that can't be read is left as it is, with the error.
|
||||
|
||||
@@ -143,6 +143,21 @@ func LatestEvery(ctx context.Context, lang string) (*Release, error) {
|
||||
return latestAt(ctx, withLang(Feed(), lang), lang)
|
||||
}
|
||||
|
||||
// LatestStable is the Stable channel's release, whatever Settings'
|
||||
// channel: what a fresh install compares itself with, to stay on Stable
|
||||
// when it is Stable's version (the site's Stable download). Only the site
|
||||
// knows it, so a failed feed is never answered from GitHub.
|
||||
func LatestStable(ctx context.Context) (*Release, error) {
|
||||
u, err := url.Parse(Feed())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q := u.Query()
|
||||
q.Set("channel", settings.UpdateStable)
|
||||
u.RawQuery = q.Encode()
|
||||
return latestFrom(ctx, u.String(), "")
|
||||
}
|
||||
|
||||
func latestAt(ctx context.Context, feed, lang string) (*Release, error) {
|
||||
if githubOnly() {
|
||||
return githubLatest(ctx, lang)
|
||||
|
||||
@@ -234,7 +234,7 @@
|
||||
<h2 id="site"><a class="anchor" href="#site">usemagpie.ai に見えるもの</a></h2>
|
||||
<p>magpie はプライバシー設定にかかわらず、どのアプリも自分の更新サーバーに尋ねるのと同じように、自分のサイトにいくつか尋ねます。どのリクエストにもインストール ID やアカウントは付きません。</p>
|
||||
<ul>
|
||||
<li><code>/api/latest</code>:更新情報。<code>noAutoUpdate</code> がオンでなければ 6 時間ごと。<code>?lang=</code> であなたの言語のノートを取ります。<span class="ui">設定</span> → <span class="ui">情報</span> → <span class="ui">アップデートチャネル</span>が安定版なら <code>?channel=stable</code> も付けます。どちらもあなたが誰かは含みません。<code>/api/notes</code> は更新後の「新機能」です。</li>
|
||||
<li><code>/api/latest</code>:更新情報。<code>noAutoUpdate</code> がオンでなければ 6 時間ごと。<code>?lang=</code> であなたの言語のノートを取ります。<span class="ui">設定</span> → <span class="ui">情報</span> → <span class="ui">アップデートチャネル</span>が安定版なら <code>?channel=stable</code> も付けます。新しくインストールした magpie も一度 <code>?channel=stable</code> を尋ね、自分が安定版なら安定版にとどまります。どちらもあなたが誰かは含みません。<code>/api/notes</code> は更新後の「新機能」です。</li>
|
||||
<li><code>/files/<バージョン>/<ファイル></code>:更新とインストーラがダウンロードするリリースファイルで、Cloudflare R2 から配信されます。サイトにないファイルは github.com へ転送されます。何も計測しません。</li>
|
||||
<li><code>/api/partners</code>:プロバイダー追加シートのパートナー一覧。6 時間ごと。パートナーが載っている間、10 回に 1 回の取得を Cloudflare が示す国とともに <code>magpie partners fetch</code> として数えます。</li>
|
||||
<li><code>/go/<パートナー>/site</code> と <code>/go/<パートナー>/keys</code>:パートナーの公式サイトとキーのページへのリンクをブラウザーで開くと、移動の前に <code>magpie partner go</code>(どのパートナーか、どのリンクか、地域、国)として数えます。</li>
|
||||
|
||||
@@ -234,7 +234,7 @@
|
||||
<h2 id="site"><a class="anchor" href="#site">What usemagpie.ai sees</a></h2>
|
||||
<p>magpie asks its own site for a few things, whatever the privacy settings say, as any app asks its update server. None of these requests carries the install id or an account.</p>
|
||||
<ul>
|
||||
<li><code>/api/latest</code>: the update feed, every 6 hours unless <code>noAutoUpdate</code> is on, with <code>?lang=</code> for the notes in your language, and <code>?channel=stable</code> when <span class="ui">Settings</span> → <span class="ui">About</span> → <span class="ui">Update channel</span> is Stable. Neither says who you are. <code>/api/notes</code> gives What’s new after an update.</li>
|
||||
<li><code>/api/latest</code>: the update feed, every 6 hours unless <code>noAutoUpdate</code> is on, with <code>?lang=</code> for the notes in your language, and <code>?channel=stable</code> when <span class="ui">Settings</span> → <span class="ui">About</span> → <span class="ui">Update channel</span> is Stable; a fresh install asks <code>?channel=stable</code> once too, to stay on Stable when it is Stable’s version. Neither says who you are. <code>/api/notes</code> gives What’s new after an update.</li>
|
||||
<li><code>/files/<version>/<file></code>: the release files an update and the installer download, served from Cloudflare R2. A file the site doesn’t hold is sent on to github.com. Nothing is counted.</li>
|
||||
<li><code>/api/partners</code>: the add sheet’s partner list, every 6 hours. One fetch in ten is counted as a <code>magpie partners fetch</code> event, with the country Cloudflare gives, while a partner is listed.</li>
|
||||
<li><code>/go/<partner>/site</code> and <code>/go/<partner>/keys</code>: a partner’s website and key-page links, opened in your browser, are counted (the partner, which link, a region, a country) as <code>magpie partner go</code> before you are sent on.</li>
|
||||
|
||||
@@ -234,7 +234,7 @@
|
||||
<h2 id="site"><a class="anchor" href="#site">usemagpie.ai 能看到什么</a></h2>
|
||||
<p>magpie 会向自己的网站请求几样东西,不受隐私设置影响,就像任何应用访问自己的更新服务器。这些请求都不带安装 ID 或账号。</p>
|
||||
<ul>
|
||||
<li><code>/api/latest</code>:更新信息,每 6 小时一次(开了 <code>noAutoUpdate</code> 则不请求),带 <code>?lang=</code> 取对应语言的说明;<span class="ui">设置</span> → <span class="ui">关于</span> → <span class="ui">更新渠道</span>选了稳定版时还带 <code>?channel=stable</code>。两者都不含你是谁。<code>/api/notes</code> 在更新后给出“新功能”。</li>
|
||||
<li><code>/api/latest</code>:更新信息,每 6 小时一次(开了 <code>noAutoUpdate</code> 则不请求),带 <code>?lang=</code> 取对应语言的说明;<span class="ui">设置</span> → <span class="ui">关于</span> → <span class="ui">更新渠道</span>选了稳定版时还带 <code>?channel=stable</code>;新安装的 magpie 也会请求一次 <code>?channel=stable</code>,若自己就是稳定版,便留在稳定版。两者都不含你是谁。<code>/api/notes</code> 在更新后给出“新功能”。</li>
|
||||
<li><code>/files/<版本>/<文件></code>:更新和安装脚本下载的发布文件,由 Cloudflare R2 提供;站点上没有的文件会转到 github.com。不做任何统计。</li>
|
||||
<li><code>/api/partners</code>:添加供应商页的合作伙伴列表,每 6 小时一次。在有合作伙伴上架时,每十次拉取记一次 <code>magpie partners fetch</code> 事件,附 Cloudflare 给出的国家。</li>
|
||||
<li><code>/go/<合作伙伴>/site</code> 和 <code>/go/<合作伙伴>/keys</code>:在浏览器里打开合作伙伴的官网和 Key 页面链接时,先记一次 <code>magpie partner go</code>(哪个合作伙伴、哪个链接、地区、国家),再跳转。</li>
|
||||
|
||||
@@ -12147,7 +12147,7 @@ The app writes a log of what it did, `app.log`, in `~/Library/Logs/magpie` on ma
|
||||
|
||||
magpie asks its own site for a few things, whatever the privacy settings say, as any app asks its update server. None of these requests carries the install id or an account.
|
||||
|
||||
- `/api/latest`: the update feed, every 6 hours unless `noAutoUpdate` is on, with `?lang=` for the notes in your language, and `?channel=stable` when Settings → About → Update channel is Stable. Neither says who you are. `/api/notes` gives What’s new after an update.
|
||||
- `/api/latest`: the update feed, every 6 hours unless `noAutoUpdate` is on, with `?lang=` for the notes in your language, and `?channel=stable` when Settings → About → Update channel is Stable; a fresh install asks `?channel=stable` once too, to stay on Stable when it is Stable’s version. Neither says who you are. `/api/notes` gives What’s new after an update.
|
||||
- `/files/<version>/<file>`: the release files an update and the installer download, served from Cloudflare R2. A file the site doesn’t hold is sent on to github.com. Nothing is counted.
|
||||
- `/api/partners`: the add sheet’s partner list, every 6 hours. One fetch in ten is counted as a `magpie partners fetch` event, with the country Cloudflare gives, while a partner is listed.
|
||||
- `/go/<partner>/site` and `/go/<partner>/keys`: a partner’s website and key-page links, opened in your browser, are counted (the partner, which link, a region, a country) as `magpie partner go` before you are sent on.
|
||||
|
||||
Reference in New Issue
Block a user