update

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 39 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 update is how the app updates itself.

Every release attaches a manifest beside its zip: the manifest's format, the message its Ed25519 signature covers, the names of the release's files, and the checks that make a manifest and the zip it names trustworthy live here. The release targets in magefiles build and verify releases with them, so the packaging and the app never disagree on what a valid release is.

The Engine checks the latest release, downloads its zip into the Cache, checks it against the manifest and the key the build trusts (ReleaseKey for a release; a rehearsal's own), and installs it through the Installer the desktop shell attaches, after backing the database up and letting the quit through. What a build does is its Flavor's: a source build never updates. The Worker runs the timed checks, the Service is the window's face, and the next start reads how the restart went (JustUpdated, InstallFailed) and cleans up what the desktop runtime's updater leaves behind.

It imports no service and speaks no HTTP: the app reads the manifest and the zip through a Feed, which core adapts over the GitHub client's release downloads, and keeps its state in the update.* preferences through Memory.

Index

Constants

View Source
const (
	// KeyLastCheck is when the last check that reached the releases ended, as RFC 3339.
	KeyLastCheck = "update.lastCheck"

	// KeyNotified is the last version a notification was sent for (or that a manual check
	// showed), so each version is told once.
	KeyNotified = "update.notified"

	// KeyBannerHidden is the banner hidden with Later: {version, until}. A newer version
	// shows it again.
	KeyBannerHidden = "update.bannerHiddenUntil"

	// KeyLastRunRelease is the version the app last ran as, set on every start once the
	// outcome of the last restart is read.
	KeyLastRunRelease = "update.lastRunRelease"

	// KeyPendingInstall is the install a restart began, {from, to, at, pid, sha512}, set
	// just before the app quits for it and read and cleared at the next start.
	KeyPendingInstall = "update.pendingInstall"

	// KeyUninstallable is the updates a restart failed to install for good (each
	// {version, sha512, reason}, the newest few), which are never downloaded or offered
	// again: a later release, or the same version rebuilt, is.
	KeyUninstallable = "update.uninstallable"
)

The update.* preferences this package alone writes: the app's memory of its updates, which a backup never holds. The setting, update.mode, is the settings package's.

View Source
const (
	// FirstCheckAfter is how long after the deferred work starts the first check runs, so
	// a check never lands on the cold start.
	FirstCheckAfter = time.Minute

	// TickEvery is how often the Worker looks whether a check is due. Timers don't advance
	// while a Mac sleeps, so the wall clock decides, at each tick, against CheckEvery.
	TickEvery = 15 * time.Minute

	// CheckEvery is how long after the last check the next is due.
	CheckEvery = 6 * time.Hour

	// DownloadLimit bounds a whole download; GitHub's download hosts stop one that stalls
	// for 30 seconds sooner.
	DownloadLimit = 10 * time.Minute

	// ManifestLimit bounds a read of the latest release's manifest, which holds the one
	// operation while it runs.
	ManifestLimit = time.Minute

	// HideFor is how long Later hides the banner.
	HideFor = 24 * time.Hour

	// BackupReuse is how long a backup a restart took serves a restart tried again, so
	// retries never push out the older backups the restore needs.
	BackupReuse = 10 * time.Minute

	// HelperWindow is how long after a restart the runtime's helper may still be at work
	// (30 seconds waiting for the app to quit, up to 90 checking the new bundle's
	// signature, its swaps and restores): while its log hasn't ended, the start leaves its
	// files, and the record of the install, alone until then.
	HelperWindow = 3 * time.Minute
)

Timing.

View Source
const (
	// Format is the manifest format's version, which the first line of the signed message
	// names. Only a change an older build would misread raises it.
	Format = 1

	// Platform is the build every release ships today: one universal macOS bundle, for
	// Apple silicon and Intel alike.
	Platform = "darwin-universal"

	// ManifestName is the manifest's asset name for Platform: one manifest per operating
	// system, so another system's builds add a file of their own, never a format change.
	ManifestName = "manifest-darwin.json"

	// SumsName is the asset that lists the SHA-256 of the zip and the disk image, for
	// people checking a download by hand; the app never reads it.
	SumsName = "SHA256SUMS"

	// MaxManifestBytes is the largest manifest that is read at all: 16 KiB.
	MaxManifestBytes = 16 << 10

	// MaxFileBytes is the largest zip a manifest may name: 200 MiB.
	MaxFileBytes = 200 << 20
)
View Source
const MoveLimit = 5 * time.Minute

MoveLimit bounds a move to Applications: the copy, and the check of its signature.

View Source
const ReleaseKey = "71FuGzlTtYY5qW/EF5YgEqCObp6akq7xIy6VpIFRhrc=" // gitleaks:allow

ReleaseKey is the Ed25519 public key, base64, that every release's manifest must verify with: the trust root of the app's updates, made with magex app:keygen. Its private half signs each release's manifest in the release workflow, and nowhere else. Changing it takes changing pinnedTrustRoot in releasekey_test.go too, and strands every copy that pins the old key: none of them could verify an update again. Were it empty, a release build would be off and magex app:package would refuse to package a release. It is public, meant to be read by anyone, so the secret scan is told to pass over it.

Variables

View Source
var (
	// ErrPlatform is returned for a manifest of another platform's build.
	ErrPlatform = errors.New("the update is for another platform")

	// ErrPrerelease is returned for a manifest of a prerelease: the app updates to
	// releases alone.
	ErrPrerelease = errors.New("the update is a prerelease")
)
View Source
var (
	// ErrNothingToDownload is returned by Download when no newer version is known.
	ErrNothingToDownload = errors.New("no newer version to download")

	// ErrLocation is returned by Download and Restart while the app runs where it can't
	// replace itself: a translocated copy, a disk image, or a folder the user can't write to.
	ErrLocation = errors.New("the app runs where it can't update itself")
)
View Source
var (
	// ErrInvalid is returned for a manifest that isn't one: not JSON, larger than
	// MaxManifestBytes, or a field out of form.
	ErrInvalid = errors.New("not a valid update manifest")

	// ErrSignature is returned when a manifest's signature does not verify with the key.
	ErrSignature = errors.New("the update manifest's signature does not verify")

	// ErrKey is returned for a key that isn't an Ed25519 key in a form this package reads.
	ErrKey = errors.New("not an Ed25519 key")

	// ErrMismatch is returned when a file's size or SHA-512 differs from its manifest's.
	ErrMismatch = errors.New("the file does not match its update manifest")
)
View Source
var (
	// ErrCantMove is returned by a move where there is nothing to move: the app runs from
	// an Applications folder already, or from no bundle.
	ErrCantMove = errors.New("the app can't be moved from where it runs")

	// ErrNoMover is returned by a move in a build that can't move itself: no desktop
	// runtime attached a Mover.
	ErrNoMover = errors.New("this build can't move itself")

	// ErrMoving is returned by a move while another is under way.
	ErrMoving = errors.New("the app is moving already")

	// ErrUpdating is returned by a move while the app restarts into an update, which goes
	// first: the restart quits the app, and its helper opens the new version. A move while a
	// restart whose quit was held finishes is ErrFinishing too.
	ErrUpdating = errors.New("the app is restarting into an update")

	// ErrTargetTaken is returned by a move when something other than a copy of the app is
	// where it would go: a link, a file, another app, or a folder that isn't one.
	ErrTargetTaken = errors.New("something else is where the app would go")

	// ErrNoCopy is returned by OpenInApplications when no copy of the app is where a move
	// would put it.
	ErrNoCopy = errors.New("no copy of the app is in Applications")

	// ErrMoveFailed is returned by a move whose copy failed, or didn't pass its signature
	// check, and by OpenInApplications for a copy that doesn't pass it.
	ErrMoveFailed = errors.New("the move failed")

	// ErrQuarantined is returned by OpenInApplications for a copy macOS would open from a
	// hidden folder (Mover.Translocates), where it can't update itself.
	ErrQuarantined = errors.New("the copy in Applications is still marked as downloaded")

	// ErrOwnSignature is in the chain of a Mover's Verify that couldn't read the designated
	// requirement of the app that runs, which a copy is checked against: the copy itself
	// was never judged.
	ErrOwnSignature = errors.New("the app's own signature couldn't be read")
)
View Source
var (
	// ErrRunsGoing is returned by a restart the user hasn't confirmed while runs go in the
	// app, which it would stop; a RunsGoingError names them.
	ErrRunsGoing = errors.New("runs are going in the app")

	// ErrNotReady is returned by a restart with no update downloaded and checked.
	ErrNotReady = errors.New("no update is ready to install")

	// ErrBusy is returned by a restart while the update downloads.
	ErrBusy = errors.New("the update is still downloading")

	// ErrNoInstaller is returned by a restart in a build that can't install updates: no
	// desktop runtime attached an Installer.
	ErrNoInstaller = errors.New("this build can't install updates")

	// ErrDamaged is returned by a restart whose downloaded update no longer matches its
	// manifest, or is gone.
	ErrDamaged = errors.New("the downloaded update is damaged")

	// ErrFinishing is returned by a restart while an earlier one finishes: its quit was
	// held, and the app is quitting on its own so the update installs.
	ErrFinishing = errors.New("a restart to update is finishing")

	// ErrOff is returned by what a build that can't update refuses.
	ErrOff = errors.New("updates are off in this build")
)
View Source
var (
	// ErrNoLog is returned by ShowInstallLog when no log of a failed install was kept.
	ErrNoLog = errors.New("no log of the failed update was kept")

	// ErrSettling is returned by Download and Restart while the start isn't settled: the
	// last install, under HelperWindow old, has a helper whose log hasn't ended, which may
	// still be replacing the app.
	ErrSettling = errors.New("the last update may still be finishing")
)
View Source
var ErrNoRelease = errors.New("the latest release has no update manifest")

ErrNoRelease is returned by a Feed whose latest release has no manifest: none is out yet, or one was pulled. It reads as up to date.

View Source
var ErrUninstallable = errors.New("the update failed to install before, the same way it would again")

ErrUninstallable is returned by Download and Restart for an update a restart failed to install for good: it failed its signature check, or couldn't be installed, as it would every time. Its release page is the way to get it.

Functions

func BundleOf

func BundleOf(exe string) string

BundleOf returns the .app bundle the executable at exe runs from, or "" when it runs outside one, as a build from magex app:dev does.

func CheckFile

func CheckFile(m Manifest, r io.Reader) error

CheckFile reads r, the file m names, and fails with ErrMismatch unless it holds exactly m.Size bytes whose SHA-512 is m.SHA512. It reads at most one byte past m.Size, so a file that runs on is refused without being read to its end. Call it only on a manifest Verify accepted: Verify is what holds m.Size to MaxFileBytes, and so bounds the read.

func Digest

func Digest(r io.Reader) (int64, string, error)

Digest reads r to its end and returns how many bytes it held and their SHA-512, as a manifest writes it.

func Encode

func Encode(m Manifest) ([]byte, error)

Encode returns m as the JSON a release attaches: indented, ending in a newline.

func EncodeKey

func EncodeKey(key ed25519.PublicKey) string

EncodeKey writes key as ReleaseKey holds it: its raw 32 bytes in base64.

func EncodePrivateKey

func EncodePrivateKey(key ed25519.PrivateKey) ([]byte, error)

EncodePrivateKey writes key as a PEM block in PKCS#8, which ParsePrivateKey reads.

func FileName

func FileName(platform, version string) string

FileName is the zip's asset name for platform and version, such as <Name>_0.3.0_darwin_universal.zip for Platform.

func ManifestURL

func ManifestURL() string

ManifestURL is where a release build reads the latest release's manifest: GitHub's link to the latest release's asset, which skips drafts and prereleases, and answers 404 while that release has no manifest.

func ParseKey

func ParseKey(text []byte) (ed25519.PublicKey, error)

ParseKey reads an Ed25519 public key from text: the raw 32 bytes in base64, as ReleaseKey holds it, or a PEM block of a public key (PKIX). Space around the text is ignored. It refuses a private key, which only ParsePrivateKey reads, and a point of small order, under which a forged signature verifies for any message.

func ParsePrivateKey

func ParsePrivateKey(text []byte) (ed25519.PrivateKey, error)

ParsePrivateKey reads an Ed25519 private key from a PEM block in PKCS#8, the form EncodePrivateKey writes. Space around the block is ignored, anything else is refused.

func PublicKeyOf

func PublicKeyOf(key ed25519.PrivateKey) ed25519.PublicKey

PublicKeyOf returns the public half of key, or nil for a key of the wrong length.

func ReleaseURL

func ReleaseURL(version string) string

ReleaseURL is the GitHub page of the release of version.

func SignedMessage

func SignedMessage(m Manifest) []byte

SignedMessage is the text a manifest's signature covers: fixed lines, with no JSON to canonicalize. The first names the format, so a signature made for one format never verifies as another's.

func ValidVersion

func ValidVersion(version string) bool

ValidVersion reports whether version is a release's version as its tag names it, without the v: 0.3.0, or a prerelease such as 0.3.0-rc.1.

func Verify

func Verify(m Manifest, key ed25519.PublicKey) error

Verify checks m: every field in form, and the signature made by key's private half over SignedMessage(m). It refuses a key ParseKey would refuse (a point of small order among them). Whether the app takes the release, its platform and version against the running build's, is the caller's to decide.

func ZipURL

func ZipURL(version, file string) string

ZipURL is where a release build downloads the zip of the release of version: pinned to its tag, so a release published between a check and its download can't move it.

Types

type Assets

type Assets struct {
	// Zip is the zipped app bundle, which updates install.
	Zip string

	// DMG is the disk image first installs open. Its name holds no version, so a link to
	// the latest release's copy never changes.
	DMG string

	// Sums is SumsName.
	Sums string

	// Manifest is ManifestName, which the app reads before anything else.
	Manifest string
}

Assets are the names of the files a release attaches.

func AssetNames

func AssetNames(version string) Assets

AssetNames returns the names of the files the release of version attaches for Platform.

type Cache

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

Cache keeps the downloaded updates, each in a folder named for its version holding its zip and its manifest (<dir>/<version>/<file> and ManifestName). Nothing in it is trusted as it lies: Load checks every update in it again, and drops what doesn't check out.

func NewCache

func NewCache(dir string, key ed25519.PublicKey) *Cache

NewCache returns the cache in dir, whose updates must verify with key.

func (*Cache) Load

func (c *Cache) Load(current string) (entry Entry, ok bool, err error)

Load returns the newest update in the cache that checks out and is newer than current, and drops every other version folder: one older than current or as new (installed), one whose manifest doesn't verify with the key or names another version or platform, and one whose zip doesn't match its manifest, as a damaged or tampered one wouldn't. ok is false when none is left. Anything in the cache that isn't a version folder is left alone.

func (*Cache) Prune

func (c *Cache) Prune(keep string) error

Prune drops every version folder but keep's; "" drops them all.

func (*Cache) Put

func (c *Cache) Put(m Manifest, fetch func(w io.Writer) error, progress func(written int64)) (Entry, error)

Put downloads the update m names into the cache with fetch, which writes the zip into the writer it is given, and returns its entry. The zip goes into a temporary file first, counted (progress hears how many bytes have arrived, as they do) and hashed as it arrives, and stops at m.Size; only a zip whose size and SHA-512 match m is renamed into place, with m written beside it after. Anything else leaves nothing of the version in the cache. m must be verified already.

type Config

type Config struct {
	// Flavor is the kind of build; an empty or unknown one is FlavorSource, which never
	// updates.
	Flavor Flavor

	// Current is the running release's version (main.release).
	Current string

	// Feed is where the releases are read from: GitHub's for a release, a folder for a
	// rehearsal.
	Feed Feed

	// Key is the public key a rehearsal trusts, as ReleaseKey holds one. A release
	// ignores it and trusts ReleaseKey alone.
	Key string

	// Memory keeps the engine's state and reads the setting.
	Memory Memory

	// Cache is the folder the downloaded updates are kept in (appdata.Paths.Updates), and
	// Logs the app's logs folder, where a failed install's helper log is kept.
	Cache string
	Logs  string

	// Bundle is the running app's bundle, as the desktop shell finds it, or "" when it
	// runs outside one; Home is the home folder. Applications is the Applications folder
	// every user shares, /Applications when "" (tests point it at a folder of their own).
	Bundle       string
	Home         string
	Applications string

	// RehearsalFolder is a folder a rehearsal build updates itself in, as it would in an
	// Applications folder: the one magex app:rehearse builds it into, which core works out
	// from the rehearsal's feed, so a rehearsal runs end to end without touching an
	// Applications folder. Every other flavor ignores it: a release updates itself only in
	// an Applications folder.
	RehearsalFolder string

	// TempDir is where the runtime's helper writes its log and readiness files
	// (os.TempDir() when ""), and PID the running app's process (os.Getpid() when 0),
	// which names the helper's log.
	TempDir string
	PID     int

	// Backup backs up the database before an install; Runs says which runs a restart
	// would stop; Notifier tells the user of a new version; Reveal shows a file in Finder.
	Backup   DataBackup
	Runs     Runs
	Notifier Notifier
	Reveal   Revealer

	// Writable reports whether the user may create files in a folder; nil asks the system.
	Writable func(dir string) bool

	// Events hears event.UpdatesUpdated whenever the status changes, and, around a
	// restart, event.QuitConfirmed and event.UpdateRestartFailed. Clock stamps the checks
	// and the banner's Later. Logger hears what the engine can't report.
	Events event.Sink
	Clock  clock.Clock
	Logger *slog.Logger
}

Config holds an Engine's dependencies. Memory is required for any flavor that updates.

type DataBackup

type DataBackup interface {
	BackUp(ctx context.Context) (string, error)
}

DataBackup backs up the database before an install: core adapts store.Backup. It returns the backup's path.

type Engine

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

Engine checks for, downloads, and installs the app's updates. It is never bound: the window reaches it through Service, the desktop shell attaches the Installer, and the Worker runs its timed checks.

One operation runs at a time (a check, a download, or a restart), so checks never overlap; the status a window reads is the engine's memory and the update.* preferences, never the network.

func NewEngine

func NewEngine(cfg Config) *Engine

NewEngine returns an Engine over cfg. A source build, a release with no key pinned, or a rehearsal without its key or folder is off: it reads, downloads, and installs nothing, and its status says why.

func (*Engine) Attach

func (e *Engine) Attach(installer Installer)

Attach hands the engine the Installer it restarts with. The desktop shell calls it once the desktop runtime is created; until then, and in a build with none, Restart refuses.

func (*Engine) AttachMover

func (e *Engine) AttachMover(m Mover)

AttachMover hands the engine the Mover it moves the app with. The desktop shell calls it once the desktop runtime is created; until then, and in a build with none, a move refuses.

func (*Engine) Enabled

func (e *Engine) Enabled() bool

Enabled reports whether this build updates.

func (*Engine) Status

func (e *Engine) Status(ctx context.Context) (Status, error)

Status returns the update as the window shows it, from the engine's memory and the update.* preferences.

type Entry

type Entry struct {
	Manifest Manifest
	Zip      string
}

Entry is one update in the cache: its manifest, verified with the key, and its zip, which matched the manifest's size and SHA-512 when it was written or loaded.

type Feed

type Feed interface {
	// Manifest returns the latest release's manifest, as its bytes, at most
	// MaxManifestBytes, or ErrNoRelease when it has none.
	Manifest(ctx context.Context) ([]byte, error)

	// Download writes the zip file of the release of version into w. It may write more
	// than the manifest's size; the caller stops it there.
	Download(ctx context.Context, version, file string, w io.Writer) error
}

Feed is where the releases are read from: GitHub's latest release for a release build (core adapts the GitHub client's release downloads), a local folder for a rehearsal.

