Skip to content

Commit

Permalink
refactor(bundler): allow downgrades, add option to disallow on Windows (
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Mar 28, 2022
1 parent 94d78ef commit 8b807e0
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .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.
27 changes: 26 additions & 1 deletion core/tauri-utils/src/config.rs
Expand Up @@ -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 {
Expand All @@ -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)]
Expand Down
7 changes: 7 additions & 0 deletions tooling/bundler/src/bundle/settings.rs
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tooling/bundler/src/bundle/windows/msi/wix.rs
Expand Up @@ -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()));
Expand Down
7 changes: 5 additions & 2 deletions tooling/bundler/src/bundle/windows/templates/main.wxs
Expand Up @@ -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" />

Expand Down
8 changes: 8 additions & 0 deletions tooling/cli/schema.json
Expand Up @@ -144,6 +144,7 @@
"useBootstrapper": false
},
"windows": {
"allowDowngrades": true,
"certificateThumbprint": null,
"digestAlgorithm": null,
"timestampUrl": null,
Expand Down Expand Up @@ -561,6 +562,7 @@
"windows": {
"description": "Configuration for the Windows bundle.",
"default": {
"allowDowngrades": true,
"certificateThumbprint": null,
"digestAlgorithm": null,
"timestampUrl": null,
Expand Down Expand Up @@ -1639,6 +1641,7 @@
"useBootstrapper": false
},
"windows": {
"allowDowngrades": true,
"certificateThumbprint": null,
"digestAlgorithm": null,
"timestampUrl": null,
Expand Down Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions tooling/cli/src/interface/rust.rs
Expand Up @@ -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,
Expand Down

0 comments on commit 8b807e0

Please sign in to comment.