refactor(bundler): allow downgrades, add option to disallow on Windows (#3777)

This commit is contained in:
Lucas Fernandes Nogueira 2022-03-27 17:34:19 -07:00 committed by GitHub
parent 94d78efbe5
commit 8b807e09d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 3 deletions

View File

@ -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.

View File

@ -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<PathBuf>,
/// 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<WixConfig>,
}
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)]

View File

@ -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<PathBuf>,
/// 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,
}
}
}

View File

@ -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()));

View File

@ -25,8 +25,11 @@
InstallScope="perMachine"
SummaryCodepage="!(loc.TauriCodepage)"/>
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeErrorMessage)"
AllowSameVersionUpgrades="yes" />
{{#if allow_downgrades}}
<MajorUpgrade AllowDowngrades="yes" />
{{else}}
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeErrorMessage)" AllowSameVersionUpgrades="yes" />
{{/if}}
<Media Id="1" Cabinet="app.cab" EmbedCab="yes" />

View File

@ -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": [

View File

@ -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,