rename + add to download

pull/2430/head
goenning 5 months ago
parent 0bc19315af
commit c89f6d5354
No known key found for this signature in database
GPG Key ID: 853BA56FC914ED48

@ -3,4 +3,4 @@
"updater-js": minor "updater-js": minor
--- ---
Add `on_before_request` hook to the updater plugin. Add `configure_client` hook to the updater plugin.

@ -115,7 +115,7 @@ pub struct UpdaterBuilder {
installer_args: Vec<OsString>, installer_args: Vec<OsString>,
current_exe_args: Vec<OsString>, current_exe_args: Vec<OsString>,
on_before_exit: Option<OnBeforeExit>, on_before_exit: Option<OnBeforeExit>,
on_before_request: Option<OnBeforeRequest>, configure_client: Option<OnBeforeRequest>,
} }
impl UpdaterBuilder { impl UpdaterBuilder {
@ -142,7 +142,7 @@ impl UpdaterBuilder {
timeout: None, timeout: None,
proxy: None, proxy: None,
on_before_exit: None, on_before_exit: None,
on_before_request: None, configure_client: None,
} }
} }
@ -245,13 +245,13 @@ impl UpdaterBuilder {
/// Allows you to modify the `reqwest`` client builder before the HTTP request is sent. /// Allows you to modify the `reqwest`` client builder before the HTTP request is sent.
/// ///
/// Note that `reqwest` crate may be updated in minor releases of tauri-plugin-updater. /// Note that `reqwest` crate may be updated in minor releases of tauri-plugin-updater.
/// Therefore it's recommended to pin the plugin to at least a minor version when you're using `on_before_request`. /// Therefore it's recommended to pin the plugin to at least a minor version when you're using `configure_client`.
/// ///
pub fn on_before_request<F: Fn(ClientBuilder) -> ClientBuilder + Send + Sync + 'static>( pub fn configure_client<F: Fn(ClientBuilder) -> ClientBuilder + Send + Sync + 'static>(
mut self, mut self,
f: F, f: F,
) -> Self { ) -> Self {
self.on_before_request.replace(Arc::new(f)); self.configure_client.replace(Arc::new(f));
self self
} }
@ -298,7 +298,7 @@ impl UpdaterBuilder {
headers: self.headers, headers: self.headers,
extract_path, extract_path,
on_before_exit: self.on_before_exit, on_before_exit: self.on_before_exit,
on_before_request: self.on_before_request, configure_client: self.configure_client,
}) })
} }
} }
@ -333,7 +333,7 @@ pub struct Updater {
headers: HeaderMap, headers: HeaderMap,
extract_path: PathBuf, extract_path: PathBuf,
on_before_exit: Option<OnBeforeExit>, on_before_exit: Option<OnBeforeExit>,
on_before_request: Option<OnBeforeRequest>, configure_client: Option<OnBeforeRequest>,
#[allow(unused)] #[allow(unused)]
installer_args: Vec<OsString>, installer_args: Vec<OsString>,
#[allow(unused)] #[allow(unused)]
@ -395,8 +395,8 @@ impl Updater {
request = request.proxy(proxy); request = request.proxy(proxy);
} }
if let Some(ref on_before_request) = self.on_before_request { if let Some(ref configure_client) = self.configure_client {
request = on_before_request(request); request = configure_client(request);
} }
let response = request let response = request
@ -463,6 +463,7 @@ impl Updater {
headers: self.headers.clone(), headers: self.headers.clone(),
installer_args: self.installer_args.clone(), installer_args: self.installer_args.clone(),
current_exe_args: self.current_exe_args.clone(), current_exe_args: self.current_exe_args.clone(),
configure_client: self.configure_client.clone(),
}) })
} else { } else {
None None
@ -511,6 +512,7 @@ pub struct Update {
installer_args: Vec<OsString>, installer_args: Vec<OsString>,
#[allow(unused)] #[allow(unused)]
current_exe_args: Vec<OsString>, current_exe_args: Vec<OsString>,
configure_client: Option<OnBeforeRequest>,
} }
impl Resource for Update {} impl Resource for Update {}
@ -539,6 +541,9 @@ impl Update {
let proxy = reqwest::Proxy::all(proxy.as_str())?; let proxy = reqwest::Proxy::all(proxy.as_str())?;
request = request.proxy(proxy); request = request.proxy(proxy);
} }
if let Some(ref configure_client) = self.configure_client {
request = configure_client(request);
}
let response = request let response = request
.build()? .build()?
.get(self.download_url.clone()) .get(self.download_url.clone())

Loading…
Cancel
Save