From aba3238146c26c8ae27b8d0d9940d715f7fb3569 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Thu, 17 Mar 2022 10:41:25 -0300 Subject: [PATCH] feat(core): add cfg alias for the updater feature --- core/tauri/build.rs | 1 + core/tauri/src/app.rs | 12 ++++++------ core/tauri/src/error.rs | 2 +- core/tauri/src/lib.rs | 8 ++++---- core/tauri/src/updater/core.rs | 11 +++-------- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/core/tauri/build.rs b/core/tauri/build.rs index db4d11d16..6fd8354f3 100644 --- a/core/tauri/build.rs +++ b/core/tauri/build.rs @@ -8,6 +8,7 @@ fn main() { cfg_aliases! { custom_protocol: { feature = "custom-protocol" }, dev: { not(feature = "custom-protocol") }, + updater: { any(feature = "updater", feature = "__updater-docs") }, api_all: { feature = "api-all" }, diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index 64da62f88..7dd365ac3 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -46,7 +46,7 @@ use crate::runtime::RuntimeHandle; #[cfg(feature = "system-tray")] use crate::runtime::{SystemTrayEvent as RuntimeSystemTrayEvent, TrayIcon}; -#[cfg(feature = "updater")] +#[cfg(updater)] use crate::updater; #[cfg(target_os = "macos")] @@ -113,7 +113,7 @@ pub enum RunEvent { /// This event is useful as a place to put your code that should be run after all state-changing events have been handled and you want to do stuff (updating state, performing calculations, etc) that happens as the “main body” of your event loop. MainEventsCleared, /// Updater event. - #[cfg(feature = "updater")] + #[cfg(updater)] #[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))] Updater(crate::UpdaterEvent), } @@ -121,7 +121,7 @@ pub enum RunEvent { impl From for RunEvent { fn from(event: EventLoopMessage) -> Self { match event { - #[cfg(feature = "updater")] + #[cfg(updater)] EventLoopMessage::Updater(event) => RunEvent::Updater(event), } } @@ -388,7 +388,7 @@ impl ManagerBase for App { macro_rules! shared_app_impl { ($app: ty) => { impl $app { - #[cfg(feature = "updater")] + #[cfg(updater)] #[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))] /// Runs the updater to check if there is a new app version. /// It is the same as triggering the `tauri://update` event. @@ -575,7 +575,7 @@ impl App { } } -#[cfg(feature = "updater")] +#[cfg(updater)] impl App { /// Runs the updater hook with built-in dialog. fn run_updater_dialog(&self) { @@ -1348,7 +1348,7 @@ impl Builder { (self.setup)(&mut app).map_err(|e| crate::Error::Setup(e))?; - #[cfg(feature = "updater")] + #[cfg(updater)] app.run_updater(); Ok(app) diff --git a/core/tauri/src/error.rs b/core/tauri/src/error.rs index ac08e2da7..b73a94910 100644 --- a/core/tauri/src/error.rs +++ b/core/tauri/src/error.rs @@ -64,7 +64,7 @@ pub enum Error { #[error("error encountered during setup hook: {0}")] Setup(Box), /// Tauri updater error. - #[cfg(any(feature = "updater", feature = "__updater-docs"))] + #[cfg(updater)] #[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))] #[error("Updater: {0}")] TauriUpdater(#[from] crate::updater::Error), diff --git a/core/tauri/src/lib.rs b/core/tauri/src/lib.rs index 2acfdb22b..d2a5020b4 100644 --- a/core/tauri/src/lib.rs +++ b/core/tauri/src/lib.rs @@ -158,7 +158,7 @@ pub use tauri_runtime as runtime; pub mod scope; pub mod settings; mod state; -#[cfg(any(feature = "updater", feature = "__updater-docs"))] +#[cfg(updater)] #[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))] pub mod updater; @@ -229,7 +229,7 @@ pub use { }; /// Updater events. -#[cfg(any(feature = "updater", feature = "__updater-docs"))] +#[cfg(updater)] #[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))] #[derive(Debug, Clone)] pub enum UpdaterEvent { @@ -252,7 +252,7 @@ pub enum UpdaterEvent { Error(String), } -#[cfg(feature = "updater")] +#[cfg(updater)] impl UpdaterEvent { pub(crate) fn status_message(self) -> &'static str { match self { @@ -269,7 +269,7 @@ impl UpdaterEvent { #[derive(Debug, Clone)] pub enum EventLoopMessage { /// Updater event. - #[cfg(feature = "updater")] + #[cfg(updater)] #[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))] Updater(UpdaterEvent), } diff --git a/core/tauri/src/updater/core.rs b/core/tauri/src/updater/core.rs index cb126daa7..efae7f362 100644 --- a/core/tauri/src/updater/core.rs +++ b/core/tauri/src/updater/core.rs @@ -417,11 +417,6 @@ impl Update { // Download and install our update // @todo(lemarier): Split into download and install (two step) but need to be thread safe pub async fn download_and_install(&self, pub_key: String) -> Result { - // download url for selected release - let url = self.download_url.as_str(); - // extract path - let extract_path = &self.extract_path; - // make sure we can install the update on linux // We fail here because later we can add more linux support // actually if we use APPIMAGE, our extract path should already @@ -441,7 +436,7 @@ impl Update { let resp = ClientBuilder::new() .build()? .send( - HttpRequestBuilder::new("GET", url)? + HttpRequestBuilder::new("GET", self.download_url.as_str())? .headers(headers) // wait 20sec for the firewall .timeout(20), @@ -481,9 +476,9 @@ impl Update { // we run the setup, appimage re-install or overwrite the // macos .app #[cfg(target_os = "windows")] - copy_files_and_run(archive_buffer, extract_path, self.with_elevated_task)?; + copy_files_and_run(archive_buffer, &self.extract_path, self.with_elevated_task)?; #[cfg(not(target_os = "windows"))] - copy_files_and_run(archive_buffer, extract_path)?; + copy_files_and_run(archive_buffer, &self.extract_path)?; } // We are done! Ok(())