mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-22 21:30:44 +02:00
feat(updater): add Builder::default_version_comparator (#1919)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
'updater': 'minor'
|
||||||
|
'updater-js': 'minor'
|
||||||
|
---
|
||||||
|
|
||||||
|
Add `tauri_plugin_updater::Builder::default_version_comparator` method to set the default version comparator for the updater.
|
||||||
@@ -11,8 +11,9 @@
|
|||||||
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
|
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
use std::ffi::OsString;
|
use std::{ffi::OsString, sync::Arc};
|
||||||
|
|
||||||
|
use semver::Version;
|
||||||
use tauri::{
|
use tauri::{
|
||||||
plugin::{Builder as PluginBuilder, TauriPlugin},
|
plugin::{Builder as PluginBuilder, TauriPlugin},
|
||||||
Manager, Runtime,
|
Manager, Runtime,
|
||||||
@@ -69,7 +70,11 @@ impl<R: Runtime, T: Manager<R>> UpdaterExt<R> for T {
|
|||||||
fn updater_builder(&self) -> UpdaterBuilder {
|
fn updater_builder(&self) -> UpdaterBuilder {
|
||||||
let app = self.app_handle();
|
let app = self.app_handle();
|
||||||
let package_info = app.package_info();
|
let package_info = app.package_info();
|
||||||
let UpdaterState { config, target } = self.state::<UpdaterState>().inner();
|
let UpdaterState {
|
||||||
|
config,
|
||||||
|
target,
|
||||||
|
version_comparator,
|
||||||
|
} = self.state::<UpdaterState>().inner();
|
||||||
|
|
||||||
let mut builder = UpdaterBuilder::new(
|
let mut builder = UpdaterBuilder::new(
|
||||||
package_info.name.clone(),
|
package_info.name.clone(),
|
||||||
@@ -86,6 +91,8 @@ impl<R: Runtime, T: Manager<R>> UpdaterExt<R> for T {
|
|||||||
builder = builder.current_exe_args(args);
|
builder = builder.current_exe_args(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
builder.version_comparator = version_comparator.clone();
|
||||||
|
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
target_os = "dragonfly",
|
target_os = "dragonfly",
|
||||||
@@ -116,6 +123,7 @@ impl<R: Runtime, T: Manager<R>> UpdaterExt<R> for T {
|
|||||||
struct UpdaterState {
|
struct UpdaterState {
|
||||||
target: Option<String>,
|
target: Option<String>,
|
||||||
config: Config,
|
config: Config,
|
||||||
|
version_comparator: Option<VersionComparator>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -123,6 +131,7 @@ pub struct Builder {
|
|||||||
target: Option<String>,
|
target: Option<String>,
|
||||||
pubkey: Option<String>,
|
pubkey: Option<String>,
|
||||||
installer_args: Vec<OsString>,
|
installer_args: Vec<OsString>,
|
||||||
|
default_version_comparator: Option<VersionComparator>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Builder {
|
impl Builder {
|
||||||
@@ -163,9 +172,20 @@ impl Builder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn default_version_comparator<
|
||||||
|
F: Fn(Version, RemoteRelease) -> bool + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
|
mut self,
|
||||||
|
f: F,
|
||||||
|
) -> Self {
|
||||||
|
self.default_version_comparator.replace(Arc::new(f));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build<R: Runtime>(self) -> TauriPlugin<R, Config> {
|
pub fn build<R: Runtime>(self) -> TauriPlugin<R, Config> {
|
||||||
let pubkey = self.pubkey;
|
let pubkey = self.pubkey;
|
||||||
let target = self.target;
|
let target = self.target;
|
||||||
|
let version_comparator = self.default_version_comparator;
|
||||||
let installer_args = self.installer_args;
|
let installer_args = self.installer_args;
|
||||||
PluginBuilder::<R, Config>::new("updater")
|
PluginBuilder::<R, Config>::new("updater")
|
||||||
.setup(move |app, api| {
|
.setup(move |app, api| {
|
||||||
@@ -176,7 +196,11 @@ impl Builder {
|
|||||||
if let Some(windows) = &mut config.windows {
|
if let Some(windows) = &mut config.windows {
|
||||||
windows.installer_args.extend_from_slice(&installer_args);
|
windows.installer_args.extend_from_slice(&installer_args);
|
||||||
}
|
}
|
||||||
app.manage(UpdaterState { target, config });
|
app.manage(UpdaterState {
|
||||||
|
target,
|
||||||
|
config,
|
||||||
|
version_comparator,
|
||||||
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
|||||||
@@ -93,12 +93,13 @@ impl RemoteRelease {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type OnBeforeExit = Arc<dyn Fn() + Send + Sync + 'static>;
|
pub type OnBeforeExit = Arc<dyn Fn() + Send + Sync + 'static>;
|
||||||
|
pub type VersionComparator = Arc<dyn Fn(Version, RemoteRelease) -> bool + Send + Sync>;
|
||||||
|
|
||||||
pub struct UpdaterBuilder {
|
pub struct UpdaterBuilder {
|
||||||
app_name: String,
|
app_name: String,
|
||||||
current_version: Version,
|
current_version: Version,
|
||||||
config: Config,
|
config: Config,
|
||||||
version_comparator: Option<Box<dyn Fn(Version, RemoteRelease) -> bool + Send + Sync>>,
|
pub(crate) version_comparator: Option<VersionComparator>,
|
||||||
executable_path: Option<PathBuf>,
|
executable_path: Option<PathBuf>,
|
||||||
target: Option<String>,
|
target: Option<String>,
|
||||||
endpoints: Option<Vec<Url>>,
|
endpoints: Option<Vec<Url>>,
|
||||||
@@ -139,7 +140,7 @@ impl UpdaterBuilder {
|
|||||||
mut self,
|
mut self,
|
||||||
f: F,
|
f: F,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.version_comparator = Some(Box::new(f));
|
self.version_comparator = Some(Arc::new(f));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,7 +284,7 @@ pub struct Updater {
|
|||||||
config: Config,
|
config: Config,
|
||||||
app_name: String,
|
app_name: String,
|
||||||
current_version: Version,
|
current_version: Version,
|
||||||
version_comparator: Option<Box<dyn Fn(Version, RemoteRelease) -> bool + Send + Sync>>,
|
version_comparator: Option<VersionComparator>,
|
||||||
timeout: Option<Duration>,
|
timeout: Option<Duration>,
|
||||||
proxy: Option<Url>,
|
proxy: Option<Url>,
|
||||||
endpoints: Vec<Url>,
|
endpoints: Vec<Url>,
|
||||||
|
|||||||
Reference in New Issue
Block a user