type Flavor

type Flavor string

Flavor is the kind of build the app is, which says whether and where it updates from.

const (
	// FlavorSource is a build made from source (magex app:build, app:run, app:dev): it never
	// checks for updates.
	FlavorSource Flavor = "source"

	// FlavorRelease is a release magex app:package made: it reads GitHub's latest release
	// and trusts only ReleaseKey.
	FlavorRelease Flavor = "release"

	// FlavorRehearsal is a pair of builds magex app:rehearse makes to try an update end to
	// end on one Mac: it reads its releases from a local folder and trusts the key the
	// build was given.
	FlavorRehearsal Flavor = "rehearsal"
)

The flavors, stamped into the build (main.flavor); an empty or unknown one is source.

type FolderFeed

type FolderFeed struct {
	// Dir is the folder.
	Dir string
}

FolderFeed reads the releases from a folder holding one release's manifest (ManifestName) and its zip, as magex app:rehearse writes them: a rehearsal's feed, read from disk with no network at all.

func (FolderFeed) Download

func (f FolderFeed) Download(ctx context.Context, _, file string, w io.Writer) error

Download copies the folder's file into w. The file must be a plain name, in the folder.

func (FolderFeed) Manifest

func (f FolderFeed) Manifest(_ context.Context) ([]byte, error)

