Skip to content

Commit

Permalink
feat(bundler): add nsis, closes #4450, closes #2319 (#4674)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
3 people committed Jan 3, 2023
1 parent 4892637 commit c94e132
Show file tree
Hide file tree
Showing 22 changed files with 1,718 additions and 286 deletions.
8 changes: 8 additions & 0 deletions .changes/nsis.md
@@ -0,0 +1,8 @@
---
"tauri-bundler": minor
"tauri-utils": minor
"cli.rs": minor
"cli.js": minor
---

Add `nsis` bundle target
112 changes: 107 additions & 5 deletions core/config-schema/schema.json
Expand Up @@ -146,6 +146,7 @@
"allowDowngrades": true,
"certificateThumbprint": null,
"digestAlgorithm": null,
"nsis": null,
"timestampUrl": null,
"tsp": false,
"webviewFixedRuntimePath": null,
Expand All @@ -169,7 +170,8 @@
"dialog": true,
"pubkey": "",
"windows": {
"installMode": "passive"
"installMode": "passive",
"installerArgs": []
}
},
"windows": []
Expand Down Expand Up @@ -282,6 +284,7 @@
"allowDowngrades": true,
"certificateThumbprint": null,
"digestAlgorithm": null,
"nsis": null,
"timestampUrl": null,
"tsp": false,
"webviewFixedRuntimePath": null,
Expand Down Expand Up @@ -427,7 +430,8 @@
"dialog": true,
"pubkey": "",
"windows": {
"installMode": "passive"
"installMode": "passive",
"installerArgs": []
}
},
"allOf": [
Expand Down Expand Up @@ -1018,7 +1022,7 @@
"type": "boolean"
},
"targets": {
"description": "The bundle targets, currently supports [\"deb\", \"appimage\", \"msi\", \"app\", \"dmg\", \"updater\"] or \"all\".",
"description": "The bundle targets, currently supports [\"deb\", \"appimage\", \"nsis\", \"msi\", \"app\", \"dmg\", \"updater\"] or \"all\".",
"default": "all",
"allOf": [
{
Expand Down Expand Up @@ -1132,6 +1136,7 @@
"allowDowngrades": true,
"certificateThumbprint": null,
"digestAlgorithm": null,
"nsis": null,
"timestampUrl": null,
"tsp": false,
"webviewFixedRuntimePath": null,
Expand Down Expand Up @@ -1200,6 +1205,13 @@
"msi"
]
},
{
"description": "The NSIS bundle (.exe).",
"type": "string",
"enum": [
"nsis"
]
},
{
"description": "The macOS application bundle (.app).",
"type": "string",
Expand Down Expand Up @@ -1384,6 +1396,17 @@
"type": "null"
}
]
},
"nsis": {
"description": "Configuration for the installer generated with NSIS.",
"anyOf": [
{
"$ref": "#/definitions/NsisConfig"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1632,6 +1655,76 @@
},
"additionalProperties": false
},
"NsisConfig": {
"description": "Configuration for the Installer bundle using NSIS.",
"type": "object",
"properties": {
"license": {
"description": "The path to the license file to render on the installer.",
"type": [
"string",
"null"
]
},
"headerImage": {
"description": "The path to a bitmap file to display on the header of installers pages.\n\nThe recommended dimensions are 150px x 57px.",
"type": [
"string",
"null"
]
},
"sidebarImage": {
"description": "The path to a bitmap file for the Welcome page and the Finish page.\n\nThe recommended dimensions are 164px x 314px.",
"type": [
"string",
"null"
]
},
"installerIcon": {
"description": "The path to an icon file used as the installer icon.",
"type": [
"string",
"null"
]
},
"installMode": {
"description": "Whether the installation will be for all users or just the current user.",
"default": "currentUser",
"allOf": [
{
"$ref": "#/definitions/NSISInstallerMode"
}
]
}
},
"additionalProperties": false
},
"NSISInstallerMode": {
"description": "Install Modes for the NSIS installer.",
"oneOf": [
{
"description": "Default mode for the installer.\n\nInstall the app by default in a directory that doesn't require Administrator access.\n\nInstaller metadata will be saved under the `HKCU` registry path.",
"type": "string",
"enum": [
"currentUser"
]
},
{
"description": "Install the app by default in the `Program Files` folder directory requires Administrator access for the installation.\n\nInstaller metadata will be saved under the `HKLM` registry path.",
"type": "string",
"enum": [
"perMachine"
]
},
{
"description": "Combines both modes and allows the user to choose at install time whether to install for the current user or per machine. Note that this mode will require Administrator access even if the user wants to install it for the current user only.\n\nInstaller metadata will be saved under the `HKLM` or `HKCU` registry path based on the user's choice.",
"type": "string",
"enum": [
"both"
]
}
]
},
"AllowlistConfig": {
"description": "Allowlist configuration.",
"type": "object",
Expand Down Expand Up @@ -2579,7 +2672,8 @@
"windows": {
"description": "The Windows configuration for the updater.",
"default": {
"installMode": "passive"
"installMode": "passive",
"installerArgs": []
},
"allOf": [
{
Expand All @@ -2599,6 +2693,14 @@
"description": "The updater configuration for Windows.",
"type": "object",
"properties": {
"installerArgs": {
"description": "Additional arguments given to the NSIS or WiX installer.",
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"installMode": {
"description": "The installation mode for the update on Windows. Defaults to `passive`.",
"default": "passive",
Expand All @@ -2622,7 +2724,7 @@
]
},
{
"description": "The quiet mode means there's no user interaction required. Requires admin privileges if the installer does.",
"description": "The quiet mode means there's no user interaction required. Requires admin privileges if the installer does (WiX).",
"type": "string",
"enum": [
"quiet"
Expand Down
69 changes: 66 additions & 3 deletions core/tauri-utils/src/config.rs
Expand Up @@ -78,6 +78,8 @@ pub enum BundleType {
AppImage,
/// The Microsoft Installer bundle (.msi).
Msi,
/// The NSIS bundle (.exe).
Nsis,
/// The macOS application bundle (.app).
App,
/// The Apple Disk Image bundle (.dmg).
Expand All @@ -95,6 +97,7 @@ impl Display for BundleType {
Self::Deb => "deb",
Self::AppImage => "appimage",
Self::Msi => "msi",
Self::Nsis => "nsis",
Self::App => "app",
Self::Dmg => "dmg",
Self::Updater => "updater",
Expand Down Expand Up @@ -122,6 +125,7 @@ impl<'de> Deserialize<'de> for BundleType {
"deb" => Ok(Self::Deb),
"appimage" => Ok(Self::AppImage),
"msi" => Ok(Self::Msi),
"nsis" => Ok(Self::Nsis),
"app" => Ok(Self::App),
"dmg" => Ok(Self::Dmg),
"updater" => Ok(Self::Updater),
Expand Down Expand Up @@ -416,6 +420,58 @@ pub struct WixConfig {
pub dialog_image_path: Option<PathBuf>,
}

/// Configuration for the Installer bundle using NSIS.
#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct NsisConfig {
/// The path to the license file to render on the installer.
pub license: Option<PathBuf>,
/// The path to a bitmap file to display on the header of installers pages.
///
/// The recommended dimensions are 150px x 57px.
pub header_image: Option<PathBuf>,
/// The path to a bitmap file for the Welcome page and the Finish page.
///
/// The recommended dimensions are 164px x 314px.
pub sidebar_image: Option<PathBuf>,
/// The path to an icon file used as the installer icon.
pub installer_icon: Option<PathBuf>,
/// Whether the installation will be for all users or just the current user.
#[serde(default)]
pub install_mode: NSISInstallerMode,
}

/// Install Modes for the NSIS installer.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub enum NSISInstallerMode {
/// Default mode for the installer.
///
/// Install the app by default in a directory that doesn't require Administrator access.
///
/// Installer metadata will be saved under the `HKCU` registry path.
CurrentUser,
/// Install the app by default in the `Program Files` folder directory requires Administrator
/// access for the installation.
///
/// Installer metadata will be saved under the `HKLM` registry path.
PerMachine,
/// Combines both modes and allows the user to choose at install time
/// whether to install for the current user or per machine. Note that this mode
/// will require Administrator access even if the user wants to install it for the current user only.
///
/// Installer metadata will be saved under the `HKLM` or `HKCU` registry path based on the user's choice.
Both,
}

impl Default for NSISInstallerMode {
fn default() -> Self {
Self::CurrentUser
}
}

/// Install modes for the Webview2 runtime.
/// Note that for the updater bundle [`Self::DownloadBootstrapper`] is used.
///
Expand Down Expand Up @@ -512,6 +568,8 @@ pub struct WindowsConfig {
pub allow_downgrades: bool,
/// Configuration for the MSI generated with WiX.
pub wix: Option<WixConfig>,
/// Configuration for the installer generated with NSIS.
pub nsis: Option<NsisConfig>,
}

impl Default for WindowsConfig {
Expand All @@ -525,6 +583,7 @@ impl Default for WindowsConfig {
webview_fixed_runtime_path: None,
allow_downgrades: default_allow_downgrades(),
wix: None,
nsis: None,
}
}
}
Expand All @@ -542,7 +601,7 @@ pub struct BundleConfig {
/// Whether Tauri should bundle your application or just output the executable.
#[serde(default)]
pub active: bool,
/// The bundle targets, currently supports ["deb", "appimage", "msi", "app", "dmg", "updater"] or "all".
/// The bundle targets, currently supports ["deb", "appimage", "nsis", "msi", "app", "dmg", "updater"] or "all".
#[serde(default)]
pub targets: BundleTarget,
/// The application identifier in reverse domain name notation (e.g. `com.tauri.example`).
Expand Down Expand Up @@ -2306,7 +2365,7 @@ pub enum WindowsUpdateInstallMode {
/// Specifies there's a basic UI during the installation process, including a final dialog box at the end.
BasicUi,
/// The quiet mode means there's no user interaction required.
/// Requires admin privileges if the installer does.
/// Requires admin privileges if the installer does (WiX).
Quiet,
/// Specifies unattended mode, which means the installation only shows a progress bar.
Passive,
Expand Down Expand Up @@ -2377,6 +2436,9 @@ impl<'de> Deserialize<'de> for WindowsUpdateInstallMode {
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct UpdaterWindowsConfig {
/// Additional arguments given to the NSIS or WiX installer.
#[serde(default, alias = "installer-args")]
pub installer_args: Vec<String>,
/// The installation mode for the update on Windows. Defaults to `passive`.
#[serde(default, alias = "install-mode")]
pub install_mode: WindowsUpdateInstallMode,
Expand Down Expand Up @@ -3355,7 +3417,8 @@ mod build {
impl ToTokens for UpdaterWindowsConfig {
fn to_tokens(&self, tokens: &mut TokenStream) {
let install_mode = &self.install_mode;
literal_struct!(tokens, UpdaterWindowsConfig, install_mode);
let installer_args = vec_lit(&self.installer_args, str_lit);
literal_struct!(tokens, UpdaterWindowsConfig, install_mode, installer_args);
}
}

Expand Down

0 comments on commit c94e132

Please sign in to comment.