Просмотр исходного кода

feat(bundler): windows installer license, closes #2009 (#2027)

Lucas Fernandes Nogueira 4 лет назад
Родитель
Сommit
b769c7f7da

+ 6 - 0
.changes/msi-license.md

@@ -0,0 +1,6 @@
+---
+"cli.rs": patch
+"tauri-bundler": patch
+---
+
+Allow setting a path to a license file for the Windows Installer (`tauri.conf.json > bundle > windows > wix > license`).

+ 2 - 1
docs/api/config.md

@@ -168,7 +168,8 @@ It's composed of the following properties:
           { property: "featureGroupRefs", optional: true, type: "string[]", description: `The FeatureGroup element ids you want to reference from the fragments.` },
           { property: "featureRefs", optional: true, type: "string[]", description: `The Feature element ids you want to reference from the fragments.` },
           { property: "mergeRefs", optional: true, type: "string[]", description: `The Merge element ids you want to reference from the fragments.` },
-          { property: "skipWebviewInstall", optional: true, type: "boolean", description: `Disables the Webview2 runtime installation after app install.` }]} />
+          { property: "skipWebviewInstall", optional: true, type: "boolean", description: `Disables the Webview2 runtime installation after app install.` },
+          { 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.` }]} />
         }
         ]} />
       },

+ 2 - 0
tooling/bundler/src/bundle/settings.rs

@@ -194,6 +194,8 @@ pub struct WixSettings {
   pub merge_refs: Vec<String>,
   /// Disables the Webview2 runtime installation after app install.
   pub skip_webview_install: bool,
+  /// The path to the LICENSE file.
+  pub license: Option<String>,
 }
 
 /// The Windows bundle settings.

+ 25 - 0
tooling/bundler/src/bundle/windows/msi/wix.rs

@@ -414,6 +414,31 @@ pub fn build_wix_app_installer(
   let language_map: HashMap<String, LanguageMetadata> =
     serde_json::from_str(include_str!("./languages.json")).unwrap();
 
+  if let Some(wix) = &settings.windows().wix {
+    if let Some(license) = &wix.license {
+      if license.ends_with(".rtf") {
+        data.insert("license", to_json(license));
+      } else {
+        let license_path = PathBuf::from(license);
+        let license_contents = std::fs::read_to_string(&license_path)?;
+        let license_rtf = format!(
+          r#"{{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{{\fonttbl{{\f0\fnil\fcharset0 Calibri;}}}}
+{{\*\generator Riched20 10.0.18362}}\viewkind4\uc1 
+\pard\sa200\sl276\slmult1\f0\fs22\lang9 {}\par
+}}
+ "#,
+          license_contents.replace("\n", "\\par ")
+        );
+        let rtf_output_path = settings
+          .project_out_directory()
+          .join("wix")
+          .join("LICENSE.rtf");
+        std::fs::write(&rtf_output_path, license_rtf)?;
+        data.insert("license", to_json(rtf_output_path));
+      }
+    }
+  }
+
   let (language, language_metadata) = if let Some(wix) = &settings.windows().wix {
     let metadata = language_map.get(&wix.language).unwrap_or_else(|| {
       panic!(

+ 5 - 0
tooling/bundler/src/bundle/windows/templates/main.wxs

@@ -33,6 +33,9 @@
         <Media Id="1" Cabinet="app.cab" EmbedCab="yes" />
         
         <WixVariable Id="WixUIBannerBmp" Value="{{{icon_path}}}" />
+        {{#if license}}
+        <WixVariable Id="WixUILicenseRtf" Value="{{{license}}}" />
+        {{/if}}
         
         <Icon Id="ProductIcon" SourceFile="{{{icon_path}}}"/>
         <Property Id="ARPPRODUCTICON" Value="ProductIcon" />
@@ -42,6 +45,7 @@
         <UI>
             <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
 
+            {{#unless license}}
             <!-- Skip license dialog -->
             <Publish Dialog="WelcomeDlg"
                      Control="Next"
@@ -53,6 +57,7 @@
                      Event="NewDialog"
                      Value="WelcomeDlg"
                      Order="2">1</Publish>
+            {{/unless}}
         </UI>
 
         <UIRef Id="WixUI_InstallDir" />

+ 2 - 0
tooling/cli.rs/config_definition.rs

@@ -78,6 +78,8 @@ pub struct WixConfig {
   pub merge_refs: Vec<String>,
   #[serde(default)]
   pub skip_webview_install: bool,
+  /// Path to the license file.
+  pub license: Option<String>,
 }
 
 #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]

+ 7 - 0
tooling/cli.rs/schema.json

@@ -1294,6 +1294,13 @@
           "default": "en-US",
           "type": "string"
         },
+        "license": {
+          "description": "Path to the license file.",
+          "type": [
+            "string",
+            "null"
+          ]
+        },
         "mergeRefs": {
           "default": [],
           "type": "array",

+ 1 - 0
tooling/cli.rs/src/helpers/config.rs

@@ -25,6 +25,7 @@ impl From<WixConfig> for tauri_bundler::WixSettings {
       feature_refs: config.feature_refs,
       merge_refs: config.merge_refs,
       skip_webview_install: config.skip_webview_install,
+      license: config.license,
     }
   }
 }

+ 8 - 2
tooling/cli.rs/src/interface/rust.rs

@@ -16,7 +16,7 @@ use serde::Deserialize;
 use crate::helpers::{app_paths::tauri_dir, config::Config, manifest::Manifest};
 use tauri_bundler::{
   AppCategory, BundleBinary, BundleSettings, DebianSettings, MacOsSettings, PackageSettings,
-  UpdaterSettings, WindowsSettings,
+  UpdaterSettings, WindowsSettings, WixSettings,
 };
 
 /// The `workspace` section of the app configuration (read from Cargo.toml).
@@ -431,7 +431,13 @@ fn tauri_config_to_bundle_settings(
       timestamp_url: config.windows.timestamp_url,
       digest_algorithm: config.windows.digest_algorithm,
       certificate_thumbprint: config.windows.certificate_thumbprint,
-      wix: config.windows.wix.map(|w| w.into()),
+      wix: config.windows.wix.map(|w| {
+        let mut wix = WixSettings::from(w);
+        wix.license = wix
+          .license
+          .map(|l| tauri_dir().join(l).to_string_lossy().into_owned());
+        wix
+      }),
       icon_path: windows_icon_path,
     },
     updater: Some(UpdaterSettings {