Skip to content

Commit

Permalink
fix(cli): resolve bundle > icon glob when searching for .ico for …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
amrbashir and lucasfernog authored Oct 12, 2024
1 parent b3563e3 commit 069c05e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
7 changes: 7 additions & 0 deletions .changes/cli-crash-icon-glob.md
Original file line number Diff line number Diff line change
@@ -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`.
32 changes: 19 additions & 13 deletions crates/tauri-bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion crates/tauri-bundler/src/bundle/windows/msi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
16 changes: 2 additions & 14 deletions crates/tauri-cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 069c05e

Please sign in to comment.