Documentation
¶
Overview ¶
Package update keeps a desktop app up to date from a feed you host: it checks for a newer version, downloads it, verifies it, replaces the app and restarts it.
u := update.New() // feed, key and version from giode.toml, via the giode CLI
rel, err := u.Check(ctx)
if err == nil && rel != nil {
dl, err := u.Download(ctx, rel, nil)
if err == nil {
err = dl.Install() // restarts into the new version
}
}
The feed is a JSON file listing the latest version and a download per platform, signed with an Ed25519 key: `giode update-key` makes the key pair (the public half goes into the app), and `giode release` writes the signed feed and the downloads from a build. The app trusts only a feed signed with its key, and only downloads whose SHA-256 the feed lists, so the server needn't be trusted.
Apps installed by a package manager or store - a .deb or .rpm, Flatpak, MSIX, the App Store - are updated by it instead: Check returns ErrManaged for them.
Index ¶
Constants ¶
const WaitEnv = "GIODE_UPDATE_WAIT_PID"
WaitEnv names the environment variable an updated app is restarted with: the old process's pid, which giode waits for to exit before taking the single-instance lock.
Variables ¶
var ErrManaged = errors.New("update: the app is installed by a package manager or store, which updates it")
ErrManaged is returned for an app a package manager or store installed and updates.
Functions ¶
func Cleanup ¶
func Cleanup()
Cleanup removes what an earlier update left behind (the replaced program). Call it once at startup.
func Newer ¶
Newer reports whether version a is newer than b (major.minor.patch, missing parts 0; anything after - or + is ignored).
func Platform ¶
func Platform() string
Platform returns this build's feed key: GOOS-GOARCH, or darwin-universal on macOS.
Types ¶
type Asset ¶
type Asset struct {
// URL is where it is, relative to the feed or absolute.
URL string `json:"url"`
// SHA256 is the hex digest of the file; Size its length.
SHA256 string `json:"sha256"`
Size int64 `json:"size"`
// Kind says how it installs: "exe" (a Windows program replacing
// the running one), "installer" (a Windows setup program run
// silently), "app.zip" (a zipped macOS app bundle), "binary" (a
// Linux program) or "appimage".
Kind string `json:"kind"`
}
Asset is a download for one platform.
type Download ¶
type Download struct {
Release *Release
// Path is the downloaded file.
Path string
// contains filtered or unexported fields
}
Download is a downloaded, verified release.
type Feed ¶
type Feed struct {
// Version is the latest version; Notes describe it; Date is when
// it was released (RFC 3339).
Version string `json:"version"`
Notes string `json:"notes,omitempty"`
Date string `json:"date,omitempty"`
// Assets are the downloads by platform.
Assets map[string]Asset `json:"assets"`
}
Feed is the update feed.
type Release ¶
type Release struct {
Version, Notes, Date string
Asset Asset
// contains filtered or unexported fields
}
Release is an available update.
type Updater ¶
type Updater struct {
// FeedURL is the feed's address; its signature is at FeedURL+".sig".
FeedURL string
// PublicKey is the base64 Ed25519 public key the feed is signed
// with.
PublicKey string
// Version is the running version, major.minor.patch.
Version string
// Client fetches the feed and downloads; http.DefaultClient when
// nil.
Client *http.Client
// Platform is the feed's key for this build ("windows-amd64",
// "darwin-universal", "linux-amd64"); detected when empty.
Platform string
// Executable is the program (or .app bundle, or AppImage) to
// replace; detected when empty.
Executable string
}
Updater checks a feed and installs its releases.