Manifest reads the folder's manifest, or fails with ErrNoRelease when there is none.

type InstallFailure

type InstallFailure struct {
	// Version is the version it was meant to install, or "" when the last restart
	// installed what it meant to, or there was none.
	Version string `json:"version"`

	// Reason says why, in words, as the update's helper's log tells it.
	Reason string `json:"reason"`

	// Log reports that the helper's log was kept, which ShowInstallLog shows.
	Log bool `json:"log"`

	// Retryable reports that trying the same update again may work: the failure was the
	// moment's (the app didn't quit in time, macOS kept it from being replaced or couldn't
	// open the new version, it couldn't be copied aside, or the helper's log doesn't say),
	// and the update stays offered. A failure of the update itself (it failed its signature
	// check, or couldn't be installed) fails the same way every time: that update is never
	// offered again, and the release page is the way to get it.
	Retryable bool `json:"retryable"`
}

InstallFailure is the update the last restart didn't install, or, in a later run, the newest version found, when an earlier restart failed to install it for good.

type Installer

type Installer interface {
	// Install stages the update in zip, of version, whose size and SHA-512 (hex) the
	// staging checks the zip against as it copies it.
	Install(ctx context.Context, zip, version string, size int64, sha512 string) error

	// Restart starts the runtime's helper, waits for it to stand by, and quits the app,
	// which the helper waits for before it swaps the bundles and opens the new one. The
	// process exits inside it: it returns only when something stopped it first.
	Restart(ctx context.Context) error
}

