Skip to content

Commit 069c05e

Browse files
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 <[email protected]> * Update crates/tauri-bundler/src/bundle/windows/msi/mod.rs Co-authored-by: Lucas Fernandes Nogueira <[email protected]> * Update crates/tauri-bundler/src/bundle/windows/msi/mod.rs Co-authored-by: Lucas Fernandes Nogueira <[email protected]> --------- Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
1 parent b3563e3 commit 069c05e

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

.changes/cli-crash-icon-glob.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-cli": "patch:bug"
3+
"@tauri-apps/cli": "patch:bug"
4+
"tauri-bundler": "patch:bug"
5+
---
6+
7+
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`.

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ pub struct WindowsSettings {
501501
/// Nsis configuration.
502502
pub nsis: Option<NsisSettings>,
503503
/// The path to the application icon. Defaults to `./icons/icon.ico`.
504+
#[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."]
504505
pub icon_path: PathBuf,
505506
/// The installation mode for the Webview2 runtime.
506507
pub webview_install_mode: WebviewInstallMode,
@@ -526,19 +527,24 @@ pub struct WindowsSettings {
526527
pub sign_command: Option<CustomSignCommandSettings>,
527528
}
528529

529-
impl Default for WindowsSettings {
530-
fn default() -> Self {
531-
Self {
532-
digest_algorithm: None,
533-
certificate_thumbprint: None,
534-
timestamp_url: None,
535-
tsp: false,
536-
wix: None,
537-
nsis: None,
538-
icon_path: PathBuf::from("icons/icon.ico"),
539-
webview_install_mode: Default::default(),
540-
allow_downgrades: true,
541-
sign_command: None,
530+
#[allow(deprecated)]
531+
mod _default {
532+
use super::*;
533+
534+
impl Default for WindowsSettings {
535+
fn default() -> Self {
536+
Self {
537+
digest_algorithm: None,
538+
certificate_thumbprint: None,
539+
timestamp_url: None,
540+
tsp: false,
541+
wix: None,
542+
nsis: None,
543+
icon_path: PathBuf::from("icons/icon.ico"),
544+
webview_install_mode: Default::default(),
545+
allow_downgrades: true,
546+
sign_command: None,
547+
}
542548
}
543549
}
544550
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,17 @@ pub fn build_wix_app_installer(
604604
data.insert("main_binary_path", to_json(main_binary_path));
605605

606606
// copy icon from `settings.windows().icon_path` folder to resource folder near msi
607-
let icon_path = copy_icon(settings, "icon.ico", &settings.windows().icon_path)?;
607+
#[allow(deprecated)]
608+
let icon_path = if !settings.windows().icon_path.as_os_str().is_empty() {
609+
settings.windows().icon_path.clone()
610+
} else {
611+
settings
612+
.icon_files()
613+
.flatten()
614+
.find(|i| i.ends_with(".ico"))
615+
.context("Couldn't find a .ico icon")?
616+
};
617+
let icon_path = copy_icon(settings, "icon.ico", &icon_path)?;
608618

609619
data.insert("icon_path", to_json(icon_path));
610620

crates/tauri-cli/src/interface/rust.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ pub fn get_profile_dir(options: &Options) -> &str {
12021202
}
12031203
}
12041204

1205-
#[allow(unused_variables)]
1205+
#[allow(unused_variables, deprecated)]
12061206
fn tauri_config_to_bundle_settings(
12071207
settings: &RustAppSettings,
12081208
features: &[String],
@@ -1217,18 +1217,6 @@ fn tauri_config_to_bundle_settings(
12171217
.unwrap()
12181218
.all_enabled_features(features);
12191219

1220-
#[cfg(windows)]
1221-
let windows_icon_path = PathBuf::from(
1222-
config
1223-
.icon
1224-
.iter()
1225-
.find(|i| i.ends_with(".ico"))
1226-
.cloned()
1227-
.expect("the bundle config must have a `.ico` icon"),
1228-
);
1229-
#[cfg(not(windows))]
1230-
let windows_icon_path = PathBuf::from("");
1231-
12321220
#[allow(unused_mut)]
12331221
let mut resources = config
12341222
.resources
@@ -1440,7 +1428,7 @@ fn tauri_config_to_bundle_settings(
14401428
certificate_thumbprint: config.windows.certificate_thumbprint,
14411429
wix: config.windows.wix.map(wix_settings),
14421430
nsis: config.windows.nsis.map(nsis_settings),
1443-
icon_path: windows_icon_path,
1431+
icon_path: PathBuf::new(),
14441432
webview_install_mode: config.windows.webview_install_mode,
14451433
allow_downgrades: config.windows.allow_downgrades,
14461434
sign_command: config.windows.sign_command.map(custom_sign_settings),

0 commit comments

Comments
 (0)