update

package
v0.4.12 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package update keeps a Lightron app up to date from a feed: a JSON file listing the latest version and a package per platform (what `lightron feed` writes), e.g. the update.json of a GitHub release:

{"version": "1.2.0", "notes": "…", "packages": {
  "darwin-arm64":  {"file": "Notes-1.2.0-darwin-arm64.dmg",       "size": 18900000, "sha256": "…"},
  "windows-amd64": {"file": "Notes-1.2.0-windows-amd64-setup.exe", "size": 13900000, "sha256": "…"}}}

Check downloads the newer package (checked: size, sha256; tried again when the server fails); Install puts it in place once the app has quit: macOS swaps the .app and opens the new one, Windows runs the installer silently.

u := update.New(update.Options{FeedURL: "https://github.com/me/notes/releases/latest/download/update.json",
	Current: version, Dir: dataDir})
if rel, err := u.Check(ctx); err == nil && rel != nil {
	if ask(rel.Version) && rel.Install() == nil {
		app.Quit()
	}
}

Index

Constants

This section is empty.

Variables

View Source
var ErrNotUpdatable = errors.New("update: this build's version can't be compared with releases")

ErrNotUpdatable: Current isn't a version Check can compare (0.1.0-dev, empty). Such builds don't update.

Functions

func Newer

func Newer(a, b string) bool

Newer reports whether version a is newer than b (false when either can't be read).

func ParseVersion

func ParseVersion(v string) []int

ParseVersion reads a release (x.y.z, v optional) or a git describe (x.y.z-N-gabc[-dirty]) as [x, y, z, N], N being commits past the x.y.z tag: a local build is ahead of the release it was built on and behind the next one. nil for anything else (0.1.0-dev).

Types

type Feed

type Feed struct {
	Version  string             `json:"version"`
	Notes    string             `json:"notes,omitempty"`
	Packages map[string]Package `json:"packages"`
}

Feed is what a feed says.

type Options

type Options struct {
	// FeedURL is the feed's address. The packages are found next to it (same directory), so
	// …/releases/latest/download/update.json on GitHub works as is.
	FeedURL string
	// Current is this build's version: x.y.z, or a git describe (x.y.z-N-gabc, -dirty).
	Current string
	// Dir is where downloads wait until installed. Default: a directory under os.TempDir().
	Dir string
	// Platform is the feed's key for this build. Default: GOOS-GOARCH (darwin-arm64, windows-amd64).
	Platform string
	// Client makes the requests. Default: http.DefaultClient.
	Client *http.Client
	// Logf receives retries and the like. Default: log.Printf.
	Logf func(format string, args ...any)
}

Options configure an Updater.

type Package

type Package struct {
	File   string `json:"file"`
	Size   int64  `json:"size"`
	Sha256 string `json:"sha256"`
}

Package is one platform's file in a feed.

type Release

type Release struct {
	Version string
	Notes   string
	// File is the downloaded package.
	File string
}

Release is a newer version, downloaded and checked, waiting to be installed.

func (*Release) Install

func (r *Release) Install() error

Install isn't supported on this platform yet.

type Updater

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

Updater checks a feed.

func New

func New(o Options) *Updater

New returns an Updater.

func (*Updater) Check

func (u *Updater) Check(ctx context.Context) (*Release, error)

Check reads the feed and, when it has a newer version with a package for this platform, downloads that. It returns nil, nil when up to date. A package downloaded before and not installed isn't downloaded again.

Jump to

Keyboard shortcuts

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