pub struct UpdateManager<S = GitHubSource>where
S: Source,{
pub target_application: PathBuf,
pub source: S,
/* private fields */
}Expand description
Drives the three-phase, in-place self-update of an application binary.
An UpdateManager lists the releases offered by its Source, downloads
the asset the source selected for this platform, and then walks through the
prepare → replace → cleanup phases by relaunching the application between
each phase (see the crate-level docs and RESUME_FLAG).
Construct one with UpdateManager::new (which targets the currently
running executable) and customise it with
with_target_application if needed. Which
release asset is downloaded is configured on the Source — see
GitHubSource.
Fields§
§target_application: PathBufThe application binary which will be replaced by the update. Defaults to the currently running executable.
source: SThe source releases are listed and downloaded from.
Implementations§
Source§impl<S> UpdateManager<S>where
S: Source,
impl<S> UpdateManager<S>where
S: Source,
Sourcepub fn new(source: S) -> Self
pub fn new(source: S) -> Self
Create a manager which will update the currently running executable
using the provided release source.
Sourcepub fn with_target_application(self, target_application: PathBuf) -> Self
pub fn with_target_application(self, target_application: PathBuf) -> Self
Override the application binary which will be updated (defaults to the currently running executable).
Sourcepub fn with_relaunch_arg(self, arg: impl Into<OsString>) -> Self
pub fn with_relaunch_arg(self, arg: impl Into<OsString>) -> Self
Append a custom command-line argument passed to every process the updater
relaunches, in addition to the library’s own
RESUME_FLAG and serialized state.
Useful for threading application-specific context through an update — for
example a --trace-context value, or a flag that tweaks behaviour while
the update is in progress. Call it repeatedly to add several arguments;
they are appended in order, after the resume flag.
Sourcepub fn with_relaunch_args<I, A>(self, args: I) -> Self
pub fn with_relaunch_args<I, A>(self, args: I) -> Self
Append several custom command-line arguments to every relaunched process.
See with_relaunch_arg.
Sourcepub fn with_relaunch_env(
self,
key: impl Into<OsString>,
value: impl Into<OsString>,
) -> Self
pub fn with_relaunch_env( self, key: impl Into<OsString>, value: impl Into<OsString>, ) -> Self
Set a custom environment variable on every process the updater relaunches.
Call it repeatedly to set several variables. They are added to (not replacing) the inherited environment of the relaunched process.
Sourcepub fn with_relaunch_envs<I, K, V>(self, envs: I) -> Self
pub fn with_relaunch_envs<I, K, V>(self, envs: I) -> Self
Set several custom environment variables on every relaunched process.
See with_relaunch_env.
Sourcepub async fn get_releases(&self) -> Result<Vec<Release>, Error>
pub async fn get_releases(&self) -> Result<Vec<Release>, Error>
List the releases available from the configured Source.
Sourcepub async fn update(&self, release: &Release) -> Result<bool, Error>
pub async fn update(&self, release: &Release) -> Result<bool, Error>
Begin updating the target_application to
the provided release.
This downloads the new binary, then launches it to continue the update
in a separate process. Returns Ok(true) if an update was started, in
which case the caller should exit promptly so the relaunched process can
replace the running binary.
Sourcepub async fn resume(&self, state: &UpdateState) -> Result<bool, Error>
pub async fn resume(&self, state: &UpdateState) -> Result<bool, Error>
Resume an update from a previously serialized UpdateState.
A consuming application calls this (usually via
resume_from_arg) when it is relaunched with
the RESUME_FLAG. Returns Ok(true) when a phase
was processed and the process should exit.
Sourcepub async fn resume_from_arg(&self, state_json: &str) -> Result<bool, Error>
pub async fn resume_from_arg(&self, state_json: &str) -> Result<bool, Error>
Deserialize an UpdateState from the JSON argument that follows the
RESUME_FLAG on the command line, then
resume the update from it.