fix(updater): fallback to passive mode & fix `installerArgs` deserialzation (#1051)

pull/1068/head
Tony 1 year ago committed by GitHub
parent 753c7be0a6
commit 4e37316af0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"updater": patch
---
Fix deserialization of `windows > installerArgs` config field.

@ -0,0 +1,5 @@
---
"updater": patch
---
On Windows, fallback to `passive` install mode when not defined in config.

@ -64,13 +64,29 @@ impl Default for WindowsUpdateInstallMode {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct WindowsConfig { pub struct WindowsConfig {
/// Additional arguments given to the NSIS or WiX installer. /// Additional arguments given to the NSIS or WiX installer.
#[serde(default, alias = "installer-args")] #[serde(
default,
alias = "installer-args",
deserialize_with = "deserialize_os_string"
)]
pub installer_args: Vec<OsString>, pub installer_args: Vec<OsString>,
/// Updating mode, see [`WindowsUpdateInstallMode`] for more info. /// Updating mode, defaults to `passive` mode.
///
/// See [`WindowsUpdateInstallMode`] for more info.
#[serde(default, alias = "install-mode")] #[serde(default, alias = "install-mode")]
pub install_mode: WindowsUpdateInstallMode, pub install_mode: WindowsUpdateInstallMode,
} }
fn deserialize_os_string<'de, D>(deserializer: D) -> Result<Vec<OsString>, D::Error>
where
D: Deserializer<'de>,
{
Ok(Vec::<String>::deserialize(deserializer)?
.into_iter()
.map(OsString::from)
.collect::<Vec<_>>())
}
/// Updater configuration. /// Updater configuration.
#[derive(Debug, Clone, Deserialize, Default)] #[derive(Debug, Clone, Deserialize, Default)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]

@ -13,7 +13,7 @@
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png" html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
)] )]
use std::ffi::{OsStr, OsString}; use std::ffi::OsString;
use tauri::{ use tauri::{
plugin::{Builder as PluginBuilder, TauriPlugin}, plugin::{Builder as PluginBuilder, TauriPlugin},
@ -136,21 +136,18 @@ impl Builder {
pub fn installer_args<I, S>(mut self, args: I) -> Self pub fn installer_args<I, S>(mut self, args: I) -> Self
where where
I: IntoIterator<Item = S>, I: IntoIterator<Item = S>,
S: AsRef<OsStr>, S: Into<OsString>,
{ {
let args = args let args = args.into_iter().map(|a| a.into()).collect::<Vec<_>>();
.into_iter()
.map(|a| a.as_ref().to_os_string())
.collect::<Vec<_>>();
self.installer_args.extend_from_slice(&args); self.installer_args.extend_from_slice(&args);
self self
} }
pub fn installer_arg<S>(mut self, arg: S) -> Self pub fn installer_arg<S>(mut self, arg: S) -> Self
where where
S: AsRef<OsStr>, S: Into<OsString>,
{ {
self.installer_args.push(arg.as_ref().to_os_string()); self.installer_args.push(arg.into());
self self
} }

@ -176,21 +176,18 @@ impl UpdaterBuilder {
pub fn installer_arg<S>(mut self, arg: S) -> Self pub fn installer_arg<S>(mut self, arg: S) -> Self
where where
S: AsRef<OsStr>, S: Into<OsString>,
{ {
self.installer_args.push(arg.as_ref().to_os_string()); self.installer_args.push(arg.into());
self self
} }
pub fn installer_args<I, S>(mut self, args: I) -> Self pub fn installer_args<I, S>(mut self, args: I) -> Self
where where
I: IntoIterator<Item = S>, I: IntoIterator<Item = S>,
S: AsRef<OsStr>, S: Into<OsString>,
{ {
let args = args let args = args.into_iter().map(|a| a.into()).collect::<Vec<_>>();
.into_iter()
.map(|a| a.as_ref().to_os_string())
.collect::<Vec<_>>();
self.installer_args.extend_from_slice(&args); self.installer_args.extend_from_slice(&args);
self self
} }
@ -543,6 +540,13 @@ impl Update {
|p| format!("{p}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"), |p| format!("{p}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
); );
let install_mode = self
.config
.windows
.as_ref()
.map(|w| w.install_mode.clone())
.unwrap_or_default();
for path in paths { for path in paths {
let found_path = path?.path(); let found_path = path?.path();
// we support 2 type of files exe & msi for now // we support 2 type of files exe & msi for now
@ -555,17 +559,11 @@ impl Update {
installer_path.push("\""); installer_path.push("\"");
let installer_args = [ let installer_args = [
self.config install_mode
.windows .nsis_args()
.as_ref() .iter()
.map(|w| { .map(OsStr::new)
w.install_mode .collect::<Vec<_>>(),
.nsis_args()
.iter()
.map(|a| OsStr::new(a))
.collect::<Vec<_>>()
})
.unwrap_or_default(),
self.installer_args self.installer_args
.iter() .iter()
.map(|a| a.as_os_str()) .map(|a| a.as_os_str())
@ -600,17 +598,11 @@ impl Update {
msi_path.push("\"\"\""); msi_path.push("\"\"\"");
let installer_args = [ let installer_args = [
self.config install_mode
.windows .msiexec_args()
.as_ref() .iter()
.map(|w| { .map(OsStr::new)
w.install_mode .collect::<Vec<_>>(),
.msiexec_args()
.iter()
.map(|a| OsStr::new(a))
.collect::<Vec<_>>()
})
.unwrap_or_default(),
self.installer_args self.installer_args
.iter() .iter()
.map(|a| a.as_os_str()) .map(|a| a.as_os_str())

@ -5,7 +5,8 @@
"endpoints": ["http://localhost:3007"], "endpoints": ["http://localhost:3007"],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEUwNDRGMjkwRjg2MDhCRDAKUldUUWkyRDRrUEpFNEQ4SmdwcU5PaXl6R2ZRUUNvUnhIaVkwVUltV0NMaEx6VTkrWVhpT0ZqeEEK", "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEUwNDRGMjkwRjg2MDhCRDAKUldUUWkyRDRrUEpFNEQ4SmdwcU5PaXl6R2ZRUUNvUnhIaVkwVUltV0NMaEx6VTkrWVhpT0ZqeEEK",
"windows": { "windows": {
"installMode": "quiet" "installMode": "quiet",
"installerArgs": ["/NS"]
} }
} }
}, },

Loading…
Cancel
Save