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! {
|
cfg_aliases! {
|
||||||
custom_protocol: { feature = "custom-protocol" },
|
custom_protocol: { feature = "custom-protocol" },
|
||||||
dev: { not(feature = "custom-protocol") },
|
dev: { not(feature = "custom-protocol") },
|
||||||
|
updater: { any(feature = "updater", feature = "__updater-docs") },
|
||||||
|
|
||||||
api_all: { feature = "api-all" },
|
api_all: { feature = "api-all" },
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ use crate::runtime::RuntimeHandle;
|
||||||
#[cfg(feature = "system-tray")]
|
#[cfg(feature = "system-tray")]
|
||||||
use crate::runtime::{SystemTrayEvent as RuntimeSystemTrayEvent, TrayIcon};
|
use crate::runtime::{SystemTrayEvent as RuntimeSystemTrayEvent, TrayIcon};
|
||||||
|
|
||||||
#[cfg(feature = "updater")]
|
#[cfg(updater)]
|
||||||
use crate::updater;
|
use crate::updater;
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[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.
|
/// 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,
|
MainEventsCleared,
|
||||||
/// Updater event.
|
/// Updater event.
|
||||||
#[cfg(feature = "updater")]
|
#[cfg(updater)]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
||||||
Updater(crate::UpdaterEvent),
|
Updater(crate::UpdaterEvent),
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ pub enum RunEvent {
|
||||||
impl From<EventLoopMessage> for RunEvent {
|
impl From<EventLoopMessage> for RunEvent {
|
||||||
fn from(event: EventLoopMessage) -> Self {
|
fn from(event: EventLoopMessage) -> Self {
|
||||||
match event {
|
match event {
|
||||||
#[cfg(feature = "updater")]
|
#[cfg(updater)]
|
||||||
EventLoopMessage::Updater(event) => RunEvent::Updater(event),
|
EventLoopMessage::Updater(event) => RunEvent::Updater(event),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ impl<R: Runtime> ManagerBase<R> for App<R> {
|
||||||
macro_rules! shared_app_impl {
|
macro_rules! shared_app_impl {
|
||||||
($app: ty) => {
|
($app: ty) => {
|
||||||
impl<R: Runtime> $app {
|
impl<R: Runtime> $app {
|
||||||
#[cfg(feature = "updater")]
|
#[cfg(updater)]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
||||||
/// Runs the updater to check if there is a new app version.
|
/// Runs the updater to check if there is a new app version.
|
||||||
/// It is the same as triggering the `tauri://update` event.
|
/// 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> {
|
impl<R: Runtime> App<R> {
|
||||||
/// Runs the updater hook with built-in dialog.
|
/// Runs the updater hook with built-in dialog.
|
||||||
fn run_updater_dialog(&self) {
|
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))?;
|
(self.setup)(&mut app).map_err(|e| crate::Error::Setup(e))?;
|
||||||
|
|
||||||
#[cfg(feature = "updater")]
|
#[cfg(updater)]
|
||||||
app.run_updater();
|
app.run_updater();
|
||||||
|
|
||||||
Ok(app)
|
Ok(app)
|
||||||
|
|
|
@ -64,7 +64,7 @@ pub enum Error {
|
||||||
#[error("error encountered during setup hook: {0}")]
|
#[error("error encountered during setup hook: {0}")]
|
||||||
Setup(Box<dyn std::error::Error + Send>),
|
Setup(Box<dyn std::error::Error + Send>),
|
||||||
/// Tauri updater error.
|
/// Tauri updater error.
|
||||||
#[cfg(any(feature = "updater", feature = "__updater-docs"))]
|
#[cfg(updater)]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
||||||
#[error("Updater: {0}")]
|
#[error("Updater: {0}")]
|
||||||
TauriUpdater(#[from] crate::updater::Error),
|
TauriUpdater(#[from] crate::updater::Error),
|
||||||
|
|
|
@ -158,7 +158,7 @@ pub use tauri_runtime as runtime;
|
||||||
pub mod scope;
|
pub mod scope;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
mod state;
|
mod state;
|
||||||
#[cfg(any(feature = "updater", feature = "__updater-docs"))]
|
#[cfg(updater)]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
||||||
pub mod updater;
|
pub mod updater;
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ pub use {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Updater events.
|
/// Updater events.
|
||||||
#[cfg(any(feature = "updater", feature = "__updater-docs"))]
|
#[cfg(updater)]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum UpdaterEvent {
|
pub enum UpdaterEvent {
|
||||||
|
@ -252,7 +252,7 @@ pub enum UpdaterEvent {
|
||||||
Error(String),
|
Error(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "updater")]
|
#[cfg(updater)]
|
||||||
impl UpdaterEvent {
|
impl UpdaterEvent {
|
||||||
pub(crate) fn status_message(self) -> &'static str {
|
pub(crate) fn status_message(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
|
@ -269,7 +269,7 @@ impl UpdaterEvent {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum EventLoopMessage {
|
pub enum EventLoopMessage {
|
||||||
/// Updater event.
|
/// Updater event.
|
||||||
#[cfg(feature = "updater")]
|
#[cfg(updater)]
|
||||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
|
||||||
Updater(UpdaterEvent),
|
Updater(UpdaterEvent),
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,11 +417,6 @@ impl Update {
|
||||||
// Download and install our update
|
// Download and install our update
|
||||||
// @todo(lemarier): Split into download and install (two step) but need to be thread safe
|
// @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 {
|
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
|
// make sure we can install the update on linux
|
||||||
// We fail here because later we can add more linux support
|
// We fail here because later we can add more linux support
|
||||||
// actually if we use APPIMAGE, our extract path should already
|
// actually if we use APPIMAGE, our extract path should already
|
||||||
|
@ -441,7 +436,7 @@ impl Update {
|
||||||
let resp = ClientBuilder::new()
|
let resp = ClientBuilder::new()
|
||||||
.build()?
|
.build()?
|
||||||
.send(
|
.send(
|
||||||
HttpRequestBuilder::new("GET", url)?
|
HttpRequestBuilder::new("GET", self.download_url.as_str())?
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
// wait 20sec for the firewall
|
// wait 20sec for the firewall
|
||||||
.timeout(20),
|
.timeout(20),
|
||||||
|
@ -481,9 +476,9 @@ impl Update {
|
||||||
// we run the setup, appimage re-install or overwrite the
|
// we run the setup, appimage re-install or overwrite the
|
||||||
// macos .app
|
// macos .app
|
||||||
#[cfg(target_os = "windows")]
|
#[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"))]
|
#[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!
|
// We are done!
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue