Documentation
¶
Overview ¶
Package updates is the in-app updater of the ActNow apps, on top of MyGo's updater API (mygo.Updater.Check, Update.Install, App.Relaunch) without MyGo's update window: the apps draw their own panel.
A Manager runs the state machine — idle → checking → available → downloading (progress) → ready (restart to finish) or failed — reads the release notes in the app's language from actnow.dev's changelog API (English where a release has no translation), and marks updates that need a paid licence for early-access (whitelist) users: at or above the app's paid_since, an early-access code stops working, so the user is told and may keep the version they have (docs/licensing.md §7).
actnowkit does not depend on MyGo: the app passes MyGo's updater as Funcs (see README).
Index ¶
- Variables
- func NotesLocale(language string) string
- type Config
- type Entry
- type Funcs
- type History
- type HistoryClient
- type Manager
- func (m *Manager) AutoCheck(ctx context.Context, interval time.Duration, enabled func() bool)
- func (m *Manager) Check(ctx context.Context) State
- func (m *Manager) Dismiss()
- func (m *Manager) History(ctx context.Context) (*History, error)
- func (m *Manager) Install(ctx context.Context, acceptPaid bool) State
- func (m *Manager) LastHistory() *History
- func (m *Manager) Restart() error
- func (m *Manager) State() State
- func (m *Manager) Subscribe(fn func(State)) (unsubscribe func())
- type Phase
- type Release
- type State
- type Updater
Constants ¶
This section is empty.
Variables ¶
var ( TextUpdateAvailable = family.Text{EN: "Update available", ZH: "有新版本"} TextNewVersion = family.Text{EN: "{app} {version} is available", ZH: "{app} {version} 已发布"} TextInstall = family.Text{EN: "Download and Install", ZH: "下载并安装"} TextDownloading = family.Text{EN: "Downloading… {percent}", ZH: "正在下载… {percent}"} TextRestart = family.Text{EN: "Restart to Finish the Update", ZH: "重新启动以完成更新"} TextLater = family.Text{EN: "Later", ZH: "稍后"} TextKeepVersion = family.Text{EN: "Keep This Version", ZH: "继续使用当前版本"} TextUpToDate = family.Text{EN: "{app} is up to date ({version})", ZH: "{app} 已是最新版本({version})"} TextChecking = family.Text{EN: "Checking for updates…", ZH: "正在检查更新…"} TextCheckNow = family.Text{EN: "Check for Updates", ZH: "检查更新"} TextFailed = family.Text{EN: "The update did not install: {error}. {app} is unchanged.", ZH: "更新没有安装成功:{error}。{app} 未做任何改动。"} TextCheckFailed = family.Text{EN: "Cannot check for updates: {error}", ZH: "无法检查更新:{error}"} TextChangelog = family.Text{EN: "Changelog", ZH: "更新日志"} TextAutoCheck = family.Text{EN: "Check for updates automatically", ZH: "自动检查更新"} TextBetaUpdates = family.Text{EN: "Get beta updates", ZH: "接收测试版更新"} TextNotesInEnglish = family.Text{EN: "", ZH: "这个版本暂无中文说明,以下为英文。"} // TextNeedsPaid is licence.TextUpdateNeedsPaid, for the update panel. TextNeedsPaid = family.Text{ EN: "This update needs a paid licence: after updating, your early-access code will no longer work. You can keep the version you have.", ZH: "这个更新需要付费授权,更新后你的体验码将不能继续使用。你也可以继续使用当前版本。", } TextInstallAnyway = family.Text{EN: "Update Anyway", ZH: "仍然更新"} )
Reference texts of the update UI, in English and Simplified Chinese. Placeholders: {app}, {version}, {percent}, {error}.
var ErrBusy = errors.New("updates: busy")
ErrBusy: a check or an install is running.
var ErrNeedsPaidLicence = errors.New("updates: this update needs a paid licence")
ErrNeedsPaidLicence: Install of an update that ends an early-access licence without AcceptPaid.
Functions ¶
func NotesLocale ¶
NotesLocale maps an app's language to a changelog language: zh, zh-CN, zh-Hans… → "zh-Hans"; everything else → "en" (the only two for now).
Types ¶
type Config ¶
type Config struct {
Updater Updater
// Current version of the app.
Current string
// History reads the changelog API (nil: manifest notes only).
History *HistoryClient
// Language: the app's language now ("zh-Hans", "en"); called at each
// check, so a language change applies to the next one.
Language func() string
// Beta: the user gets beta updates (the history includes betas).
Beta func() bool
// Licence: the app's licence state (nil for free apps): its edition
// and paid_since decide NeedsPaidLicence.
Licence func() licence.Status
// Restart relaunches the app (mygo.App.Relaunch).
Restart func()
// Log receives one line per step and every failure.
Log func(string)
// Now: time.Now.
Now func() time.Time
}
Config of a Manager.
type Entry ¶
type Entry struct {
Version string `json:"version"`
Channel string `json:"channel"`
// Date: YYYY-MM-DD.
Date string `json:"date"`
// Notes in Markdown, in Locale: the asked language, or English where a
// release has no translation.
Notes string `json:"notes"`
Locale string `json:"locale"`
// RequiresPaidLicence: paid_since is set and this version is at or above
// it (early-access codes do not work with it).
RequiresPaidLicence bool `json:"requiresPaidLicence"`
}
Entry is one release in the changelog history (GET /api/changelog/<app>).
type History ¶
type History struct {
App string `json:"app"`
Locale string `json:"locale"`
PaidSince *string `json:"paidSince"`
Entries []Entry `json:"entries"`
}
History is the changelog of an app in one language.
func (*History) PaidSinceVersion ¶
PaidSinceVersion is the site's paid_since, "" when not set.
type HistoryClient ¶
type HistoryClient struct {
// BaseURL: https://actnow.dev (http only on loopback, for tests).
BaseURL string
App string
// HTTPClient: one with a 20 s timeout.
HTTPClient *http.Client
}
HistoryClient reads the changelog API of actnow.dev.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager runs the update state machine. Safe for concurrent use.
func (*Manager) AutoCheck ¶
AutoCheck checks now and then every interval (24 h by default) while enabled() says so (the app's "check automatically" setting), until ctx ends. A check is skipped while one runs or an update is downloading.
func (*Manager) Check ¶
Check asks the feed for an update and, when there is one, its notes in the app's language and whether it needs a paid licence.
func (*Manager) Dismiss ¶
func (m *Manager) Dismiss()
Dismiss returns to Idle from Available, UpToDate or Failed (the user closed the panel or chose to keep the version they have).
func (*Manager) History ¶
History is the changelog in the app's language (Settings → About → Changelog): fetched at each call.
func (*Manager) Install ¶
Install downloads and installs the available update (progress in State.Downloaded/Total). An update that needs a paid licence for an early-access user installs only with acceptPaid. On failure the app is unchanged (MyGo puts the old bundle back if the swap fails) and the State is Failed; Check again to retry.
func (*Manager) LastHistory ¶
LastHistory is the changelog fetched by the last check (nil if none).
type Release ¶
type Release struct {
Version string
// Notes from the update manifest (English, MyGo's CHANGELOG section).
Notes string
Date time.Time
// Install downloads, verifies and installs the update (MyGo's
// Update.Install); the running app is not affected until Restart.
Install func(ctx context.Context, progress func(done, total int64)) error
}
Release is an available update, as MyGo's updater gives it.
type State ¶
type State struct {
Phase Phase
// Current is the running version.
Current string
// Release: the available (or installed, when Ready) update.
Release *Release
// Notes of Release in the app's language (Markdown), and its language.
Notes string
NotesLocale string
// NeedsPaidLicence: the user has an early-access licence and this
// update is at or above paid_since: after it the code stops working.
// Show licence.TextUpdateNeedsPaid; Install needs AcceptPaid.
NeedsPaidLicence bool
PaidSince string
// Downloaded and Total bytes while Downloading.
Downloaded, Total int64
// Err and the step it happened in ("check", "download") when Failed.
Err error
Step string
// CheckedAt: the last check.
CheckedAt time.Time
}
State is what the update UI shows.