Installer installs an update and restarts into it: the desktop shell's adapter over the desktop runtime's updater, which stages the zip beside the running bundle and swaps it in after the app quits.

type Location

type Location struct {
	// OK reports that the app can update where it is: in an Applications folder whose
	// folder it can write to, where the update is staged beside it.
	OK bool `json:"ok"`

	// Kind says where it is.
	Kind LocationKind `json:"kind"`

	// Target is where moving it would put it, with ~ for home: the Applications folder
	// when the user can write to it, else the one in the home folder.
	Target string `json:"target"`

	// Movable reports that Move to Applications can put the app at Target: a build that
	// updates, running from its bundle on a disk image, from a path macOS translocated it
	// to, or from anywhere else outside an Applications folder. A copy in an Applications
	// folder its account can't change isn't movable: it is in Applications already.
	Movable bool `json:"movable"`
}

Location is where the running app is.

type LocationKind

type LocationKind string

LocationKind says where the running app is, which decides whether it can replace itself.

const (
	// LocationApplications is the Applications folder, or a folder in it.
	LocationApplications LocationKind = "applications"

	// LocationUserApplications is the Applications folder in the home folder.
	LocationUserApplications LocationKind = "userApplications"

	// LocationTranslocated is a random read-only path macOS runs a downloaded app from
	// until it is moved (App Translocation).
	LocationTranslocated LocationKind = "translocated"

	// LocationDiskImage is a mounted disk image or another volume.
	LocationDiskImage LocationKind = "diskImage"

	// LocationElsewhere is anywhere else, such as Downloads, or no bundle at all.
	LocationElsewhere LocationKind = "elsewhere"
)

