Documentation ¶
Index ¶
- Constants
- type Asset
- type Config
- type Context
- type Error
- type ErrorType
- type Log
- type Property
- type Update
- type UpdateAction
- type UpdateChecker
- type UpdateOptions
- type UpdatePromptOptions
- type UpdatePromptResponse
- type UpdateSource
- type UpdateType
- type UpdateUI
- type Updater
- func (u *Updater) ApplyDownloaded(ctx Context) (bool, error)
- func (u *Updater) CheckAndDownload(ctx Context) (updateAvailable, updateWasDownloaded bool, err error)
- func (u *Updater) Cleanup(tmpDir string)
- func (u *Updater) CleanupPreviousUpdates() (err error)
- func (u *Updater) FindDownloadedAsset(assetName string) (matchingAssetPath string, err error)
- func (u *Updater) NeedUpdate(ctx Context) (upToDate bool, err error)
- func (u *Updater) SetTickDuration(dur time.Duration)
- func (u *Updater) Update(ctx Context) (*Update, error)
Constants ¶
const DefaultTickDuration = time.Hour
const Version = "0.3.8"
Version is the updater version
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Asset ¶
type Asset struct { Name string `json:"name"` URL string `json:"url"` Digest string `json:"digest"` Signature string `json:"signature"` LocalPath string `json:"localPath"` }
Asset describes a downloadable file
type Config ¶
type Config interface { GetUpdateAuto() (bool, bool) SetUpdateAuto(b bool) error GetUpdateAutoOverride() bool SetUpdateAutoOverride(bool) error GetInstallID() string SetInstallID(installID string) error IsLastUpdateCheckTimeRecent(d time.Duration) bool SetLastUpdateCheckTime() SetLastAppliedVersion(string) error GetLastAppliedVersion() string }
Config defines configuration for the Updater
type Context ¶
type Context interface { GetUpdateUI() UpdateUI UpdateOptions() UpdateOptions Verify(update Update) error BeforeUpdatePrompt(update Update, options UpdateOptions) error BeforeApply(update Update) error Apply(update Update, options UpdateOptions, tmpDir string) error AfterApply(update Update) error ReportError(err error, update *Update, options UpdateOptions) ReportAction(updatePromptResponse UpdatePromptResponse, update *Update, options UpdateOptions) ReportSuccess(update *Update, options UpdateOptions) AfterUpdateCheck(update *Update) GetAppStatePath() string IsCheckCommand() bool DeepClean() }
Context defines options, UI and hooks for the updater. This is where you can define custom behavior specific to your apps.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is an update error with a type/category for reporting
func (Error) TypeString ¶
TypeString returns a unique short string to denote the error type
type ErrorType ¶
type ErrorType string
ErrorType is a unique short string denoting the error category
const ( // UnknownError is for if we had an unknown error UnknownError ErrorType = "unknown" // CancelError is for if we canceled CancelError ErrorType = "cancel" // ConfigError is for errors reading/saving config ConfigError ErrorType = "config" // ConfigError is for when the GUI is active GUIBusyError ErrorType = "guiBusy" )
const ( // FindError is an error trying to find the update FindError ErrorType = "find" // PromptError is an UI prompt error PromptError ErrorType = "prompt" // DownloadError is an error trying to download the update DownloadError ErrorType = "download" // ApplyError is an error applying the update ApplyError ErrorType = "apply" // VerifyError is an error verifing the update (signature or digest) VerifyError ErrorType = "verify" )
Errors corresponding to each stage in the update process
type Log ¶
type Log interface { Debug(...interface{}) Info(...interface{}) Debugf(s string, args ...interface{}) Infof(s string, args ...interface{}) Warningf(s string, args ...interface{}) Errorf(s string, args ...interface{}) }
Log is the logging interface for this package
type Property ¶
type Property struct { Name string `codec:"name" json:"name"` Value string `codec:"value" json:"value"` }
Property is a generic key value pair for custom properties
type Update ¶
type Update struct { Version string `json:"version"` Name string `json:"name"` Description string `json:"description"` InstallID string `json:"installId"` RequestID string `json:"requestId"` Type UpdateType `json:"type"` PublishedAt int64 `json:"publishedAt"` Props []Property `codec:"props" json:"props,omitempty"` Asset *Asset `json:"asset,omitempty"` NeedUpdate bool `json:"needUpdate"` }
Update defines an update to apply
type UpdateAction ¶
type UpdateAction string
UpdateAction is the update action requested by the user
const ( // UpdateActionApply means the user accepted and to perform update UpdateActionApply UpdateAction = "apply" // UpdateActionAuto means that auto update is set and to perform update UpdateActionAuto UpdateAction = "auto" // UpdateActionSnooze snoozes an update UpdateActionSnooze UpdateAction = "snooze" // UpdateActionCancel cancels an update UpdateActionCancel UpdateAction = "cancel" // UpdateActionError means an error occurred UpdateActionError UpdateAction = "error" // UpdateActionContinue means no update action was available and the update should continue UpdateActionContinue UpdateAction = "continue" // UpdateActionUIBusy means the UI was busy and the update should be attempted later UpdateActionUIBusy UpdateAction = "uiBusy" )
func (UpdateAction) String ¶
func (u UpdateAction) String() string
String is a unique string label for the action
type UpdateChecker ¶
type UpdateChecker struct {
// contains filtered or unexported fields
}
UpdateChecker runs updates checks every check duration
func NewUpdateChecker ¶
func NewUpdateChecker(updater *Updater, ctx Context, tickDuration time.Duration, log Log) UpdateChecker
NewUpdateChecker creates an update checker
func (UpdateChecker) Count ¶
func (u UpdateChecker) Count() int
Count is number of times the check has been called
func (*UpdateChecker) Start ¶
func (u *UpdateChecker) Start() bool
Start starts the update checker. Returns false if we are already running.
type UpdateOptions ¶
type UpdateOptions struct { // Version is the current version of the app Version string `json:"version"` // Platform is the os type (darwin, darwin-arm64, windows, linux) Platform string `json:"platform"` // DestinationPath is where to apply the update to DestinationPath string `json:"destinationPath"` // URL can override where the updater looks URL string `json:"URL"` // Channel is an alternative channel to get updates from (test, prerelease) Channel string `json:"channel"` // Env is an environment or run mode (prod, staging, devel) Env string `json:"env"` // Arch is an architecure description (x64, i386, arm) Arch string `json:"arch"` // Force is whether to apply the update, even if older or same version Force bool `json:"force"` // OSVersion is the version of the OS OSVersion string `json:"osVersion"` // UpdaterVersion is the version of the updater service UpdaterVersion string `json:"updaterVersion"` // IgnoreSnooze tells the server to send update despite we have snoozed // recently or not. IgnoreSnooze bool `json:"ignoreSnooze"` }
UpdateOptions are options used to find an update
type UpdatePromptOptions ¶
type UpdatePromptOptions struct { AutoUpdate bool `json:"autoUpdate"` OutPath string `json:"outPath"` // Used for windows instead of stdout }
UpdatePromptOptions are the options for UpdatePrompt
type UpdatePromptResponse ¶
type UpdatePromptResponse struct { Action UpdateAction `json:"action"` AutoUpdate bool `json:"autoUpdate"` SnoozeDuration int `json:"snooze_duration"` }
UpdatePromptResponse is the result for UpdatePrompt
type UpdateSource ¶
type UpdateSource interface { // Description is a short description about the update source Description() string // FindUpdate finds an update given options FindUpdate(options UpdateOptions) (*Update, error) }
UpdateSource defines where the updater can find updates
type UpdateType ¶
type UpdateType int
UpdateType is the update type. This is an int type for compatibility.
const ( // UpdateTypeNormal is a normal update UpdateTypeNormal UpdateType = 0 // UpdateTypeBugFix is a bugfix update UpdateTypeBugFix UpdateType = 1 // UpdateTypeCritical is a critical update UpdateTypeCritical UpdateType = 2 )
type UpdateUI ¶
type UpdateUI interface { // UpdatePrompt prompts for an update UpdatePrompt(Update, UpdateOptions, UpdatePromptOptions) (*UpdatePromptResponse, error) }
UpdateUI is a UI interface
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater knows how to find and apply updates
func NewUpdater ¶
func NewUpdater(source UpdateSource, config Config, log Log) *Updater
NewUpdater constructs an Updater
func (*Updater) CheckAndDownload ¶
func (*Updater) CleanupPreviousUpdates ¶
CleanupPreviousUpdates removes temporary files from previous updates.
func (*Updater) FindDownloadedAsset ¶
Inspect previously downloaded updates to avoid redownloading
func (*Updater) NeedUpdate ¶
NeedUpdate returns true if we are out-of-date.