Documentation
¶
Overview ¶
Package update keeps magpie current. Builds are published as GitHub releases of yetone/magpie-releases; usemagpie.ai/api/latest describes the newest one: its version, notes, and every file with its SHA-256.
The macOS app replaces its own bundle: the new zip is downloaded, checked against its hash, unpacked, and accepted only if it is signed by the same team as the app already installed. A bare binary (the terminal build, and the desktop app on Windows and Linux) replaces itself the same way, minus the signature.
Index ¶
- Constants
- Variables
- func Alive(pid int) bool
- func AppAsset() string
- func AwaitPredecessor()
- func BinaryAsset() string
- func Bundle() string
- func CanElevate() bool
- func Executable() (string, error)
- func Feed() string
- func Homebrew(exe string) bool
- func InLang(md, lang string) string
- func Install(staged, bundle string) error
- func InstallAsAdmin(staged, bundle string) error
- func InstallBinary(staged, exe string) error
- func InstallBinaryAsAdmin(staged, exe string) error
- func NeedsAdmin(err error) bool
- func Newer(a, b string) bool
- func NotesFeed() string
- func Reexec(exe string, args, env []string) error
- func Relaunch(bundle string) error
- func RelaunchArgs(window bool, view string) []string
- func RelaunchBinary(exe string, window bool, view string) error
- func Released(v string) bool
- func RemoveOld(exe string)
- func RemoveStaleNew(exe string)
- func ReplaceBinary(ctx context.Context, rel *Release) error
- func Replaced(exe string, started os.FileInfo) bool
- func ShowNotes(last, current string, existed bool) (after string, show bool)
- func Stage(ctx context.Context, rel *Release, bundle string) (string, error)
- func StageBinary(ctx context.Context, rel *Release) (string, error)
- func StripInstall(md string) string
- func Stuck(bundle string) string
- func WithProgress(ctx context.Context, f func(done, total int64)) context.Context
- func Writable(dir string) bool
- type Asset
- type Note
- type Release
Constants ¶
const MaxNotes = 40
MaxNotes is how many releases' notes are shown at most: magpie releases often, and a long-unopened one would have pages of them.
const Site = "https://usemagpie.ai"
Site is magpie's home; its /api/latest is the update feed.
Variables ¶
var ErrCanceled = errors.New("the update was canceled")
ErrCanceled is the administrator's password prompt dismissed.
var GUI bool
GUI says this binary has the desktop app in it. Off the Mac that app is a single binary too, and it updates from its own build, not the terminal one.
Functions ¶
func AppAsset ¶
func AppAsset() string
AppAsset and BinaryAsset name the files this machine would install.
func AwaitPredecessor ¶ added in v0.1.3
func AwaitPredecessor()
AwaitPredecessor blocks, for a while at most, until the magpie that relaunched this one has exited.
func BinaryAsset ¶
func BinaryAsset() string
func Bundle ¶
func Bundle() string
Bundle is the .app the running binary lives in, or "" when it is not in one.
func CanElevate ¶ added in v0.1.38
func CanElevate() bool
CanElevate reports whether this system can ask for the administrator's password: always on a Mac, with polkit on Linux, not on Windows.
func Executable ¶ added in v0.1.3
Executable is the running binary, symlinks resolved.
func Feed ¶
func Feed() string
Feed is where the newest release is described. MAGPIE_UPDATE_FEED points it elsewhere, for testing an update against a local server.
func Homebrew ¶ added in v0.1.126
Homebrew is whether exe was installed by Homebrew (brew install magpie), which keeps it in its Cellar and has to be the one to upgrade it: a binary replaced under it leaves brew thinking the old version is there.
func InLang ¶ added in v0.1.627
InLang is a release's notes in lang, as the site cuts them (a site from before it did, or a feed elsewhere, hands them whole): "zh" the Chinese where there is some, else the English, everything above the marker. Notes from before the marker are English alone, in any language.
func Install ¶
Install swaps the staged app in for bundle. The running copy keeps going until it quits; the next launch is the new one. Where the folder is not magpie's to change the error is a permission one (NeedsAdmin), and InstallAsAdmin can do it instead.
func InstallAsAdmin ¶ added in v0.1.38
InstallAsAdmin is Install with the administrator's password, asked for by the system.
func InstallBinary ¶ added in v0.1.3
InstallBinary swaps a staged binary in for exe, the running one, which keeps going until it exits.
func InstallBinaryAsAdmin ¶ added in v0.1.38
InstallBinaryAsAdmin is InstallBinary with the administrator's password.
func NeedsAdmin ¶ added in v0.1.38
NeedsAdmin reports whether err is magpie not being allowed to change the folder it lives in, which the administrator's password gets past.
func Newer ¶
Newer reports whether version a comes after b. A pre-release comes before the release it leads up to.
func NotesFeed ¶ added in v0.1.606
func NotesFeed() string
NotesFeed is where the notes of past releases are listed: beside the update feed, on magpie's site. MAGPIE_NOTES_FEED points it elsewhere.
func Reexec ¶ added in v0.1.191
Reexec runs exe in this process's place with args and env: the same process, in the same terminal or under the same service manager, now running the new version (magpie web's restart to update).
func RelaunchArgs ¶ added in v0.1.458
RelaunchArgs is what RelaunchBinary starts magpie with: `gui [view]` for the window, `tray` for the tray icon alone.
func RelaunchBinary ¶ added in v0.1.3
RelaunchBinary starts exe again: with its window on view when window is set (the window was open), else as the tray app alone, as autostart starts it. The new process waits for this one to exit before it takes the gateway's port; see AwaitPredecessor.
func Released ¶
Released reports whether v is a release version rather than a build from source ("dev", "0bcb2cc-dirty", git describe's "v0.1.0-3-g0bcb2cc"); only releases update themselves.
func RemoveOld ¶ added in v0.1.92
func RemoveOld(exe string)
RemoveOld removes what earlier updates moved aside of exe, those no longer running.
func RemoveStaleNew ¶ added in v0.1.107
func RemoveStaleNew(exe string)
RemoveStaleNew removes exe.new when it is exe over again: the update a magpie left running from before it downloaded once more.
func ReplaceBinary ¶
ReplaceBinary puts the release's build for this binary where the running one is.
func Replaced ¶ added in v0.1.107
Replaced reports whether exe is no longer the binary that was there when this process looked (started, from os.Stat): another magpie installed an update over it, and this one runs from where it was moved aside.
func ShowNotes ¶ added in v0.1.606
ShowNotes decides, as magpie starts on current having last run as last ("" when it never said), whether to show what changed since, and from which version on (exclusive). Only an upgrade between releases shows: not a fresh install, the same version again, a downgrade, or a build from source. A magpie from before versions were kept has no last; when it was already in use (existed) its own version's notes are shown, from "", which Between takes as upto's alone.
func Stage ¶
Stage downloads the app in rel and unpacks it next to the installed bundle, ready for Install. It returns the unpacked app.
func StageBinary ¶ added in v0.1.3
StageBinary downloads the release's build for this binary next to it (or to the cache, where magpie may not write there), ready for InstallBinary.
func StripInstall ¶ added in v0.1.606
StripInstall takes a release's "Install" section out of its notes: the download links, which mean nothing to a magpie that just updated itself. The section runs to the next heading of its level or above.
func Stuck ¶ added in v0.1.38
Stuck says why the app at bundle cannot be replaced where it is, or "" when it can: opened from its disk image, or moved aside by macOS (App Translocation) because it was never moved out of Downloads.
func WithProgress ¶ added in v0.1.17
WithProgress has downloads made under ctx report how far along they are; total is 0 while the size is unknown.
Types ¶
type Asset ¶
type Asset struct {
URL string `json:"url"`
Size int64 `json:"size"`
SHA256 string `json:"sha256"`
}
Asset is one downloadable file of a release.
type Note ¶ added in v0.1.606
type Note struct {
Version string `json:"version"` // no v
Notes string `json:"notes"` // markdown, its Install section taken out
URL string `json:"url,omitempty"`
}
Note is one release's notes, as the app shows them after an update.
type Release ¶
type Release struct {
Version string `json:"version"` // "0.2.0", no v
Notes string `json:"notes"` // markdown
URL string `json:"url"` // the release page
Assets map[string]Asset `json:"assets"` // by file name
}
Release is one published version.