The kinds of location.

func Classify

func Classify(bundle, home string) LocationKind

Classify says where the bundle at bundle is: an Applications folder (the system's, or the one in home), a path macOS translocated it to, a mounted volume such as a disk image, or elsewhere, which "" (no bundle) is too.

type Manifest

type Manifest struct {
	// Version is the release's version, without a leading v, such as 0.3.0.
	Version string `json:"version"`

	// Platform is the build the zip holds, such as Platform.
	Platform string `json:"platform"`

	// File is the zip's asset name, exactly FileName(Platform, Version).
	File string `json:"file"`

	// Size is the zip's size in bytes.
	Size int64 `json:"size"`

	// SHA512 is the zip's SHA-512, as 128 lowercase hex characters.
	SHA512 string `json:"sha512"`

	// Signature is the Ed25519 signature of SignedMessage, base64.
	Signature string `json:"signature"`
}

Manifest describes the zip one release's update installs. The signature covers every other field, so none of them can be changed, a version relabeled, or a file swapped, without the key.

func Parse

func Parse(data []byte) (Manifest, error)

Parse reads a manifest from its JSON, refusing one larger than MaxManifestBytes, a field the format doesn't have, or anything after the object. It checks no field's value: Verify does.

func Sign

func Sign(m Manifest, key ed25519.PrivateKey) (Manifest, error)

Sign returns m signed with key. It refuses a manifest whose fields are out of form, so it never signs one Verify would refuse.

type Memory

type Memory interface {
	GetMany(ctx context.Context, keys ...string) (map[string]string, error)
	SetMany(ctx context.Context, values map[string]string) error
	Delete(ctx context.Context, key string) error
}

Memory is where the engine keeps its state, the update.* preferences, and reads the setting: a *prefs.Store.

type MoveOutcome

type MoveOutcome string

MoveOutcome is how a move to Applications, or an Open it, ended.

const (
	// MoveMoved is the app copied into Applications and checked: the app quits the normal
	// way, and the copy opens once it has.
	MoveMoved MoveOutcome = "moved"

	// MoveExists is a copy of the app already in Applications: nothing was copied or
	// replaced, and OpenInApplications opens that copy, which updates itself when it is
	// older.
	MoveExists MoveOutcome = "exists"

	// MoveOpening is the copy in Applications checked: the app quits the normal way, and
	// that copy opens once it has.
	MoveOpening MoveOutcome = "opening"
)

The outcomes. A failure is an error, in words.

type MoveResult

type MoveResult struct {
	// Outcome says what happened.
	Outcome MoveOutcome `json:"outcome"`

	// Target is the copy in Applications, with ~ for home.
	Target string `json:"target"`
}

MoveResult is what a move to Applications, or an Open it, did.

type Mover

type Mover interface {
	// HoldQuit holds every quit of the app while a move runs, so its copy is never cut off
	// partway: a quit asked for meanwhile waits, and goes ahead once the func it returns
	// lets go, which the move calls once, as it ends.
	HoldQuit() (release func())

	// Copy copies the app's bundle at from into to, an empty folder the engine has just
	// made for it, and takes the quarantine mark a download carries off the copy. Its error
	// says why in a few words (uierr.Message).
	Copy(ctx context.Context, from, to string) error

	// Verify checks the code signature of the bundle at bundle, deeply and strictly, and
	// that it meets the designated requirement of the app that runs, read from its process:
	// signed as this copy is. Its error says why in a few words, with ErrOwnSignature in its
	// chain when that requirement couldn't be read.
	Verify(ctx context.Context, bundle string) error

	// Translocates reports whether macOS would open the bundle at bundle from a hidden,
	// read-only copy (App Translocation), as it does an app still marked as downloaded that
	// the user never moved with Finder: one that can't update itself.
	Translocates(bundle string) (bool, error)

	// OpenAfterQuit quits the app the normal way, which asks first while runs go in the
	// app, and opens the bundle at bundle once it has quit. Asked again, it still opens one
	// bundle, once: the last it was asked to. A quit the user keeps from going through
	// opens nothing.
	OpenAfterQuit(bundle string)
}

Mover moves the app into an Applications folder: the desktop shell's, which copies with ditto and checks the copy with codesign, both through execpath, holds the app's quit while a move runs, and opens a bundle once the app has quit. The engine works out where the copy goes, makes the folder it is copied into, and puts it in place; the Mover only runs the programs, reads the quarantine mark, and holds and relaunches.

type Notice

type Notice struct {
	// Version is the new version.
	Version string

	// Ready reports that it is downloaded and checked, waiting for a restart; otherwise it
	// is only available.
	Ready bool
}

Notice is a new version the user is told of.

type Notifier

type Notifier interface {
	UpdateFound(ctx context.Context, n Notice)
}

Notifier tells the user once that a new version is ready, or available: core records a notification about no item (update_ready), with its banner.

type RefusalCode

type RefusalCode string

RefusalCode names a refusal the window answers on its own, without asking the user, so it tells which one from the code and never from the words.

const (
	// RefusalSettling is a download or a restart refused while the last update's helper may
	// still be at work (ErrSettling): the same click works in a moment, so the window says
	// so quietly and offers the update again.
	RefusalSettling RefusalCode = "settling"

	// RefusalFinishing is a restart refused while an earlier one finishes (ErrFinishing):
	// its quit was held, and the app is quitting on its own so the update installs, so the
	// window says so calmly and offers nothing to click.
	RefusalFinishing RefusalCode = "finishing"

	// RefusalUninstallable is a download or a restart refused for an update that failed to
	// install for good (ErrUninstallable): trying again fails the same way, so the window
	// offers only its release page, never Try again.
	RefusalUninstallable RefusalCode = "uninstallable"
)

The refusals the window tells apart.

type RefusalDetail

type RefusalDetail struct {
	Code RefusalCode `json:"code"`
}

RefusalDetail is what the window gets beside a RefusalError's message: {"code": "..."}.

type RefusalError

type RefusalError struct {
	// Code says which refusal it is.
	Code RefusalCode
	// contains filtered or unexported fields
}

RefusalError is a refusal the window answers on its own. Its message and chain are the refusal's (errors.Is sees ErrSettling, say), and Detail hands the desktop runtime its code, which it sends the window beside the message, as a RunsGoingError's runs are.

func (*RefusalError) Detail

func (e *RefusalError) Detail() any

Detail returns the code, for the window.

func (*RefusalError) Error

func (e *RefusalError) Error() string

Error returns the refusal's text.

func (*RefusalError) Unwrap

func (e *RefusalError) Unwrap() error

Unwrap returns the refusal, with the words for the user.

type Revealer

type Revealer interface {
	Reveal(ctx context.Context, path string) error
}

Revealer shows a file in Finder: core's open -R.

type Run

type Run struct {
	ID    int64  `json:"id"`
	Kind  string `json:"kind"`
	Title string `json:"title"`

	// Repo is the run's repository, "owner/name", or "", and Dir its folder, with ~ for
	// home.
	Repo string `json:"repo"`
	Dir  string `json:"dir"`

	// StopRefused says why the run can't be stopped right now, or "": quitting then waits a
	// few seconds for it.
	StopRefused string `json:"stopRefused"`
}

Run is a run going in the app, as the window names it when it asks before a restart.

type Runs

type Runs interface {
	// Active reports whether a run is going in the app. It never waits.
	Active() bool

	// Going lists the runs going in the app.
	Going(ctx context.Context) ([]Run, error)
}

Runs says which runs are going in the app, which a restart would stop: core adapts the runs' engine.

type RunsGoingDetail

type RunsGoingDetail struct {
	RunsGoing []Run `json:"runsGoing"`
}

RunsGoingDetail is what the window gets beside a RunsGoingError's message.

type RunsGoingError

type RunsGoingError struct {
	// Runs are the runs going, as Runs.Going listed them.
	Runs []Run
	// contains filtered or unexported fields
}

RunsGoingError refuses a restart the user hasn't confirmed while runs go in the app. Its message names them, and Detail hands them to the desktop runtime, which sends them to the window as {"runsGoing": [...]}, so it can ask first in the quit dialog's words; a run that couldn't be listed leaves the list empty, and the window asks about the runs as a whole.

func (*RunsGoingError) Detail

func (e *RunsGoingError) Detail() any

Detail returns the runs, for the window.

func (*RunsGoingError) Error

func (e *RunsGoingError) Error() string

Error returns the refusal's text.

func (*RunsGoingError) Unwrap

func (e *RunsGoingError) Unwrap() error

Unwrap returns the refusal: ErrRunsGoing, with the words for the user.

type Service

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

Service is the app's update as the window sees it: its status, Check for Updates, the download Just tell me's Update asks for, the restart, Later, and the toast after an update. The window binds it; the Engine behind it is never bound.

func NewService

func NewService(e *Engine) *Service

NewService returns the window's face of e.

func (*Service) AckUpdated

func (s *Service) AckUpdated(ctx context.Context) (Status, error)

AckUpdated forgets which version this launch updated to, once the window has said so, and returns the status.

func (*Service) CheckNow

func (s *Service) CheckNow(ctx context.Context) (Status, error)

CheckNow checks for a new version now, in every mode, Don't check included, and returns the status, whose LastError tells a check that failed. A version it finds is shown without a notification; with Download it and tell me, the Worker downloads it at once, a download that failed before included, but only once the start is settled. While the update downloads, it returns the status as it is.

func (*Service) Download

func (s *Service) Download(ctx context.Context) (Status, error)

Download downloads the newer version found and checks it, and returns the status, ready: what Update asks for with Just tell me, before it restarts. A version downloaded already is ready as it is. While the last install's helper may still be at work, it refuses with ErrSettling.

func (*Service) HideBanner

func (s *Service) HideBanner(ctx context.Context) (Status, error)

HideBanner hides the banner of the newer version for HideFor, as Later asks, and returns the status. A newer version than the one hidden shows it again.

func (*Service) MoveToApplications

func (s *Service) MoveToApplications(ctx context.Context) (MoveResult, error)

MoveToApplications moves the app into Applications, where it can update itself, as the move dialog asks: it copies the running bundle to Location.Target, checks the copy's signature, and quits the app the normal way, which asks first while runs go in the app, opening the copy once it has quit; the result is MoveMoved. A copy of the app there already is never replaced: the result is MoveExists, for OpenInApplications. Anything else there, a copy that fails, or one that doesn't pass its check (which is removed) is an error in words, and nothing changes. The bundle that runs is never touched.

func (*Service) OpenInApplications

func (s *Service) OpenInApplications(ctx context.Context) (MoveResult, error)

OpenInApplications opens the copy of the app already in Applications, as Open it asks, once its signature checks out: it quits the app the normal way, which asks first while runs go, and opens that copy once it has quit, which updates itself when it is older. The result is MoveOpening.

func (*Service) Restart

func (s *Service) Restart(ctx context.Context, confirmed bool) (Status, error)

Restart installs the update that is ready and restarts into it. While runs go in the app, it refuses with a RunsGoingError naming them unless confirmed, so the window can ask first; confirmed, it stops them. It backs up the database first and refuses to go on without the backup. The app quits inside it once the update is staged, so it returns only when something stopped the restart: the update is then ready again, and the error says why. While the last install's helper may still be at work, it refuses with ErrSettling.

func (*Service) ShowAppInFinder

func (s *Service) ShowAppInFinder(ctx context.Context) error

ShowAppInFinder shows the running app in Finder, so the user can delete the copy they opened once it has moved to Applications. A copy macOS translocated runs from a folder it hides, which Finder can't show.

func (*Service) ShowBanner

func (s *Service) ShowBanner(ctx context.Context) (Status, error)

ShowBanner shows the banner again, lifting Later, as a click on the update's notification asks, and returns the status.

func (*Service) ShowInstallLog

func (s *Service) ShowInstallLog(ctx context.Context) error

ShowInstallLog shows the log of the update the last restart didn't install in Finder, the copy kept in the logs folder.

func (*Service) Status

func (s *Service) Status(ctx context.Context) (Status, error)

Status returns the update as the window shows it. It reads no network.

type State

type State string

State is where the app's update stands.

const (
	// StateOff is a build that can't update (Status.Off says why).
	StateOff State = "off"

	// StateIdle is no newer version known: up to date, or never checked.
	StateIdle State = "idle"

	// StateChecking is a check running while no newer version is known.
	StateChecking State = "checking"

	// StateDownloading is the newer version downloading (Status.Progress).
	StateDownloading State = "downloading"

	// StateAvailable is a newer version found and not downloaded yet, as Just tell me and
	// Don't check leave one: Update downloads it, then restarts.
	StateAvailable State = "available"

	// StateReady is a newer version downloaded and checked, waiting for a restart.
	StateReady State = "ready"

	// StateInstalling is a restart under way: the data backed up, the update staged, the
	// app about to quit.
	StateInstalling State = "installing"

	// StateFinishing is a restart whose quit was held (a modal panel, say) after the
	// runtime's helper started: the update stays staged and recorded, and the app quits on
	// its own within moments so the helper installs it.
	StateFinishing State = "finishing"
)

The states. A failure changes none of them: it is the status's LastError, so an update that is ready stays ready when a later check fails.

type Status

type Status struct {
	// Flavor is the kind of build, and Enabled whether it can update: only a release or a
	// rehearsal build with a key can. Off says why not, in words, or "".
	Flavor  Flavor `json:"flavor"`
	Enabled bool   `json:"enabled"`
	Off     string `json:"off"`

	// Current is the running release's version, such as 0.2.0.
	Current string `json:"current"`

	// Mode is what the app does when a new version is out (the setting).
	Mode updateprefs.Mode `json:"mode"`

	// State is where the update stands, and Checking whether a check runs now, in any
	// state.
	State    State `json:"state"`
	Checking bool  `json:"checking"`

	// Progress is how much of the download has arrived, 0 to 100, while downloading.
	Progress int `json:"progress"`

	// Latest is the newer version found, or "".
	Latest string `json:"latest"`

	// ReleaseURL is the release page of Latest, or of Current when none is found, for
	// What's new; "" for a build that can't update.
	ReleaseURL string `json:"releaseUrl"`

	// LastChecked is when the last check that reached the releases ended, as RFC 3339, or
	// "", and LastError what went wrong last, in words, or "" once a later step worked.
	LastChecked string `json:"lastChecked"`
	LastError   string `json:"lastError"`

	// BannerHidden reports that the user chose Later for Latest less than a day ago.
	BannerHidden bool `json:"bannerHidden"`

	// JustUpdated is the version this launch updated to, until AckUpdated: the window
	// says so once.
	JustUpdated string `json:"justUpdated"`

	// InstallFailed is the update the last restart didn't install, if any.
	InstallFailed InstallFailure `json:"installFailed"`

	// Location is where the running app is.
	Location Location `json:"location"`
}

Status is the app's update as the window shows it. Every field is a plain value.

type Worker

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

Worker runs the engine's timed checks. It is a desktop worker, run as deferred work, so never on the cold start, and never bound.

It first reads how the last restart went, cleans up after it, and loads the update kept in the cache (so one waiting is ready at once, with no download), waiting first while the last install's helper may still be at work (HelperWindow); FirstCheckAfter later, or at once when woken first, it looks whether a check is due, and again every TickEvery: a check is due once CheckEvery has passed on the wall clock since the last, since timers stand still while a Mac sleeps. A Wake (the setting changed, or a manual check found a version to download) has it look at once. Its checks and the window's never overlap.

func NewWorker

func NewWorker(e *Engine) *Worker

NewWorker returns the Worker of e, which the engine wakes when a manual check finds a version to download.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context)

Run settles the start, waits FirstCheckAfter (or for a Wake), and then looks every TickEvery, or when woken, until ctx ends, returning once the look in flight has. A build that doesn't update returns at once.

func (*Worker) Wake

func (w *Worker) Wake()

Wake has the Worker look at once, as when the user changed the setting.

Jump to

Keyboard shortcuts

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