updateui 实验性
实验性
本包属于实验层:任何 0.x 版本都可能有不兼容变化(docs/release.md「API 稳定性」)。
import "github.com/tangoui/tango/service/updater/updateui"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package updateui is a ready-made update window for apps that use service/updater: it checks for updates in the background, shows what a new release contains, downloads it with progress, and restarts into it when the user agrees.
u := &updater.Updater{ManifestURL: "...", PublicKey: "...", Version: "1.2.0", AppID: "com.example.notes"}
stop, err := updateui.Start(app, u, updateui.Options{}) // after the app is ready
...
updateui.CheckNow(app, u, updateui.Options{}) // from a "Check for Updates…" menu item
The window is drawn by package ui in a window of its own (uihost.Open), so WebView apps and Go-drawn apps use it alike; it follows the app's theme, light or dark appearance and language. Start also calls Updater.Confirm, so a new version is kept after it starts.
One *updater.Updater should be driven by one of updateui or the jsapi updater bridge (jsapi InstallUpdater), not both: the Updater is not safe for concurrent use and both install an OnEvent hook.
Experimental: this package's API may change in any 0.x release (see docs/release.md, "API 稳定性").
常量
const (
DefaultInterval = 24 * time.Hour // between background checks
DefaultFirstDelay = 30 * time.Second // after Start, before the first one
)Default check timing.
函数
func CheckNow
func CheckNow(app *tango.App, u *updater.Updater, opts Options)CheckNow checks for an update right away and shows the result in the window, including "up to date" and errors (for a "Check for Updates…" menu item). While a check or download runs it just shows the window. It returns at once; the check runs on its own goroutine.
func Start
func Start(app *tango.App, u *updater.Updater, opts Options) (stop func(), err error)Start shows the update window when an update is found: it confirms a newly installed version (Updater.Confirm, so it is kept), offers an update downloaded at an earlier launch, then checks in the background every Options.Interval. Call it once the app is running (App.OnReady or later). It returns an error, and changes nothing, when u lacks ManifestURL, Version or a public key. stop ends the background checks, closes the window and gives u back its own OnEvent; calling Start again for the same Updater returns the same stop. A Start while an earlier stop of the same Updater is still running waits for it to finish.
stop waits for a running check, download or install to end (a check and a download are cancelled; an install, which is short, is not). So while Start or stop runs on the main thread, the app's own u.OnEvent must not wait for the main thread (tango.Await): neither would return.
类型
Options
type Options struct {
// Interval is the time between background checks: 0 means
// DefaultInterval, a negative value turns background checks off
// (CheckNow still works).
Interval time.Duration
// FirstDelay is how long after Start the first background check
// waits at least (0 means DefaultFirstDelay), so it does not slow
// down the app's start; a check is never sooner than Interval after
// the previous one, across launches.
FirstDelay time.Duration
// Window sets the window's theme, design flavor and locale like for
// uihost.Open; the title and size are updateui's unless Surface sets
// them. The window is always auxiliary (Surface.Auxiliary): it does
// not keep the app running when the app's other windows close.
Window uihost.Options
// Text replaces every text of the window; nil uses the built-in
// English, Simplified Chinese, Traditional Chinese or Japanese texts
// for i18n.Locale(), following locale changes.
Text *Strings
}Options configures Start and CheckNow.
Strings
type Strings struct {
Title string // window title
Checking string
NewVersion string // "%s is available (you have %s)"
Released string // "Released %s"
Notes string // heading of the release notes
Skip string // skip this version
Later string // remind me later
Install string // download and install
Downloading string
Patch string // the download is an incremental update
Full string // the download is the full release
Cancel string
Ready string // downloaded and verified
RestartNow string
// InstallNextLaunch keeps the download and asks again at the next launch.
InstallNextLaunch string
Installing string // Apply is preparing the new version
Downloaded string // offered at launch: an update was downloaded earlier
Error string
Retry string
Close string
UpToDate string // "You're up to date (%s)"
RolledBack string // "The last update did not start; restored %s"
Unsupported string // this installation cannot update itself
OpenDownloadPage string
}Strings are the texts of the update window. Fields holding a format verb are used with fmt.Sprintf: NewVersion takes the new and the running version, Released the release date, UpToDate and RolledBack the running version.