Skip to main content

Launcher

Trait Launcher 

Source
pub trait Launcher {
    // Provided methods
    fn resume_args(&self, state_json: &str) -> Vec<OsString> { ... }
    fn extra_args(&self) -> Vec<OsString> { ... }
    fn extra_envs(&self) -> Vec<(OsString, OsString)> { ... }
    fn launch(&self, app_path: &Path, state: &UpdateState) -> Result<(), Error> { ... }
    fn detach(&self, cmd: &mut Command) { ... }
    fn spawn(&self, cmd: Command) -> Result<(), Error> { ... }
}
Expand description

Launches the application binary to drive the next phase of an update.

Every method has a default implementation, so the simplest custom launcher is an empty impl Launcher for MyLauncher {} (equivalent to a bare DefaultLauncher). Customise as much or as little as you need:

  • override resume_args to change how the update state is handed to the relaunched process (e.g. via a sub-command rather than the default RESUME_FLAG);
  • override extra_args / extra_envs to add your own arguments / environment variables to the relaunch (DefaultLauncher exposes builders for these, so you usually don’t need a custom launcher just for that);
  • override launch for complete control over the relaunch command, or spawn to change how the child is started.

Install a custom launcher with UpdateManager::with_launcher.

Provided Methods§

Source

fn resume_args(&self, state_json: &str) -> Vec<OsString>

The arguments that carry the serialized resume state_json to the relaunched process.

The default passes the library’s RESUME_FLAG followed by the JSON, which a consuming main() detects (before any other argument parsing) and forwards to resume_from_arg. Override it to use a different convention — for example handing the state to a sub-command:

use std::ffi::OsString;
use update_rs::Launcher;

struct SubcommandLauncher;
impl Launcher for SubcommandLauncher {
    fn resume_args(&self, state_json: &str) -> Vec<OsString> {
        vec!["update".into(), "--state".into(), state_json.into()]
    }
}
Source

fn extra_args(&self) -> Vec<OsString>

Extra command-line arguments to append to the relaunch command, after the resume_args.

The default adds none; DefaultLauncher returns the arguments configured via DefaultLauncher::with_arg.

Source

fn extra_envs(&self) -> Vec<(OsString, OsString)>

Extra environment variables to set on the relaunched process (added to, not replacing, the inherited environment).

The default sets none; DefaultLauncher returns the variables configured via DefaultLauncher::with_env.

Source

fn launch(&self, app_path: &Path, state: &UpdateState) -> Result<(), Error>

Build and spawn the command that relaunches app_path to continue the update with state.

The default builds app_path <resume_args> <extra_args> with the extra_envs and the platform detach flags, then spawns it. Override this for complete control over the relaunch command, reusing resume_args, detach and spawn as needed.

Source

fn detach(&self, cmd: &mut Command)

Apply the platform-specific flags that detach the relaunched process from the current console so it survives the parent exiting (a detached process in its own group on Windows). A no-op on non-Windows platforms. Exposed so custom launch implementations can reuse it.

Source

fn spawn(&self, cmd: Command) -> Result<(), Error>

Spawn the prepared Command. The default starts the child process and returns immediately. This is the single seam the default launch relies on, so tests can mock it.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§