Skip to content

Commit 8b807e0

Browse files
authored
refactor(bundler): allow downgrades, add option to disallow on Windows (#3777)
1 parent 94d78ef commit 8b807e0

File tree

7 files changed

+57
-3
lines changed

7 files changed

+57
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Added a configuration flag for disallowing install downgrades on Windows.
6+
**Breaking change:** The default behavior on Windows is now to allow downgrades.

core/tauri-utils/src/config.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub struct WixConfig {
245245
}
246246

247247
/// Windows bundler configuration.
248-
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
248+
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
249249
#[cfg_attr(feature = "schema", derive(JsonSchema))]
250250
#[serde(rename_all = "camelCase", deny_unknown_fields)]
251251
pub struct WindowsConfig {
@@ -264,10 +264,35 @@ pub struct WindowsConfig {
264264
/// The fixed version can be downloaded [on the official website](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section).
265265
/// The `.cab` file must be extracted to a folder and this folder path must be defined on this field.
266266
pub webview_fixed_runtime_path: Option<PathBuf>,
267+
/// Validates a second app installation, blocking the user from installing an older version if set to `false`.
268+
///
269+
/// 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`.
270+
///
271+
/// The default value of this flag is `true`.
272+
#[serde(default = "default_allow_downgrades")]
273+
pub allow_downgrades: bool,
267274
/// Configuration for the MSI generated with WiX.
268275
pub wix: Option<WixConfig>,
269276
}
270277

278+
impl Default for WindowsConfig {
279+
fn default() -> Self {
280+
Self {
281+
digest_algorithm: None,
282+
certificate_thumbprint: None,
283+
timestamp_url: None,
284+
tsp: None,
285+
webview_fixed_runtime_path: None,
286+
allow_downgrades: default_allow_downgrades(),
287+
wix: None,
288+
}
289+
}
290+
}
291+
292+
fn default_allow_downgrades() -> bool {
293+
true
294+
}
295+
271296
/// Configuration for tauri-bundler.
272297
#[skip_serializing_none]
273298
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]

tooling/bundler/src/bundle/settings.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ pub struct WindowsSettings {
250250
pub icon_path: PathBuf,
251251
/// Path to the webview fixed runtime to use.
252252
pub webview_fixed_runtime_path: Option<PathBuf>,
253+
/// Validates a second app installation, blocking the user from installing an older version if set to `false`.
254+
///
255+
/// 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`.
256+
///
257+
/// /// The default value of this flag is `true`.
258+
pub allow_downgrades: bool,
253259
}
254260

255261
impl Default for WindowsSettings {
@@ -262,6 +268,7 @@ impl Default for WindowsSettings {
262268
wix: None,
263269
icon_path: PathBuf::from("icons/icon.ico"),
264270
webview_fixed_runtime_path: None,
271+
allow_downgrades: true,
265272
}
266273
}
267274
}

tooling/bundler/src/bundle/windows/msi/wix.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@ pub fn build_wix_app_installer(
467467
.to_string();
468468

469469
data.insert("upgrade_code", to_json(&upgrade_code.as_str()));
470+
data.insert(
471+
"allow_downgrades",
472+
to_json(settings.windows().allow_downgrades),
473+
);
470474

471475
let path_guid = generate_package_guid(settings).to_string();
472476
data.insert("path_component_guid", to_json(&path_guid.as_str()));

tooling/bundler/src/bundle/windows/templates/main.wxs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
InstallScope="perMachine"
2626
SummaryCodepage="!(loc.TauriCodepage)"/>
2727

28-
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeErrorMessage)"
29-
AllowSameVersionUpgrades="yes" />
28+
{{#if allow_downgrades}}
29+
<MajorUpgrade AllowDowngrades="yes" />
30+
{{else}}
31+
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeErrorMessage)" AllowSameVersionUpgrades="yes" />
32+
{{/if}}
3033

3134
<Media Id="1" Cabinet="app.cab" EmbedCab="yes" />
3235

tooling/cli/schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
"useBootstrapper": false
145145
},
146146
"windows": {
147+
"allowDowngrades": true,
147148
"certificateThumbprint": null,
148149
"digestAlgorithm": null,
149150
"timestampUrl": null,
@@ -561,6 +562,7 @@
561562
"windows": {
562563
"description": "Configuration for the Windows bundle.",
563564
"default": {
565+
"allowDowngrades": true,
564566
"certificateThumbprint": null,
565567
"digestAlgorithm": null,
566568
"timestampUrl": null,
@@ -1639,6 +1641,7 @@
16391641
"useBootstrapper": false
16401642
},
16411643
"windows": {
1644+
"allowDowngrades": true,
16421645
"certificateThumbprint": null,
16431646
"digestAlgorithm": null,
16441647
"timestampUrl": null,
@@ -2054,6 +2057,11 @@
20542057
"description": "Windows bundler configuration.",
20552058
"type": "object",
20562059
"properties": {
2060+
"allowDowngrades": {
2061+
"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`.",
2062+
"default": true,
2063+
"type": "boolean"
2064+
},
20572065
"certificateThumbprint": {
20582066
"description": "Specifies the SHA1 hash of the signing certificate.",
20592067
"type": [

tooling/cli/src/interface/rust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ fn tauri_config_to_bundle_settings(
489489
}),
490490
icon_path: windows_icon_path,
491491
webview_fixed_runtime_path: config.windows.webview_fixed_runtime_path,
492+
allow_downgrades: config.windows.allow_downgrades,
492493
},
493494
updater: Some(UpdaterSettings {
494495
active: updater_config.active,

0 commit comments

Comments
 (0)