Forráskód Böngészése

feat(bundler): add icon path config instead of enforcing icons/icon.ico (#1698)

* feat(bundler): add icon path config instead of enforcing icons/icon.ico

* fix: build on unix
Lucas Fernandes Nogueira 4 éve
szülő
commit
314936efbe

+ 5 - 0
.changes/bundler-windows-icon-path.md

@@ -0,0 +1,5 @@
+---
+"tauri-bundler": patch
+---
+
+Adds `icon_path` field to the `WindowsSettings` struct (defaults to `icons/icon.ico`).

+ 15 - 1
tooling/bundler/src/bundle/settings.rs

@@ -194,7 +194,7 @@ pub struct WixSettings {
 }
 
 /// The Windows bundle settings.
-#[derive(Clone, Debug, Default)]
+#[derive(Clone, Debug)]
 pub struct WindowsSettings {
   /// The file digest algorithm to use for creating file signatures. Required for code signing. SHA-256 is recommended.
   pub digest_algorithm: Option<String>,
@@ -204,6 +204,20 @@ pub struct WindowsSettings {
   pub timestamp_url: Option<String>,
   /// WiX configuration.
   pub wix: Option<WixSettings>,
+  /// The path to the application icon. Defaults to `./icons/icon.ico`.
+  pub icon_path: PathBuf,
+}
+
+impl Default for WindowsSettings {
+  fn default() -> Self {
+    Self {
+      digest_algorithm: None,
+      certificate_thumbprint: None,
+      timestamp_url: None,
+      wix: None,
+      icon_path: PathBuf::from("icons/icon.ico"),
+    }
+  }
 }
 
 /// The bundle settings of the BuildArtifact we're bundling.

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

@@ -141,7 +141,7 @@ fn copy_icon(settings: &Settings) -> crate::Result<PathBuf> {
   std::fs::create_dir_all(&resource_dir)?;
   let icon_target_path = resource_dir.join("icon.ico");
 
-  let icon_path = std::env::current_dir()?.join("icons").join("icon.ico");
+  let icon_path = std::env::current_dir()?.join(&settings.windows().icon_path);
 
   copy_file(
     icon_path,

+ 12 - 4
tooling/cli.rs/src/build/rust.rs

@@ -14,11 +14,9 @@ use anyhow::Context;
 use serde::Deserialize;
 
 use crate::helpers::{app_paths::tauri_dir, config::Config};
-#[cfg(windows)]
-use tauri_bundler::WindowsSettings;
 use tauri_bundler::{
   AppCategory, BundleBinary, BundleSettings, DebianSettings, MacOsSettings, PackageSettings,
-  UpdaterSettings,
+  UpdaterSettings, WindowsSettings,
 };
 
 /// The `workspace` section of the app configuration (read from Cargo.toml).
@@ -337,6 +335,16 @@ fn tauri_config_to_bundle_settings(
   config: crate::helpers::config::BundleConfig,
   updater_config: crate::helpers::config::UpdaterConfig,
 ) -> crate::Result<BundleSettings> {
+  #[cfg(windows)]
+  let windows_icon_path = PathBuf::from(
+    config
+      .icon
+      .as_ref()
+      .and_then(|icons| icons.iter().find(|i| i.ends_with(".ico")).cloned())
+      .expect("the bundle config must have a `.ico` icon"),
+  );
+  #[cfg(not(windows))]
+  let windows_icon_path = PathBuf::from("");
   Ok(BundleSettings {
     identifier: config.identifier,
     icon: config.icon,
@@ -366,12 +374,12 @@ fn tauri_config_to_bundle_settings(
       signing_identity: config.macos.signing_identity,
       entitlements: config.macos.entitlements,
     },
-    #[cfg(windows)]
     windows: WindowsSettings {
       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()),
+      icon_path: windows_icon_path,
     },
     updater: Some(UpdaterSettings {
       active: updater_config.active,

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

@@ -13,7 +13,6 @@ use serde_json::Value as JsonValue;
 mod config_definition;
 pub use config_definition::*;
 
-#[cfg(windows)]
 impl From<WixConfig> for tauri_bundler::WixSettings {
   fn from(config: WixConfig) -> tauri_bundler::WixSettings {
     tauri_bundler::WixSettings {