Skip to content

Commit b769c7f

Browse files
authored
feat(bundler): windows installer license, closes #2009 (#2027)
1 parent feb7c6e commit b769c7f

File tree

9 files changed

+58
-3
lines changed

9 files changed

+58
-3
lines changed

.changes/msi-license.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": patch
3+
"tauri-bundler": patch
4+
---
5+
6+
Allow setting a path to a license file for the Windows Installer (`tauri.conf.json > bundle > windows > wix > license`).

docs/api/config.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ It's composed of the following properties:
168168
{ property: "featureGroupRefs", optional: true, type: "string[]", description: `The FeatureGroup element ids you want to reference from the fragments.` },
169169
{ property: "featureRefs", optional: true, type: "string[]", description: `The Feature element ids you want to reference from the fragments.` },
170170
{ property: "mergeRefs", optional: true, type: "string[]", description: `The Merge element ids you want to reference from the fragments.` },
171-
{ property: "skipWebviewInstall", optional: true, type: "boolean", description: `Disables the Webview2 runtime installation after app install.` }]} />
171+
{ property: "skipWebviewInstall", optional: true, type: "boolean", description: `Disables the Webview2 runtime installation after app install.` },
172+
{ property: "license", optional: true, type: "string", description: `The path to the license file to render on the installer. Must be an RTF file, so if a different extension is provided, we convert it to the RTF format.` }]} />
172173
}
173174
]} />
174175
},

tooling/bundler/src/bundle/settings.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ pub struct WixSettings {
194194
pub merge_refs: Vec<String>,
195195
/// Disables the Webview2 runtime installation after app install.
196196
pub skip_webview_install: bool,
197+
/// The path to the LICENSE file.
198+
pub license: Option<String>,
197199
}
198200

199201
/// The Windows bundle settings.

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,31 @@ pub fn build_wix_app_installer(
414414
let language_map: HashMap<String, LanguageMetadata> =
415415
serde_json::from_str(include_str!("./languages.json")).unwrap();
416416

417+
if let Some(wix) = &settings.windows().wix {
418+
if let Some(license) = &wix.license {
419+
if license.ends_with(".rtf") {
420+
data.insert("license", to_json(license));
421+
} else {
422+
let license_path = PathBuf::from(license);
423+
let license_contents = std::fs::read_to_string(&license_path)?;
424+
let license_rtf = format!(
425+
r#"{{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{{\fonttbl{{\f0\fnil\fcharset0 Calibri;}}}}
426+
{{\*\generator Riched20 10.0.18362}}\viewkind4\uc1
427+
\pard\sa200\sl276\slmult1\f0\fs22\lang9 {}\par
428+
}}
429+
"#,
430+
license_contents.replace("\n", "\\par ")
431+
);
432+
let rtf_output_path = settings
433+
.project_out_directory()
434+
.join("wix")
435+
.join("LICENSE.rtf");
436+
std::fs::write(&rtf_output_path, license_rtf)?;
437+
data.insert("license", to_json(rtf_output_path));
438+
}
439+
}
440+
}
441+
417442
let (language, language_metadata) = if let Some(wix) = &settings.windows().wix {
418443
let metadata = language_map.get(&wix.language).unwrap_or_else(|| {
419444
panic!(

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
<Media Id="1" Cabinet="app.cab" EmbedCab="yes" />
3434

3535
<WixVariable Id="WixUIBannerBmp" Value="{{{icon_path}}}" />
36+
{{#if license}}
37+
<WixVariable Id="WixUILicenseRtf" Value="{{{license}}}" />
38+
{{/if}}
3639

3740
<Icon Id="ProductIcon" SourceFile="{{{icon_path}}}"/>
3841
<Property Id="ARPPRODUCTICON" Value="ProductIcon" />
@@ -42,6 +45,7 @@
4245
<UI>
4346
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
4447

48+
{{#unless license}}
4549
<!-- Skip license dialog -->
4650
<Publish Dialog="WelcomeDlg"
4751
Control="Next"
@@ -53,6 +57,7 @@
5357
Event="NewDialog"
5458
Value="WelcomeDlg"
5559
Order="2">1</Publish>
60+
{{/unless}}
5661
</UI>
5762

5863
<UIRef Id="WixUI_InstallDir" />

tooling/cli.rs/config_definition.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ pub struct WixConfig {
7878
pub merge_refs: Vec<String>,
7979
#[serde(default)]
8080
pub skip_webview_install: bool,
81+
/// Path to the license file.
82+
pub license: Option<String>,
8183
}
8284

8385
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]

tooling/cli.rs/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,13 @@
12941294
"default": "en-US",
12951295
"type": "string"
12961296
},
1297+
"license": {
1298+
"description": "Path to the license file.",
1299+
"type": [
1300+
"string",
1301+
"null"
1302+
]
1303+
},
12971304
"mergeRefs": {
12981305
"default": [],
12991306
"type": "array",

tooling/cli.rs/src/helpers/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl From<WixConfig> for tauri_bundler::WixSettings {
2525
feature_refs: config.feature_refs,
2626
merge_refs: config.merge_refs,
2727
skip_webview_install: config.skip_webview_install,
28+
license: config.license,
2829
}
2930
}
3031
}

tooling/cli.rs/src/interface/rust.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use serde::Deserialize;
1616
use crate::helpers::{app_paths::tauri_dir, config::Config, manifest::Manifest};
1717
use tauri_bundler::{
1818
AppCategory, BundleBinary, BundleSettings, DebianSettings, MacOsSettings, PackageSettings,
19-
UpdaterSettings, WindowsSettings,
19+
UpdaterSettings, WindowsSettings, WixSettings,
2020
};
2121

2222
/// The `workspace` section of the app configuration (read from Cargo.toml).
@@ -431,7 +431,13 @@ fn tauri_config_to_bundle_settings(
431431
timestamp_url: config.windows.timestamp_url,
432432
digest_algorithm: config.windows.digest_algorithm,
433433
certificate_thumbprint: config.windows.certificate_thumbprint,
434-
wix: config.windows.wix.map(|w| w.into()),
434+
wix: config.windows.wix.map(|w| {
435+
let mut wix = WixSettings::from(w);
436+
wix.license = wix
437+
.license
438+
.map(|l| tauri_dir().join(l).to_string_lossy().into_owned());
439+
wix
440+
}),
435441
icon_path: windows_icon_path,
436442
},
437443
updater: Some(UpdaterSettings {

0 commit comments

Comments
 (0)