Struct tauri::updater::UpdateBuilder
source · [−]pub struct UpdateBuilder<R: Runtime> { /* private fields */ }
updater
only.Expand description
An update check builder.
Implementations
sourceimpl<R: Runtime> UpdateBuilder<R>
impl<R: Runtime> UpdateBuilder<R>
sourcepub fn skip_events(self) -> Self
pub fn skip_events(self) -> Self
Do not use the event system to emit information or listen to install the update.
sourcepub fn target(self, target: impl Into<String>) -> Self
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!("{}-{}", tauri::updater::target().unwrap(), kind));
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(())
});
sourcepub fn should_install<F: FnOnce(&Version, &RemoteRelease) -> bool + Send + 'static>(
self,
f: F
) -> Self
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(())
});
sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Sets the timeout for the requests to the updater endpoints.
sourcepub fn header<K, V>(self, key: K, value: V) -> Result<Self> where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
pub fn header<K, V>(self, key: K, value: V) -> Result<Self> where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
Add a Header
to the request.
sourcepub async fn check(self) -> Result<UpdateResponse<R>>
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) => {}
Err(error) => {}
}
});
Ok(())
});
Trait Implementations
Auto Trait Implementations
impl<R> !RefUnwindSafe for UpdateBuilder<R>
impl<R> Send for UpdateBuilder<R>
impl<R> !Sync for UpdateBuilder<R>
impl<R> Unpin for UpdateBuilder<R> where
<R as Runtime<EventLoopMessage>>::ClipboardManager: Unpin,
<R as Runtime<EventLoopMessage>>::GlobalShortcutManager: Unpin,
<R as Runtime<EventLoopMessage>>::Handle: Unpin,
<R as Runtime<EventLoopMessage>>::TrayHandler: Unpin,
impl<R> !UnwindSafe for UpdateBuilder<R>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more