Skip to content

Commit c01770f

Browse files
authored
Fix resolving windows icon path (#5072)
Signed-off-by: Nico Burns <[email protected]>
1 parent 46b1639 commit c01770f

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

packages/cli/src/cli/bundle.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,35 @@ impl Bundle {
183183
bail!("\n\nBundle publisher was not provided in `Dioxus.toml`. Add it as:\n\n[bundle]\npublisher = \"MyCompany\"\n\n");
184184
}
185185

186+
/// Resolve an icon path relative to the crate dir
187+
fn canonicalize_icon_path(build: &BuildRequest, icon: &mut String) -> Result<(), Error> {
188+
let icon_path = build
189+
.crate_dir()
190+
.join(&icon)
191+
.canonicalize()
192+
.with_context(|| format!("Failed to canonicalize path to icon {icon:?}"))?;
193+
*icon = icon_path.to_string_lossy().to_string();
194+
Ok(())
195+
}
196+
197+
// Resolve bundle.icon relative to the crate dir
198+
if let Some(icons) = bundle_settings.icon.as_mut() {
199+
for icon in icons.iter_mut() {
200+
canonicalize_icon_path(build, icon)?;
201+
}
202+
}
203+
204+
#[allow(deprecated)]
186205
if cfg!(windows) {
206+
// Resolve bundle.windows.icon_path relative to the crate dir
207+
let mut windows_icon_path = bundle_settings
208+
.windows
209+
.icon_path
210+
.to_string_lossy()
211+
.to_string();
212+
canonicalize_icon_path(build, &mut windows_icon_path)?;
213+
bundle_settings.windows.icon_path = PathBuf::from(&windows_icon_path);
214+
187215
let windows_icon_override = krate.config.bundle.windows.as_ref().map(|w| &w.icon_path);
188216
if windows_icon_override.is_none() {
189217
let icon_path = bundle_settings
@@ -197,18 +225,6 @@ impl Bundle {
197225
}
198226
}
199227

200-
// resolve the icon relative to the crate, not the current working directory
201-
if let Some(icons) = bundle_settings.icon.as_mut() {
202-
for icon in icons {
203-
let icon_path = build
204-
.crate_dir()
205-
.join(&icon)
206-
.canonicalize()
207-
.with_context(|| format!("Failed to canonicalize path to icon {icon:?}"))?;
208-
*icon = icon_path.to_string_lossy().to_string();
209-
}
210-
}
211-
212228
if bundle_settings.resources_map.is_none() {
213229
bundle_settings.resources_map = Some(HashMap::new());
214230
}

0 commit comments

Comments
 (0)