From 8b807e09d6868f6bff8357f16d27b15bd1fccadd Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sun, 27 Mar 2022 17:34:19 -0700 Subject: [PATCH] refactor(bundler): allow downgrades, add option to disallow on Windows (#3777) --- .changes/windows-disallow-downgrades.md | 6 +++++ core/tauri-utils/src/config.rs | 27 ++++++++++++++++++- tooling/bundler/src/bundle/settings.rs | 7 +++++ tooling/bundler/src/bundle/windows/msi/wix.rs | 4 +++ .../src/bundle/windows/templates/main.wxs | 7 +++-- tooling/cli/schema.json | 8 ++++++ tooling/cli/src/interface/rust.rs | 1 + 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 .changes/windows-disallow-downgrades.md diff --git a/.changes/windows-disallow-downgrades.md b/.changes/windows-disallow-downgrades.md new file mode 100644 index 00000000000..8e12ef157f9 --- /dev/null +++ b/.changes/windows-disallow-downgrades.md @@ -0,0 +1,6 @@ +--- +"tauri": patch +--- + +Added a configuration flag for disallowing install downgrades on Windows. +**Breaking change:** The default behavior on Windows is now to allow downgrades. diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index f5d42617281..f4db9714a06 100644 --- a/core/tauri-utils/src/config.rs +++ b/core/tauri-utils/src/config.rs @@ -245,7 +245,7 @@ pub struct WixConfig { } /// Windows bundler configuration. -#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[cfg_attr(feature = "schema", derive(JsonSchema))] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct WindowsConfig { @@ -264,10 +264,35 @@ pub struct WindowsConfig { /// The fixed version can be downloaded [on the official website](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section). /// The `.cab` file must be extracted to a folder and this folder path must be defined on this field. pub webview_fixed_runtime_path: Option, + /// Validates a second app installation, blocking the user from installing an older version if set to `false`. + /// + /// For instance, if `1.2.1` is installed, the user won't be able to install app version `1.2.0` or `1.1.5`. + /// + /// The default value of this flag is `true`. + #[serde(default = "default_allow_downgrades")] + pub allow_downgrades: bool, /// Configuration for the MSI generated with WiX. pub wix: Option, } +impl Default for WindowsConfig { + fn default() -> Self { + Self { + digest_algorithm: None, + certificate_thumbprint: None, + timestamp_url: None, + tsp: None, + webview_fixed_runtime_path: None, + allow_downgrades: default_allow_downgrades(), + wix: None, + } + } +} + +fn default_allow_downgrades() -> bool { + true +} + /// Configuration for tauri-bundler. #[skip_serializing_none] #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)] diff --git a/tooling/bundler/src/bundle/settings.rs b/tooling/bundler/src/bundle/settings.rs index 381a21b5b17..21618e84715 100644 --- a/tooling/bundler/src/bundle/settings.rs +++ b/tooling/bundler/src/bundle/settings.rs @@ -250,6 +250,12 @@ pub struct WindowsSettings { pub icon_path: PathBuf, /// Path to the webview fixed runtime to use. pub webview_fixed_runtime_path: Option, + /// Validates a second app installation, blocking the user from installing an older version if set to `false`. + /// + /// For instance, if `1.2.1` is installed, the user won't be able to install app version `1.2.0` or `1.1.5`. + /// + /// /// The default value of this flag is `true`. + pub allow_downgrades: bool, } impl Default for WindowsSettings { @@ -262,6 +268,7 @@ impl Default for WindowsSettings { wix: None, icon_path: PathBuf::from("icons/icon.ico"), webview_fixed_runtime_path: None, + allow_downgrades: true, } } } diff --git a/tooling/bundler/src/bundle/windows/msi/wix.rs b/tooling/bundler/src/bundle/windows/msi/wix.rs index d22997e488a..5c73aaffabe 100644 --- a/tooling/bundler/src/bundle/windows/msi/wix.rs +++ b/tooling/bundler/src/bundle/windows/msi/wix.rs @@ -467,6 +467,10 @@ pub fn build_wix_app_installer( .to_string(); data.insert("upgrade_code", to_json(&upgrade_code.as_str())); + data.insert( + "allow_downgrades", + to_json(settings.windows().allow_downgrades), + ); let path_guid = generate_package_guid(settings).to_string(); data.insert("path_component_guid", to_json(&path_guid.as_str())); diff --git a/tooling/bundler/src/bundle/windows/templates/main.wxs b/tooling/bundler/src/bundle/windows/templates/main.wxs index c420ec0c8c8..f6eea5204a5 100644 --- a/tooling/bundler/src/bundle/windows/templates/main.wxs +++ b/tooling/bundler/src/bundle/windows/templates/main.wxs @@ -25,8 +25,11 @@ InstallScope="perMachine" SummaryCodepage="!(loc.TauriCodepage)"/> - + {{#if allow_downgrades}} + + {{else}} + + {{/if}} diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index a76a07a06e5..77a21db15f2 100644 --- a/tooling/cli/schema.json +++ b/tooling/cli/schema.json @@ -144,6 +144,7 @@ "useBootstrapper": false }, "windows": { + "allowDowngrades": true, "certificateThumbprint": null, "digestAlgorithm": null, "timestampUrl": null, @@ -561,6 +562,7 @@ "windows": { "description": "Configuration for the Windows bundle.", "default": { + "allowDowngrades": true, "certificateThumbprint": null, "digestAlgorithm": null, "timestampUrl": null, @@ -1639,6 +1641,7 @@ "useBootstrapper": false }, "windows": { + "allowDowngrades": true, "certificateThumbprint": null, "digestAlgorithm": null, "timestampUrl": null, @@ -2054,6 +2057,11 @@ "description": "Windows bundler configuration.", "type": "object", "properties": { + "allowDowngrades": { + "description": "Validates a second app installation, blocking the user from installing an older version if set to `false`.\n\nFor instance, if `1.2.1` is installed, the user won't be able to install app version `1.2.0` or `1.1.5`.\n\nThe default value of this flag is `true`.", + "default": true, + "type": "boolean" + }, "certificateThumbprint": { "description": "Specifies the SHA1 hash of the signing certificate.", "type": [ diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs index 111cb1b9197..d9ad1545767 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/tooling/cli/src/interface/rust.rs @@ -489,6 +489,7 @@ fn tauri_config_to_bundle_settings( }), icon_path: windows_icon_path, webview_fixed_runtime_path: config.windows.webview_fixed_runtime_path, + allow_downgrades: config.windows.allow_downgrades, }, updater: Some(UpdaterSettings { active: updater_config.active,