github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/updater/protocol.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package updater 5 6 // Asset describes a downloadable file 7 type Asset struct { 8 Name string `json:"name"` 9 URL string `json:"url"` 10 Digest string `json:"digest"` 11 Signature string `json:"signature"` 12 LocalPath string `json:"localPath"` 13 } 14 15 // UpdateType is the update type. 16 // This is an int type for compatibility. 17 type UpdateType int 18 19 const ( 20 // UpdateTypeNormal is a normal update 21 UpdateTypeNormal UpdateType = 0 22 // UpdateTypeBugFix is a bugfix update 23 UpdateTypeBugFix UpdateType = 1 24 // UpdateTypeCritical is a critical update 25 UpdateTypeCritical UpdateType = 2 26 ) 27 28 // Property is a generic key value pair for custom properties 29 type Property struct { 30 Name string `codec:"name" json:"name"` 31 Value string `codec:"value" json:"value"` 32 } 33 34 // Update defines an update to apply 35 type Update struct { 36 Version string `json:"version"` 37 Name string `json:"name"` 38 Description string `json:"description"` 39 InstallID string `json:"installId"` 40 RequestID string `json:"requestId"` 41 Type UpdateType `json:"type"` 42 PublishedAt int64 `json:"publishedAt"` 43 Props []Property `codec:"props" json:"props,omitempty"` 44 Asset *Asset `json:"asset,omitempty"` 45 NeedUpdate bool `json:"needUpdate"` 46 } 47 48 func (u Update) missingAsset() bool { 49 return u.Asset == nil || u.Asset.URL == "" 50 51 } 52 53 // UpdateOptions are options used to find an update 54 type UpdateOptions struct { 55 // Version is the current version of the app 56 Version string `json:"version"` 57 // Platform is the os type (darwin, darwin-arm64, windows, linux) 58 Platform string `json:"platform"` 59 // DestinationPath is where to apply the update to 60 DestinationPath string `json:"destinationPath"` 61 // URL can override where the updater looks 62 URL string `json:"URL"` 63 // Channel is an alternative channel to get updates from (test, prerelease) 64 Channel string `json:"channel"` 65 // Env is an environment or run mode (prod, staging, devel) 66 Env string `json:"env"` 67 // Arch is an architecure description (x64, i386, arm) 68 Arch string `json:"arch"` 69 // Force is whether to apply the update, even if older or same version 70 Force bool `json:"force"` 71 // OSVersion is the version of the OS 72 OSVersion string `json:"osVersion"` 73 // UpdaterVersion is the version of the updater service 74 UpdaterVersion string `json:"updaterVersion"` 75 // IgnoreSnooze tells the server to send update despite we have snoozed 76 // recently or not. 77 IgnoreSnooze bool `json:"ignoreSnooze"` 78 } 79 80 // UpdateAction is the update action requested by the user 81 type UpdateAction string 82 83 const ( 84 // UpdateActionApply means the user accepted and to perform update 85 UpdateActionApply UpdateAction = "apply" 86 // UpdateActionAuto means that auto update is set and to perform update 87 UpdateActionAuto UpdateAction = "auto" 88 // UpdateActionSnooze snoozes an update 89 UpdateActionSnooze UpdateAction = "snooze" 90 // UpdateActionCancel cancels an update 91 UpdateActionCancel UpdateAction = "cancel" 92 // UpdateActionError means an error occurred 93 UpdateActionError UpdateAction = "error" 94 // UpdateActionContinue means no update action was available and the update should continue 95 UpdateActionContinue UpdateAction = "continue" 96 // UpdateActionUIBusy means the UI was busy and the update should be attempted later 97 UpdateActionUIBusy UpdateAction = "uiBusy" 98 ) 99 100 // String is a unique string label for the action 101 func (u UpdateAction) String() string { 102 return string(u) 103 } 104 105 // UpdatePromptOptions are the options for UpdatePrompt 106 type UpdatePromptOptions struct { 107 AutoUpdate bool `json:"autoUpdate"` 108 OutPath string `json:"outPath"` // Used for windows instead of stdout 109 } 110 111 // UpdatePromptResponse is the result for UpdatePrompt 112 type UpdatePromptResponse struct { 113 Action UpdateAction `json:"action"` 114 AutoUpdate bool `json:"autoUpdate"` 115 SnoozeDuration int `json:"snooze_duration"` 116 } 117 118 // UpdateUI is a UI interface 119 type UpdateUI interface { 120 // UpdatePrompt prompts for an update 121 UpdatePrompt(Update, UpdateOptions, UpdatePromptOptions) (*UpdatePromptResponse, error) 122 }