diff --git a/plugins/updater/src/lib.rs b/plugins/updater/src/lib.rs index b45f91a2..c2188dde 100644 --- a/plugins/updater/src/lib.rs +++ b/plugins/updater/src/lib.rs @@ -13,8 +13,9 @@ 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::{ plugin::{Builder as PluginBuilder, TauriPlugin}, Manager, Runtime, @@ -71,7 +72,7 @@ impl> UpdaterExt for T { fn updater_builder(&self) -> UpdaterBuilder { let app = self.app_handle(); let package_info = app.package_info(); - let UpdaterState { config, target } = self.state::().inner(); + let UpdaterState { config, target, version_comparator } = self.state::().inner(); let mut builder = UpdaterBuilder::new( package_info.name.clone(), @@ -88,6 +89,10 @@ impl> UpdaterExt for T { builder = builder.current_exe_args(args); } + if let Some(version_comparator) = version_comparator { + builder = builder.global_version_comparator(version_comparator.clone()); + } + #[cfg(any( target_os = "linux", target_os = "dragonfly", @@ -118,6 +123,7 @@ impl> UpdaterExt for T { struct UpdaterState { target: Option, config: Config, + version_comparator: Option, } #[derive(Default)] @@ -125,6 +131,7 @@ pub struct Builder { target: Option, pubkey: Option, installer_args: Vec, + version_comparator: Option, } impl Builder { @@ -165,9 +172,18 @@ impl Builder { self } + pub fn version_comparator bool + Send + Sync + 'static>( + mut self, + f: F, + ) -> Self { + self.version_comparator.replace(Arc::new(f)); + self + } + pub fn build(self) -> TauriPlugin { let pubkey = self.pubkey; let target = self.target; + let version_comparator = self.version_comparator; let installer_args = self.installer_args; PluginBuilder::::new("updater") .setup(move |app, api| { @@ -178,7 +194,7 @@ impl Builder { if let Some(windows) = &mut config.windows { windows.installer_args.extend_from_slice(&installer_args); } - app.manage(UpdaterState { target, config }); + app.manage(UpdaterState { target, config, version_comparator }); Ok(()) }) .invoke_handler(tauri::generate_handler![ diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index b1dadd6d..1b608d88 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -93,12 +93,14 @@ impl RemoteRelease { } pub type OnBeforeExit = Arc; +pub(crate) type GlobalVersionComparator = Arc bool + Send + Sync>; pub struct UpdaterBuilder { app_name: String, current_version: Version, config: Config, version_comparator: Option bool + Send + Sync>>, + global_version_comparator: Option, executable_path: Option, target: Option, endpoints: Option>, @@ -125,6 +127,7 @@ impl UpdaterBuilder { current_version, config, version_comparator: None, + global_version_comparator: None, executable_path: None, target: None, endpoints: None, @@ -221,6 +224,14 @@ impl UpdaterBuilder { self } + pub(crate) fn global_version_comparator( + mut self, + f: GlobalVersionComparator, + ) -> Self { + self.global_version_comparator.replace(f); + self + } + pub fn build(self) -> Result { let endpoints = self .endpoints