Struct tauri::updater::UpdateBuilder

source ·
pub struct UpdateBuilder<R: Runtime> { /* private fields */ }
Available on crate feature updater only.
Expand description

An update check builder.

Implementations§

source§

impl<R: Runtime> UpdateBuilder<R>

source

pub fn skip_events(self) -> Self

Do not use the event system to emit information or listen to install the update.

source

pub fn target(self, target: impl Into<String>) -> Self

Sets the current platform’s target name for the updater.

The target is injected in the endpoint URL by replacing {{target}}. Note that this does not affect the {{arch}} variable.

If the updater response JSON includes the platforms field, that object must contain a value for the target key.

By default Tauri uses $OS_NAME as the replacement for {{target}} and $OS_NAME-$ARCH as the key in the platforms object, where $OS_NAME is the current operating system name “linux”, “windows” or “darwin”) and $ARCH is one of the supported architectures (“i686”, “x86_64”, “armv7” or “aarch64”).

See Builder::updater_target for a way to set the target globally.

§Examples
§Use a macOS Universal binary target name

In this example, we set the updater target only on macOS. On other platforms, we set the default target. Note that {{target}} will be replaced with darwin-universal, but {{arch}} is still the running platform’s architecture.

tauri::Builder::default()
  .setup(|app| {
    let handle = app.handle();
    tauri::async_runtime::spawn(async move {
      let builder = tauri::updater::builder(handle).target(if cfg!(target_os = "macos") {
        "darwin-universal".to_string()
      } else {
        tauri::updater::target().unwrap()
      });
      match builder.check().await {
        Ok(update) => {}
        Err(error) => {}
      }
    });
    Ok(())
  });
§Append debug information to the target

This allows you to provide updates for both debug and release applications.

tauri::Builder::default()
  .setup(|app| {
    let handle = app.handle();
    tauri::async_runtime::spawn(async move {
      let kind = if cfg!(debug_assertions) { "debug" } else { "release" };
      let builder = tauri::updater::builder(handle).target(format!("{}-{kind}", tauri::updater::target().unwrap()));
      match builder.check().await {
        Ok(update) => {}
        Err(error) => {}
      }
    });
    Ok(())
  });
§Use the platform’s target triple
tauri::Builder::default()
  .setup(|app| {
    let handle = app.handle();
    tauri::async_runtime::spawn(async move {
      let builder = tauri::updater::builder(handle).target(tauri::utils::platform::target_triple().unwrap());
      match builder.check().await {
        Ok(update) => {}
        Err(error) => {}
      }
    });
    Ok(())
  });
source

pub fn should_install<F: FnOnce(&Version, &RemoteRelease) -> bool + Send + 'static>( self, f: F ) -> Self

Sets a closure that is invoked to compare the current version and the latest version returned by the updater server. The first argument is the current version, and the second one is the latest version.

The closure must return true if the update should be installed.

§Examples
  • Always install the version returned by the server:
tauri::Builder::default()
  .setup(|app| {
    tauri::updater::builder(app.handle()).should_install(|_current, _latest| true);
    Ok(())
  });
source

pub fn timeout(self, timeout: Duration) -> Self

Sets the timeout for the requests to the updater endpoints.

source

pub fn header<K, V>(self, key: K, value: V) -> Result<Self>

Adds a header for the requests to the updater endpoints.

source

pub fn endpoints(self, urls: &[String]) -> Self

Adds a list of endpoints to fetch the update.

source

pub async fn check(self) -> Result<UpdateResponse<R>>

Check if an update is available.

§Examples
tauri::Builder::default()
  .setup(|app| {
    let handle = app.handle();
    tauri::async_runtime::spawn(async move {
      match tauri::updater::builder(handle).check().await {
        Ok(update) => {
          if update.is_update_available() {
            update.download_and_install().await.unwrap();
          }
        }
        Err(e) => {
          println!("failed to get update: {}", e);
        }
      }
    });
    Ok(())
  });

If ther server responds with status code 204, this method will return Error::UpToDate

Trait Implementations§

source§

impl<R: Debug + Runtime> Debug for UpdateBuilder<R>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more