瀏覽代碼

fix(cli): resolve `bundle > icon` glob when searching for `.ico` for MSI installer (#11315)

* fix(cli): resolve `bundle > icon` glob when searching for `.ico` for MSI installer

closes #11220

* Update crates/tauri-bundler/src/bundle/settings.rs

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>

* Update crates/tauri-bundler/src/bundle/windows/msi/mod.rs

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>

* Update crates/tauri-bundler/src/bundle/windows/msi/mod.rs

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>

---------

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
Amr Bashir 9 月之前
父節點
當前提交
069c05e44f

+ 7 - 0
.changes/cli-crash-icon-glob.md

@@ -0,0 +1,7 @@
+---
+"tauri-cli": "patch:bug"
+"@tauri-apps/cli": "patch:bug"
+"tauri-bundler": "patch:bug"
+---
+
+Fix CLI crashing and failing to find a `.ico` file when `bundle > icon` option is using globs and doesn't have a string that ends with `.ico`.

+ 19 - 13
crates/tauri-bundler/src/bundle/settings.rs

@@ -501,6 +501,7 @@ pub struct WindowsSettings {
   /// Nsis configuration.
   pub nsis: Option<NsisSettings>,
   /// The path to the application icon. Defaults to `./icons/icon.ico`.
+  #[deprecated = "This is used for the MSI installer and will be removed in 3.0.0, use `BundleSettings::icon` field and make sure a `.ico` icon exists instead."]
   pub icon_path: PathBuf,
   /// The installation mode for the Webview2 runtime.
   pub webview_install_mode: WebviewInstallMode,
@@ -526,19 +527,24 @@ pub struct WindowsSettings {
   pub sign_command: Option<CustomSignCommandSettings>,
 }
 
-impl Default for WindowsSettings {
-  fn default() -> Self {
-    Self {
-      digest_algorithm: None,
-      certificate_thumbprint: None,
-      timestamp_url: None,
-      tsp: false,
-      wix: None,
-      nsis: None,
-      icon_path: PathBuf::from("icons/icon.ico"),
-      webview_install_mode: Default::default(),
-      allow_downgrades: true,
-      sign_command: None,
+#[allow(deprecated)]
+mod _default {
+  use super::*;
+
+  impl Default for WindowsSettings {
+    fn default() -> Self {
+      Self {
+        digest_algorithm: None,
+        certificate_thumbprint: None,
+        timestamp_url: None,
+        tsp: false,
+        wix: None,
+        nsis: None,
+        icon_path: PathBuf::from("icons/icon.ico"),
+        webview_install_mode: Default::default(),
+        allow_downgrades: true,
+        sign_command: None,
+      }
     }
   }
 }

+ 11 - 1
crates/tauri-bundler/src/bundle/windows/msi/mod.rs

@@ -604,7 +604,17 @@ pub fn build_wix_app_installer(
   data.insert("main_binary_path", to_json(main_binary_path));
 
   // copy icon from `settings.windows().icon_path` folder to resource folder near msi
-  let icon_path = copy_icon(settings, "icon.ico", &settings.windows().icon_path)?;
+  #[allow(deprecated)]
+  let icon_path = if !settings.windows().icon_path.as_os_str().is_empty() {
+    settings.windows().icon_path.clone()
+  } else {
+    settings
+      .icon_files()
+      .flatten()
+      .find(|i| i.ends_with(".ico"))
+      .context("Couldn't find a .ico icon")?
+  };
+  let icon_path = copy_icon(settings, "icon.ico", &icon_path)?;
 
   data.insert("icon_path", to_json(icon_path));
 

+ 2 - 14
crates/tauri-cli/src/interface/rust.rs

@@ -1202,7 +1202,7 @@ pub fn get_profile_dir(options: &Options) -> &str {
   }
 }
 
-#[allow(unused_variables)]
+#[allow(unused_variables, deprecated)]
 fn tauri_config_to_bundle_settings(
   settings: &RustAppSettings,
   features: &[String],
@@ -1217,18 +1217,6 @@ fn tauri_config_to_bundle_settings(
     .unwrap()
     .all_enabled_features(features);
 
-  #[cfg(windows)]
-  let windows_icon_path = PathBuf::from(
-    config
-      .icon
-      .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("");
-
   #[allow(unused_mut)]
   let mut resources = config
     .resources
@@ -1440,7 +1428,7 @@ fn tauri_config_to_bundle_settings(
       certificate_thumbprint: config.windows.certificate_thumbprint,
       wix: config.windows.wix.map(wix_settings),
       nsis: config.windows.nsis.map(nsis_settings),
-      icon_path: windows_icon_path,
+      icon_path: PathBuf::new(),
       webview_install_mode: config.windows.webview_install_mode,
       allow_downgrades: config.windows.allow_downgrades,
       sign_command: config.windows.sign_command.map(custom_sign_settings),