From 9d22173f1203ad521c04bb0526981cc61448b4d5 Mon Sep 17 00:00:00 2001 From: Night_Hunter Date: Mon, 25 Nov 2024 18:46:19 +1300 Subject: [PATCH] remove global and change all to user arc --- plugins/updater/src/lib.rs | 8 +++----- plugins/updater/src/updater.rs | 26 ++++++-------------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/plugins/updater/src/lib.rs b/plugins/updater/src/lib.rs index fee88b98..f69cb7f1 100644 --- a/plugins/updater/src/lib.rs +++ b/plugins/updater/src/lib.rs @@ -91,9 +91,7 @@ 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()); - } + builder.version_comparator = version_comparator.clone(); #[cfg(any( target_os = "linux", @@ -125,7 +123,7 @@ impl> UpdaterExt for T { struct UpdaterState { target: Option, config: Config, - version_comparator: Option, + version_comparator: Option, } #[derive(Default)] @@ -133,7 +131,7 @@ pub struct Builder { target: Option, pubkey: Option, installer_args: Vec, - version_comparator: Option, + version_comparator: Option, } impl Builder { diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index e9a87972..58506394 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -93,14 +93,13 @@ impl RemoteRelease { } pub type OnBeforeExit = Arc; -pub(crate) type GlobalVersionComparator = Arc bool + Send + Sync>; +pub type VersionComparator = 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, + pub(crate) version_comparator: Option, executable_path: Option, target: Option, endpoints: Option>, @@ -127,7 +126,6 @@ impl UpdaterBuilder { current_version, config, version_comparator: None, - global_version_comparator: None, executable_path: None, target: None, endpoints: None, @@ -142,7 +140,7 @@ impl UpdaterBuilder { mut self, f: F, ) -> Self { - self.version_comparator = Some(Box::new(f)); + self.version_comparator = Some(Arc::new(f)); self } @@ -224,11 +222,6 @@ 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 @@ -260,7 +253,6 @@ impl UpdaterBuilder { app_name: self.app_name, current_version: self.current_version, version_comparator: self.version_comparator, - global_version_comparator: self.global_version_comparator, timeout: self.timeout, proxy: self.proxy, endpoints, @@ -292,8 +284,7 @@ pub struct Updater { config: Config, app_name: String, current_version: Version, - version_comparator: Option bool + Send + Sync>>, - global_version_comparator: Option, + version_comparator: Option, timeout: Option, proxy: Option, endpoints: Vec, @@ -405,13 +396,8 @@ impl Updater { let should_update = match self.version_comparator.as_ref() { Some(comparator) => comparator(self.current_version.clone(), release.clone()), None => { - match self.global_version_comparator.as_ref() { - Some(comparator) => comparator(self.current_version.clone(), release.clone()), - None => { - // default comparator - release.version > self.current_version - } - } + // default comparator + release.version > self.current_version } };