Merge branch 'v2' into feature/fallback_targets

This commit is contained in:
Krzysztof Andrelczyk
2025-07-08 23:55:33 +02:00
202 changed files with 3272 additions and 2454 deletions
+19
View File
@@ -1,5 +1,24 @@
# Changelog
## \[2.9.0]
- [`f209b2f2`](https://github.com/tauri-apps/plugins-workspace/commit/f209b2f23cb29133c97ad5961fb46ef794dbe063) ([#2804](https://github.com/tauri-apps/plugins-workspace/pull/2804) by [@renovate](https://github.com/tauri-apps/plugins-workspace/../../renovate)) Updated tauri to 2.6
## \[2.8.1]
- [`735d209d`](https://github.com/tauri-apps/plugins-workspace/commit/735d209d5d1d92dcac70c6083bcfcd34ec7d84be) ([#2761](https://github.com/tauri-apps/plugins-workspace/pull/2761) by [@FabianLars](https://github.com/tauri-apps/plugins-workspace/../../FabianLars)) Fixed an issue preventing updates via the NSIS installer from succeeding when the app was launched with command line arguments containing spaces.
## \[2.8.0]
- [`87afa23c`](https://github.com/tauri-apps/plugins-workspace/commit/87afa23cad077c09bc1eb743800ae3396b531146) ([#2726](https://github.com/tauri-apps/plugins-workspace/pull/2726)) Add allowDowngrades parameter to check command
Added a new optional `allowDowngrades` parameter to the JavaScript check command that allows the updater to consider versions that are lower than the current version as valid updates. When enabled, the version comparator will accept any version that is different from the current version, effectively allowing downgrades.
- [`73ff15de`](https://github.com/tauri-apps/plugins-workspace/commit/73ff15de5d07d476693e40e8e5d138c16da5211e) ([#2757](https://github.com/tauri-apps/plugins-workspace/pull/2757)) Fix headers option in `Update.download` and `Update.downloadAndInstall` doesn't work with `Record<string, string> | Headers` types
## \[2.7.1]
- [`c5b0f51c`](https://github.com/tauri-apps/plugins-workspace/commit/c5b0f51cfd911cca9317b59efc718b570980129b) ([#2621](https://github.com/tauri-apps/plugins-workspace/pull/2621) by [@Legend-Master](https://github.com/tauri-apps/plugins-workspace/../../Legend-Master)) Fix `check` and `download` overrides the `accept` header
## \[2.7.0]
### bug
+3 -3
View File
@@ -1,6 +1,6 @@
[package]
name = "tauri-plugin-updater"
version = "2.7.0"
version = "2.9.0"
description = "In-app updates for Tauri applications."
edition = { workspace = true }
authors = { workspace = true }
@@ -48,8 +48,8 @@ infer = "0.19"
percent-encoding = "2.3"
[target."cfg(target_os = \"windows\")".dependencies]
zip = { version = "2", default-features = false, optional = true }
windows-sys = { version = "0.59.0", features = [
zip = { version = "4", default-features = false, optional = true }
windows-sys = { version = "0.60.0", features = [
"Win32_Foundation",
"Win32_UI_WindowsAndMessaging",
"Win32_UI_Shell",
+1 -1
View File
@@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_PLUGIN_UPDATER__=function(t){"use strict";function e(t,e,s,n){if("function"==typeof e||!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?n:"a"===s?n.call(t):n?n.value:e.get(t)}function s(t,e,s,n,i){if("function"==typeof e||!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,s),s}var n,i,r,a;"function"==typeof SuppressedError&&SuppressedError;const o="__TAURI_TO_IPC_KEY__";class d{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,n.set(this,(()=>{})),i.set(this,0),r.set(this,[]),this.id=function(t,e=!1){return window.__TAURI_INTERNALS__.transformCallback(t,e)}((({message:t,id:a})=>{if(a==e(this,i,"f"))for(e(this,n,"f").call(this,t),s(this,i,e(this,i,"f")+1);e(this,i,"f")in e(this,r,"f");){const t=e(this,r,"f")[e(this,i,"f")];e(this,n,"f").call(this,t),delete e(this,r,"f")[e(this,i,"f")],s(this,i,e(this,i,"f")+1)}else e(this,r,"f")[a]=t}))}set onmessage(t){s(this,n,t)}get onmessage(){return e(this,n,"f")}[(n=new WeakMap,i=new WeakMap,r=new WeakMap,o)](){return`__CHANNEL__:${this.id}`}toJSON(){return this[o]()}}async function c(t,e={},s){return window.__TAURI_INTERNALS__.invoke(t,e,s)}class h{get rid(){return e(this,a,"f")}constructor(t){a.set(this,void 0),s(this,a,t)}async close(){return c("plugin:resources|close",{rid:this.rid})}}a=new WeakMap;class l extends h{constructor(t){super(t.rid),this.available=!0,this.currentVersion=t.currentVersion,this.version=t.version,this.date=t.date,this.body=t.body,this.rawJson=t.rawJson}async download(t,e){const s=new d;t&&(s.onmessage=t);const n=await c("plugin:updater|download",{onEvent:s,rid:this.rid,...e});this.downloadedBytes=new h(n)}async install(){if(!this.downloadedBytes)throw new Error("Update.install called before Update.download");await c("plugin:updater|install",{updateRid:this.rid,bytesRid:this.downloadedBytes.rid}),this.downloadedBytes=void 0}async downloadAndInstall(t,e){const s=new d;t&&(s.onmessage=t),await c("plugin:updater|download_and_install",{onEvent:s,rid:this.rid,...e})}async close(){await(this.downloadedBytes?.close()),await super.close()}}return t.Update=l,t.check=async function(t){t?.headers&&(t.headers=Array.from(new Headers(t.headers).entries()));const e=await c("plugin:updater|check",{...t});return e?new l(e):null},t}({});Object.defineProperty(window.__TAURI__,"updater",{value:__TAURI_PLUGIN_UPDATER__})}
if("__TAURI__"in window){var __TAURI_PLUGIN_UPDATER__=function(t){"use strict";function e(t,e,s,n){if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?n:"a"===s?n.call(t):n?n.value:e.get(t)}function s(t,e,s,n,i){if("function"==typeof e||!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,s),s}var n,i,a,r,o;"function"==typeof SuppressedError&&SuppressedError;const d="__TAURI_TO_IPC_KEY__";class c{constructor(t){n.set(this,void 0),i.set(this,0),a.set(this,[]),r.set(this,void 0),s(this,n,t||(()=>{})),this.id=function(t,e=!1){return window.__TAURI_INTERNALS__.transformCallback(t,e)}((t=>{const o=t.index;if("end"in t)return void(o==e(this,i,"f")?this.cleanupCallback():s(this,r,o));const d=t.message;if(o==e(this,i,"f")){for(e(this,n,"f").call(this,d),s(this,i,e(this,i,"f")+1);e(this,i,"f")in e(this,a,"f");){const t=e(this,a,"f")[e(this,i,"f")];e(this,n,"f").call(this,t),delete e(this,a,"f")[e(this,i,"f")],s(this,i,e(this,i,"f")+1)}e(this,i,"f")===e(this,r,"f")&&this.cleanupCallback()}else e(this,a,"f")[o]=d}))}cleanupCallback(){window.__TAURI_INTERNALS__.unregisterCallback(this.id)}set onmessage(t){s(this,n,t)}get onmessage(){return e(this,n,"f")}[(n=new WeakMap,i=new WeakMap,a=new WeakMap,r=new WeakMap,d)](){return`__CHANNEL__:${this.id}`}toJSON(){return this[d]()}}async function l(t,e={},s){return window.__TAURI_INTERNALS__.invoke(t,e,s)}class h{get rid(){return e(this,o,"f")}constructor(t){o.set(this,void 0),s(this,o,t)}async close(){return l("plugin:resources|close",{rid:this.rid})}}o=new WeakMap;class u extends h{constructor(t){super(t.rid),this.available=!0,this.currentVersion=t.currentVersion,this.version=t.version,this.date=t.date,this.body=t.body,this.rawJson=t.rawJson}async download(t,e){_(e);const s=new c;t&&(s.onmessage=t);const n=await l("plugin:updater|download",{onEvent:s,rid:this.rid,...e});this.downloadedBytes=new h(n)}async install(){if(!this.downloadedBytes)throw new Error("Update.install called before Update.download");await l("plugin:updater|install",{updateRid:this.rid,bytesRid:this.downloadedBytes.rid}),this.downloadedBytes=void 0}async downloadAndInstall(t,e){_(e);const s=new c;t&&(s.onmessage=t),await l("plugin:updater|download_and_install",{onEvent:s,rid:this.rid,...e})}async close(){await(this.downloadedBytes?.close()),await super.close()}}function _(t){t?.headers&&(t.headers=Array.from(new Headers(t.headers).entries()))}return t.Update=u,t.check=async function(t){_(t);const e=await l("plugin:updater|check",{...t});return e?new u(e):null},t}({});Object.defineProperty(window.__TAURI__,"updater",{value:__TAURI_PLUGIN_UPDATER__})}
+16 -3
View File
@@ -22,6 +22,10 @@ interface CheckOptions {
* Target identifier for the running application. This is sent to the backend.
*/
target?: string
/**
* Allow downgrades to previous versions by not checking if the current version is greater than the available version.
*/
allowDowngrades?: boolean
}
/** Options used when downloading an update */
@@ -77,6 +81,7 @@ class Update extends Resource {
onEvent?: (progress: DownloadEvent) => void,
options?: DownloadOptions
): Promise<void> {
convertToRustHeaders(options)
const channel = new Channel<DownloadEvent>()
if (onEvent) {
channel.onmessage = onEvent
@@ -109,6 +114,7 @@ class Update extends Resource {
onEvent?: (progress: DownloadEvent) => void,
options?: DownloadOptions
): Promise<void> {
convertToRustHeaders(options)
const channel = new Channel<DownloadEvent>()
if (onEvent) {
channel.onmessage = onEvent
@@ -128,9 +134,7 @@ class Update extends Resource {
/** Check for updates, resolves to `null` if no updates are available */
async function check(options?: CheckOptions): Promise<Update | null> {
if (options?.headers) {
options.headers = Array.from(new Headers(options.headers).entries())
}
convertToRustHeaders(options)
const metadata = await invoke<UpdateMetadata | null>('plugin:updater|check', {
...options
@@ -138,5 +142,14 @@ async function check(options?: CheckOptions): Promise<Update | null> {
return metadata ? new Update(metadata) : null
}
/**
* Converts the headers in options to be an {@linkcode Array<[string, string]>} which is what the Rust side expects
*/
function convertToRustHeaders(options?: { headers?: HeadersInit }) {
if (options?.headers) {
options.headers = Array.from(new Headers(options.headers).entries())
}
}
export type { CheckOptions, DownloadOptions, DownloadEvent }
export { check, Update }
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@tauri-apps/plugin-updater",
"version": "2.7.0",
"version": "2.9.0",
"license": "MIT OR Apache-2.0",
"authors": [
"Tauri Programme within The Commons Conservancy"
@@ -24,6 +24,6 @@
"LICENSE"
],
"dependencies": {
"@tauri-apps/api": "^2.0.0"
"@tauri-apps/api": "^2.6.0"
}
}
@@ -8,8 +8,6 @@ updater functions are exposed to the frontend.
The full workflow from checking for updates to installing them
is enabled.
#### This default permission set includes the following:
- `allow-check`
+4
View File
@@ -46,6 +46,7 @@ pub(crate) async fn check<R: Runtime>(
timeout: Option<u64>,
proxy: Option<String>,
target: Option<String>,
allow_downgrades: Option<bool>,
) -> Result<Option<Metadata>> {
let mut builder = webview.updater_builder();
if let Some(headers) = headers {
@@ -63,6 +64,9 @@ pub(crate) async fn check<R: Runtime>(
if let Some(target) = target {
builder = builder.target(target);
}
if allow_downgrades.unwrap_or(false) {
builder = builder.version_comparator(|current, update| update.version != current);
}
let updater = builder.build()?;
let update = updater.check().await?;
+105 -17
View File
@@ -17,7 +17,7 @@ use std::ffi::OsStr;
use base64::Engine;
use futures_util::StreamExt;
use http::HeaderName;
use http::{header::ACCEPT, HeaderName};
use minisign_verify::{PublicKey, Signature};
use percent_encoding::{AsciiSet, CONTROLS};
use reqwest::{
@@ -401,7 +401,10 @@ impl Updater {
pub async fn check(&self) -> Result<Option<Update>> {
// we want JSON only
let mut headers = self.headers.clone();
headers.insert("Accept", HeaderValue::from_str("application/json").unwrap());
if !headers.contains_key(ACCEPT) {
headers.insert(ACCEPT, HeaderValue::from_static("application/json"));
}
// Set SSL certs for linux if they aren't available.
#[cfg(target_os = "linux")]
{
@@ -613,10 +616,9 @@ impl Update {
) -> Result<Vec<u8>> {
// set our headers
let mut headers = self.headers.clone();
headers.insert(
"Accept",
HeaderValue::from_str("application/octet-stream").unwrap(),
);
if !headers.contains_key(ACCEPT) {
headers.insert(ACCEPT, HeaderValue::from_static("application/octet-stream"));
}
let mut request = ClientBuilder::new().user_agent(UPDATER_USER_AGENT);
if let Some(timeout) = self.timeout {
@@ -746,17 +748,25 @@ impl Update {
let install_mode = self.config.install_mode();
let current_args = &self.current_exe_args()[1..];
let msi_args;
let nsis_args;
let installer_args: Vec<&OsStr> = match &updater_type {
WindowsUpdaterType::Nsis { .. } => install_mode
.nsis_args()
.iter()
.map(OsStr::new)
.chain(once(OsStr::new("/UPDATE")))
.chain(once(OsStr::new("/ARGS")))
.chain(current_args.to_vec())
.chain(self.installer_args())
.collect(),
WindowsUpdaterType::Nsis { .. } => {
nsis_args = current_args
.iter()
.map(escape_nsis_current_exe_arg)
.collect::<Vec<_>>();
install_mode
.nsis_args()
.iter()
.map(OsStr::new)
.chain(once(OsStr::new("/UPDATE")))
.chain(once(OsStr::new("/ARGS")))
.chain(nsis_args.iter().map(OsStr::new))
.chain(self.installer_args())
.collect()
}
WindowsUpdaterType::Msi { path, .. } => {
let escaped_args = current_args
.iter()
@@ -1419,6 +1429,41 @@ impl PathExt for PathBuf {
}
}
// adapted from https://github.com/rust-lang/rust/blob/1c047506f94cd2d05228eb992b0a6bbed1942349/library/std/src/sys/args/windows.rs#L174
#[cfg(windows)]
fn escape_nsis_current_exe_arg(arg: &&OsStr) -> String {
let arg = arg.to_string_lossy();
let mut cmd: Vec<char> = Vec::new();
// compared to std we additionally escape `/` so that nsis won't interpret them as a beginning of an nsis argument.
let quote = arg.chars().any(|c| c == ' ' || c == '\t' || c == '/') || arg.is_empty();
let escape = true;
if quote {
cmd.push('"');
}
let mut backslashes: usize = 0;
for x in arg.chars() {
if escape {
if x == '\\' {
backslashes += 1;
} else {
if x == '"' {
// Add n+1 backslashes to total 2n+1 before internal '"'.
cmd.extend((0..=backslashes).map(|_| '\\'));
}
backslashes = 0;
}
}
cmd.push(x);
}
if quote {
// Add n backslashes to total 2n before ending '"'.
cmd.extend((0..backslashes).map(|_| '\\'));
cmd.push('"');
}
cmd.into_iter().collect()
}
#[cfg(windows)]
fn escape_msi_property_arg(arg: impl AsRef<OsStr>) -> String {
let mut arg = arg.as_ref().to_string_lossy().to_string();
@@ -1431,7 +1476,7 @@ fn escape_msi_property_arg(arg: impl AsRef<OsStr>) -> String {
}
if arg.contains('"') {
arg = arg.replace('"', r#""""""#)
arg = arg.replace('"', r#""""""#);
}
if arg.starts_with('-') {
@@ -1462,7 +1507,7 @@ mod tests {
#[test]
#[cfg(windows)]
fn it_escapes_correctly() {
fn it_escapes_correctly_for_msi() {
use crate::updater::escape_msi_property_arg;
// Explanation for quotes:
@@ -1507,4 +1552,47 @@ mod tests {
assert_eq!(escape_msi_property_arg(orig), escaped);
}
}
#[test]
#[cfg(windows)]
fn it_escapes_correctly_for_nsis() {
use crate::updater::escape_nsis_current_exe_arg;
use std::ffi::OsStr;
let cases = [
"something",
"--flag",
"--empty=",
"--arg=value",
"some space", // This simulates `./my-app "some string"`.
"--arg value", // -> This simulates `./my-app "--arg value"`. Same as above but it triggers the startsWith(`-`) logic.
"--arg=unwrapped space", // `./my-app --arg="unwrapped space"`
"--arg=\"wrapped\"", // `./my-app --args=""wrapped""`
"--arg=\"wrapped space\"", // `./my-app --args=""wrapped space""`
"--arg=midword\"wrapped space\"", // `./my-app --args=midword""wrapped""`
"", // `./my-app '""'`
];
// Note: These may not be the results we actually want (monitor this!).
// We only make sure the implementation doesn't unintentionally change.
let cases_escaped = [
"something",
"--flag",
"--empty=",
"--arg=value",
"\"some space\"",
"\"--arg value\"",
"\"--arg=unwrapped space\"",
"--arg=\\\"wrapped\\\"",
"\"--arg=\\\"wrapped space\\\"\"",
"\"--arg=midword\\\"wrapped space\\\"\"",
"\"\"",
];
// Just to be sure we didn't mess that up
assert_eq!(cases.len(), cases_escaped.len());
for (orig, escaped) in cases.iter().zip(cases_escaped) {
assert_eq!(escape_nsis_current_exe_arg(&OsStr::new(orig)), escaped);
}
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ edition = { workspace = true }
tauri-build = { workspace = true }
[dependencies]
tauri = { workspace = true, features = ["wry", "compression"] }
tauri = { workspace = true, features = ["wry", "common-controls-v6", "x11"] }
serde = { workspace = true }
serde_json = { workspace = true }
tauri-plugin-updater = { path = "../.." }
@@ -7,7 +7,7 @@ edition = { workspace = true }
tauri-build = { workspace = true }
[dependencies]
tauri = { workspace = true, features = ["wry", "compression"] }
tauri = { workspace = true, features = ["wry", "common-controls-v6", "x11"] }
serde = { workspace = true }
serde_json = { workspace = true }
tauri-plugin-updater = { path = "../.." }
@@ -7,7 +7,7 @@ edition = { workspace = true }
tauri-build = { workspace = true }
[dependencies]
tauri = { workspace = true, features = ["wry", "compression"] }
tauri = { workspace = true, features = ["wry", "common-controls-v6", "x11"] }
serde = { workspace = true }
serde_json = { workspace = true }
tauri-plugin-updater = { path = "../../.." }