mirror of https://github.com/tauri-apps/tauri
feat(core): add cfg alias for the updater feature
This commit is contained in:
parent
4094494a1b
commit
aba3238146
|
@ -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" },
|
||||
|
||||
|
|
|
@ -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<EventLoopMessage> 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<R: Runtime> ManagerBase<R> for App<R> {
|
|||
macro_rules! shared_app_impl {
|
||||
($app: ty) => {
|
||||
impl<R: Runtime> $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<R: Runtime> App<R> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "updater")]
|
||||
#[cfg(updater)]
|
||||
impl<R: Runtime> App<R> {
|
||||
/// Runs the updater hook with built-in dialog.
|
||||
fn run_updater_dialog(&self) {
|
||||
|
@ -1348,7 +1348,7 @@ impl<R: Runtime> Builder<R> {
|
|||
|
||||
(self.setup)(&mut app).map_err(|e| crate::Error::Setup(e))?;
|
||||
|
||||
#[cfg(feature = "updater")]
|
||||
#[cfg(updater)]
|
||||
app.run_updater();
|
||||
|
||||
Ok(app)
|
||||
|
|
|
@ -64,7 +64,7 @@ pub enum Error {
|
|||
#[error("error encountered during setup hook: {0}")]
|
||||
Setup(Box<dyn std::error::Error + Send>),
|
||||
/// 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),
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
|
|
Loading…
Reference in New Issue