Skip to content

Commit e092f79

Browse files
authored
feat(bundler/nsis): allow specifying custom template, closes #6887 (#6922)
1 parent c2b0dab commit e092f79

File tree

8 files changed

+48
-15
lines changed

8 files changed

+48
-15
lines changed

.changes/nsis-custom-template.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'tauri-utils': 'minor'
3+
'tauri-bundler': 'minor'
4+
'cli.rs': 'minor'
5+
'cli.js': 'minor'
6+
---
7+
8+
Add `nsis > template` option to specify custom NSIS installer template.

core/tauri-config-schema/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,13 @@
16611661
"description": "Configuration for the Installer bundle using NSIS.",
16621662
"type": "object",
16631663
"properties": {
1664+
"template": {
1665+
"description": "A custom .nsi template to use.",
1666+
"type": [
1667+
"string",
1668+
"null"
1669+
]
1670+
},
16641671
"license": {
16651672
"description": "The path to the license file to render on the installer.",
16661673
"type": [

core/tauri-utils/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ pub struct WixConfig {
435435
#[cfg_attr(feature = "schema", derive(JsonSchema))]
436436
#[serde(rename_all = "camelCase", deny_unknown_fields)]
437437
pub struct NsisConfig {
438+
/// A custom .nsi template to use.
439+
pub template: Option<PathBuf>,
438440
/// The path to the license file to render on the installer.
439441
pub license: Option<PathBuf>,
440442
/// The path to a bitmap file to display on the header of installers pages.

tooling/bundler/src/bundle/settings.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ pub struct WixSettings {
252252
/// Settings specific to the NSIS implementation.
253253
#[derive(Clone, Debug, Default)]
254254
pub struct NsisSettings {
255+
/// A custom .nsi template to use.
256+
pub template: Option<PathBuf>,
255257
/// The path to the license file to render on the installer.
256258
pub license: Option<PathBuf>,
257259
/// The path to a bitmap file to display on the header of installers pages.

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ pub fn build_wix_app_installer(
615615
let mut fragment_paths = Vec::new();
616616
let mut handlebars = Handlebars::new();
617617
handlebars.register_escape_fn(handlebars::no_escape);
618-
let mut has_custom_template = false;
618+
let mut custom_template_path = None;
619619
let mut enable_elevated_update_task = false;
620620

621621
if let Some(wix) = &settings.windows().wix {
@@ -626,15 +626,7 @@ pub fn build_wix_app_installer(
626626
data.insert("merge_refs", to_json(&wix.merge_refs));
627627
fragment_paths = wix.fragment_paths.clone();
628628
enable_elevated_update_task = wix.enable_elevated_update_task;
629-
630-
if let Some(temp_path) = &wix.template {
631-
let template = read_to_string(temp_path)?;
632-
handlebars
633-
.register_template_string("main.wxs", &template)
634-
.map_err(|e| e.to_string())
635-
.expect("Failed to setup custom handlebar template");
636-
has_custom_template = true;
637-
}
629+
custom_template_path = wix.template.clone();
638630

639631
if let Some(banner_path) = &wix.banner_path {
640632
let filename = banner_path
@@ -661,7 +653,12 @@ pub fn build_wix_app_installer(
661653
}
662654
}
663655

664-
if !has_custom_template {
656+
if let Some(path) = custom_template_path {
657+
handlebars
658+
.register_template_string("main.wxs", read_to_string(path)?)
659+
.map_err(|e| e.to_string())
660+
.expect("Failed to setup custom handlebar template");
661+
} else {
665662
handlebars
666663
.register_template_string("main.wxs", include_str!("../templates/main.wxs"))
667664
.map_err(|e| e.to_string())

tooling/bundler/src/bundle/windows/nsis.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ fn build_nsis_app_installer(
188188

189189
let mut install_mode = NSISInstallerMode::CurrentUser;
190190
let mut languages = vec!["English".into()];
191+
let mut custom_template_path = None;
191192
if let Some(nsis) = &settings.windows().nsis {
193+
custom_template_path = nsis.template.clone();
192194
install_mode = nsis.install_mode;
193195
if let Some(langs) = &nsis.languages {
194196
languages.clear();
@@ -359,10 +361,17 @@ fn build_nsis_app_installer(
359361
}
360362
output
361363
});
362-
handlebars
363-
.register_template_string("installer.nsi", include_str!("./templates/installer.nsi"))
364-
.map_err(|e| e.to_string())
365-
.expect("Failed to setup handlebar template");
364+
if let Some(path) = custom_template_path {
365+
handlebars
366+
.register_template_string("installer.nsi", std::fs::read_to_string(path)?)
367+
.map_err(|e| e.to_string())
368+
.expect("Failed to setup custom handlebar template");
369+
} else {
370+
handlebars
371+
.register_template_string("installer.nsi", include_str!("./templates/installer.nsi"))
372+
.map_err(|e| e.to_string())
373+
.expect("Failed to setup handlebar template");
374+
}
366375
let installer_nsi_path = output_path.join("installer.nsi");
367376
write(
368377
&installer_nsi_path,

tooling/cli/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,13 @@
16611661
"description": "Configuration for the Installer bundle using NSIS.",
16621662
"type": "object",
16631663
"properties": {
1664+
"template": {
1665+
"description": "A custom .nsi template to use.",
1666+
"type": [
1667+
"string",
1668+
"null"
1669+
]
1670+
},
16641671
"license": {
16651672
"description": "The path to the license file to render on the installer.",
16661673
"type": [

tooling/cli/src/helpers/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub fn wix_settings(config: WixConfig) -> tauri_bundler::WixSettings {
9999

100100
pub fn nsis_settings(config: NsisConfig) -> tauri_bundler::NsisSettings {
101101
tauri_bundler::NsisSettings {
102+
template: config.template,
102103
license: config.license,
103104
header_image: config.header_image,
104105
sidebar_image: config.sidebar_image,

0 commit comments

Comments
 (0)