Skip to content

Commit

Permalink
refactor(core): move updater to a plugin (#6919)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored May 9, 2023
1 parent 60cf9ed commit b072daa
Show file tree
Hide file tree
Showing 42 changed files with 34 additions and 6,805 deletions.
7 changes: 7 additions & 0 deletions .changes/move-updater.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"api": patch
"tauri": patch
"tauri-utils": patch
---

Moved the `updater` feature to its own plugin in the plugins-workspace repository.
107 changes: 0 additions & 107 deletions .github/workflows/artifacts-updater.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .scripts/update-lockfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

declare -a examples=("api" "sidecar" "updater" "resources" "tauri-dynamic-lib" "workspace")
declare -a examples=("api" "sidecar" "resources" "tauri-dynamic-lib" "workspace")
declare -a tooling=("bench" "cli" "webdriver")

for example in "${examples[@]}"
Expand Down
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ members = [

# integration tests
"core/tests/restart",
"core/tests/app-updater",
]

exclude = [
# examples that can be compiled with the tauri CLI
"examples/api/src-tauri",
"examples/updater/src-tauri",
"examples/resources/src-tauri",
"examples/sidecar/src-tauri",
"examples/web/core",
Expand Down
10 changes: 1 addition & 9 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2206,22 +2206,14 @@ impl TauriConfig {
#[allow(dead_code)]
pub fn all_features() -> Vec<&'static str> {
let mut features = AllowlistConfig::all_features();
features.extend(vec![
"updater",
"system-tray",
"macos-private-api",
"isolation",
]);
features.extend(vec!["system-tray", "macos-private-api", "isolation"]);
features
}

/// Returns the enabled Cargo features.
#[allow(dead_code)]
pub fn features(&self) -> Vec<&str> {
let mut features = self.allowlist.to_features();
if self.updater.active {
features.push("updater");
}
if self.system_tray.is_some() {
features.push("system-tray");
}
Expand Down
14 changes: 2 additions & 12 deletions core/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ flate2 = "1.0"
http = "0.2"
dirs-next = "2.0"
percent-encoding = "2.2"
base64 = { version = "0.21", optional = true }
reqwest = { version = "0.11", default-features = false, features = [ "json", "stream" ] }
bytes = { version = "1", features = [ "serde" ] }
raw-window-handle = "0.5"
minisign-verify = { version = "0.2", optional = true }
time = { version = "0.3", features = [ "parsing", "formatting" ], optional = true }
time = { version = "0.3", optional = true }
glob = "0.3"
data-url = { version = "0.2", optional = true }
serialize-to-javascript = "=0.1.1"
Expand Down Expand Up @@ -110,14 +108,12 @@ once_cell = "1"
tauri-build = { path = "../tauri-build/", version = "2.0.0-alpha.1" }

[dev-dependencies]
mockito = "0.31"
proptest = "1.0.0"
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1.0"
tauri = { path = ".", default-features = false, features = [ "wry" ] }
tokio-test = "0.4.2"
tokio = { version = "1", features = [ "full" ] }
cargo_toml = "0.11"
winnow = "=0.4.1"
Expand All @@ -130,13 +126,7 @@ objc-exception = [ "tauri-runtime-wry/objc-exception" ]
linux-protocol-headers = [ "tauri-runtime-wry/linux-headers", "webkit2gtk/v2_36" ]
isolation = [ "tauri-utils/isolation", "tauri-macros/isolation" ]
custom-protocol = [ "tauri-macros/custom-protocol" ]
updater = [
"minisign-verify",
"time",
"base64",
"dialog-ask",
"fs-extract-api"
]
updater = [ "time" ]
fs-extract-api = [ "zip" ]
native-tls = [ "reqwest/native-tls" ]
native-tls-vendored = [ "reqwest/native-tls-vendored" ]
Expand Down
4 changes: 2 additions & 2 deletions core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

103 changes: 2 additions & 101 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ use crate::runtime::menu::{Menu, MenuId, MenuIdRef};

use crate::runtime::RuntimeHandle;

#[cfg(updater)]
use crate::updater;

#[cfg(target_os = "macos")]
use crate::ActivationPolicy;

Expand Down Expand Up @@ -232,12 +229,6 @@ impl<R: Runtime> GlobalWindowEvent<R> {
}
}

#[cfg(updater)]
#[derive(Debug, Clone, Default)]
pub(crate) struct UpdaterSettings {
pub(crate) target: Option<String>,
}

/// The asset resolver is a helper to access the [`tauri_utils::assets::Assets`] interface.
#[derive(Debug, Clone)]
pub struct AssetResolver<R: Runtime> {
Expand All @@ -259,15 +250,11 @@ impl<R: Runtime> AssetResolver<R> {
pub struct AppHandle<R: Runtime> {
pub(crate) runtime_handle: R::Handle,
pub(crate) manager: WindowManager<R>,
/// The updater configuration.
#[cfg(updater)]
pub(crate) updater_settings: UpdaterSettings,
}

impl<R: Runtime> AppHandle<R> {
// currently only used on the updater
#[allow(dead_code)]
pub(crate) fn create_proxy(&self) -> R::EventLoopProxy {
/// Creates a proxy to send events through the event loop.
pub fn create_proxy(&self) -> R::EventLoopProxy {
self.runtime_handle.create_proxy()
}
}
Expand Down Expand Up @@ -306,8 +293,6 @@ impl<R: Runtime> Clone for AppHandle<R> {
Self {
runtime_handle: self.runtime_handle.clone(),
manager: self.manager.clone(),
#[cfg(updater)]
updater_settings: self.updater_settings.clone(),
}
}
}
Expand Down Expand Up @@ -511,29 +496,6 @@ impl App<crate::Wry> {
macro_rules! shared_app_impl {
($app: ty) => {
impl<R: Runtime> $app {
#[cfg(updater)]
#[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
/// Gets the updater builder to manually check if an update is available.
///
/// # Examples
///
/// ```no_run
/// tauri::Builder::default()
/// .setup(|app| {
/// let handle = app.handle();
/// tauri::async_runtime::spawn(async move {
#[cfg_attr(
feature = "updater",
doc = r#" let response = handle.updater().check().await;"#
)]
/// });
/// Ok(())
/// });
/// ```
pub fn updater(&self) -> updater::UpdateBuilder<R> {
updater::builder(self.app_handle())
}

/// Gets a handle to the first system tray.
///
/// Prefer [`Self::tray_handle_by_id`] when multiple system trays are created.
Expand Down Expand Up @@ -788,21 +750,6 @@ impl<R: Runtime> App<R> {
}
}

#[cfg(updater)]
impl<R: Runtime> App<R> {
fn run_updater(&self) {
// check if updater is active or not
if self.manager.config().tauri.updater.active {
// we only listen for `tauri://update`
// once we receive the call, we check if an update is available or not
// if there is a new update we emit `tauri://update-available` with details
// this is the user responsibilities to display dialog and ask if user want to install
// to install the update you need to invoke the Event `tauri://update-install`
updater::listener(self.handle());
}
}
}

/// Builds a Tauri application.
///
/// # Examples
Expand Down Expand Up @@ -866,10 +813,6 @@ pub struct Builder<R: Runtime> {
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_event_listeners: Vec<SystemTrayEventListener<R>>,

/// The updater configuration.
#[cfg(updater)]
updater_settings: UpdaterSettings,

/// The device event filter.
device_event_filter: DeviceEventFilter,
}
Expand Down Expand Up @@ -898,8 +841,6 @@ impl<R: Runtime> Builder<R> {
system_tray: None,
#[cfg(all(desktop, feature = "system-tray"))]
system_tray_event_listeners: Vec::new(),
#[cfg(updater)]
updater_settings: Default::default(),
device_event_filter: Default::default(),
}
}
Expand Down Expand Up @@ -1307,42 +1248,6 @@ impl<R: Runtime> Builder<R> {
self
}

/// Sets the current platform's target name for the updater.
///
/// See [`UpdateBuilder::target`](crate::updater::UpdateBuilder#method.target) for more information.
///
/// # Examples
///
/// - Use a macOS Universal binary target name:
///
/// ```
/// let mut builder = tauri::Builder::default();
/// #[cfg(target_os = "macos")]
/// {
/// builder = builder.updater_target("darwin-universal");
/// }
/// ```
///
/// - Append debug information to the target:
///
/// ```
/// let kind = if cfg!(debug_assertions) { "debug" } else { "release" };
/// tauri::Builder::default()
/// .updater_target(format!("{}-{kind}", tauri::updater::target().unwrap()));
/// ```
///
/// - Use the platform's target triple:
///
/// ```
/// tauri::Builder::default()
/// .updater_target(tauri::utils::platform::target_triple().unwrap());
/// ```
#[cfg(updater)]
pub fn updater_target<T: Into<String>>(mut self, target: T) -> Self {
self.updater_settings.target.replace(target.into());
self
}

/// Change the device event filter mode.
///
/// Since the DeviceEvent capture can lead to high CPU usage for unfocused windows, [`tao`]
Expand Down Expand Up @@ -1431,8 +1336,6 @@ impl<R: Runtime> Builder<R> {
handle: AppHandle {
runtime_handle,
manager,
#[cfg(updater)]
updater_settings: self.updater_settings,
},
};

Expand Down Expand Up @@ -1550,8 +1453,6 @@ fn setup<R: Runtime>(app: &mut App<R>) -> crate::Result<()> {
(setup)(app).map_err(|e| crate::Error::Setup(e.into()))?;
}

#[cfg(updater)]
app.run_updater();
Ok(())
}

Expand Down
Loading

0 comments on commit b072daa

Please sign in to comment.