updates

package
v0.23.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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}.

View Source
var ErrBusy = errors.New("updates: busy")

ErrBusy: a check or an install is running.

View Source
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

func NotesLocale(language string) string

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 Funcs

type Funcs struct {
	EnabledFunc func() bool
	CheckFunc   func(ctx context.Context) (*Release, error)
}

Funcs adapts functions (MyGo's) to Updater.

func (Funcs) Check

func (f Funcs) Check(ctx context.Context) (*Release, error)

func (Funcs) Enabled

func (f Funcs) Enabled() bool

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) Find

func (h *History) Find(version string) *Entry

Find returns the entry of a version, or nil.

func (*History) PaidSinceVersion

func (h *History) PaidSinceVersion() string

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.

func (*HistoryClient) Fetch

func (c *HistoryClient) Fetch(ctx context.Context, language string, beta bool, limit int) (*History, error)

Fetch gets the history in a language (NotesLocale of the app's language), stable releases or, with beta, betas too; limit 0 = 50.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager runs the update state machine. Safe for concurrent use.

func New

func New(cfg Config) *Manager

New makes a Manager; Disabled when the updater is.

func (*Manager) AutoCheck

func (m *Manager) AutoCheck(ctx context.Context, interval time.Duration, enabled func() bool)

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

func (m *Manager) Check(ctx context.Context) State

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

func (m *Manager) History(ctx context.Context) (*History, error)

History is the changelog in the app's language (Settings → About → Changelog): fetched at each call.

func (*Manager) Install

func (m *Manager) Install(ctx context.Context, acceptPaid bool) State

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

func (m *Manager) LastHistory() *History

LastHistory is the changelog fetched by the last check (nil if none).

func (*Manager) Restart

func (m *Manager) Restart() error

Restart relaunches the app into the installed update (Ready only).

func (*Manager) State

func (m *Manager) State() State

State now.

func (*Manager) Subscribe

func (m *Manager) Subscribe(fn func(State)) (unsubscribe func())

Subscribe calls fn with every new state (from any goroutine: the app moves it to its UI thread); the returned func stops it.

type Phase

type Phase string

Phase of the state machine.

const (
	Idle        Phase = "idle"
	Disabled    Phase = "disabled" // development builds, read-only installs
	Checking    Phase = "checking"
	UpToDate    Phase = "up_to_date"
	Available   Phase = "available"
	Downloading Phase = "downloading"
	Ready       Phase = "ready" // installed: restart to finish
	Failed      Phase = "failed"
)

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.

func (State) Fraction

func (s State) Fraction() float64

Fraction of the download (0–1).

type Updater

type Updater interface {
	// Enabled: the build has updates and can write where it is installed.
	Enabled() bool
	// Check returns the newer release, or nil when up to date.
	Check(ctx context.Context) (*Release, error)
}

Updater is what the Manager needs of MyGo.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL