pub struct Updater { /* private fields */ }Expand description
A package’s updates: one thread checks and downloads, the state is shared, and nothing
is applied until Updater::apply. Clones share the thread and the state; the thread
ends with the last clone.
Implementations§
Source§impl Updater
impl Updater
Sourcepub fn new(spec: &'static PackageSpec, source: Source) -> Result<Updater, Error>
pub fn new(spec: &'static PackageSpec, source: Source) -> Result<Updater, Error>
Error::NotPackaged outside a package.
Sourcepub fn on_change(&self, f: impl Fn() + Send + Sync + 'static)
pub fn on_change(&self, f: impl Fn() + Send + Sync + 'static)
Called after every change of state: a GUI asks for a repaint here. Runs on the
updater’s thread, or on the thread calling apply when before_apply refuses.
Sourcepub fn status(&self) -> PackageStatus
pub fn status(&self) -> PackageStatus
The running version and what the updater is doing. Never waits for a check.
Sourcepub fn run_in_background(&self, every: Duration)
pub fn run_in_background(&self, every: Duration)
Look at once and then every every, downloading what is found. A second call
replaces the interval.
Sourcepub fn apply(&self, after: After) -> Result<(), Error>
pub fn apply(&self, after: After) -> Result<(), Error>
Runs before_apply, then hands the downloaded update to Velopack’s updater, which
waits for this process to end before it replaces the files.
Who ends the process: for After::Exit this call exits it and returns only on an
error. For After::RestartApp and After::RestartWith it returns Ok, and the
caller must end the process soon (Velopack waits 60 seconds), a GUI by closing its
window so that what it saves on exit is saved.
Once this returns Ok, the update is Velopack’s: if the app cancels the close (a
“save your changes?” it answers with Cancel) or otherwise keeps running, a later
call in this process fails with Error::Applying. Whether the update is applied
then is up to Velopack’s updater, which waits for this process to end.
An error: nothing downloaded, an apply already running on another thread
(Error::Applying), before_apply refused (nothing is applied, and a later call
tries again), or Velopack failed.
Sourcepub fn apply_pending_at_start(&self) -> Result<(), Error>
pub fn apply_pending_at_start(&self) -> Result<(), Error>
For a GUI’s start only, before its window opens: apply an update downloaded earlier
and never applied, and start the app again; this call then exits the process itself,
as there is no window to close. Looks at the downloaded packages only, never the
network, so the start is not delayed. Ok when there is none, and on a start by
Velopack’s updater: an update it failed to apply would otherwise be tried at every
start.
Only the app’s single GUI instance may call this: an app that can run two must
prevent the second first (corundum-framework-platform’s instance, or the gui
crate’s WindowOptions::single_instance), or the second applies under the first.