Skip to content

Commit 314936e

Browse files
authored
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
1 parent 2747bb6 commit 314936e

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": patch
3+
---
4+
5+
Adds `icon_path` field to the `WindowsSettings` struct (defaults to `icons/icon.ico`).

tooling/bundler/src/bundle/settings.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub struct WixSettings {
194194
}
195195

196196
/// The Windows bundle settings.
197-
#[derive(Clone, Debug, Default)]
197+
#[derive(Clone, Debug)]
198198
pub struct WindowsSettings {
199199
/// The file digest algorithm to use for creating file signatures. Required for code signing. SHA-256 is recommended.
200200
pub digest_algorithm: Option<String>,
@@ -204,6 +204,20 @@ pub struct WindowsSettings {
204204
pub timestamp_url: Option<String>,
205205
/// WiX configuration.
206206
pub wix: Option<WixSettings>,
207+
/// The path to the application icon. Defaults to `./icons/icon.ico`.
208+
pub icon_path: PathBuf,
209+
}
210+
211+
impl Default for WindowsSettings {
212+
fn default() -> Self {
213+
Self {
214+
digest_algorithm: None,
215+
certificate_thumbprint: None,
216+
timestamp_url: None,
217+
wix: None,
218+
icon_path: PathBuf::from("icons/icon.ico"),
219+
}
220+
}
207221
}
208222

209223
/// The bundle settings of the BuildArtifact we're bundling.

tooling/bundler/src/bundle/windows/msi/wix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn copy_icon(settings: &Settings) -> crate::Result<PathBuf> {
141141
std::fs::create_dir_all(&resource_dir)?;
142142
let icon_target_path = resource_dir.join("icon.ico");
143143

144-
let icon_path = std::env::current_dir()?.join("icons").join("icon.ico");
144+
let icon_path = std::env::current_dir()?.join(&settings.windows().icon_path);
145145

146146
copy_file(
147147
icon_path,

tooling/cli.rs/src/build/rust.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ use anyhow::Context;
1414
use serde::Deserialize;
1515

1616
use crate::helpers::{app_paths::tauri_dir, config::Config};
17-
#[cfg(windows)]
18-
use tauri_bundler::WindowsSettings;
1917
use tauri_bundler::{
2018
AppCategory, BundleBinary, BundleSettings, DebianSettings, MacOsSettings, PackageSettings,
21-
UpdaterSettings,
19+
UpdaterSettings, WindowsSettings,
2220
};
2321

2422
/// The `workspace` section of the app configuration (read from Cargo.toml).
@@ -337,6 +335,16 @@ fn tauri_config_to_bundle_settings(
337335
config: crate::helpers::config::BundleConfig,
338336
updater_config: crate::helpers::config::UpdaterConfig,
339337
) -> crate::Result<BundleSettings> {
338+
#[cfg(windows)]
339+
let windows_icon_path = PathBuf::from(
340+
config
341+
.icon
342+
.as_ref()
343+
.and_then(|icons| icons.iter().find(|i| i.ends_with(".ico")).cloned())
344+
.expect("the bundle config must have a `.ico` icon"),
345+
);
346+
#[cfg(not(windows))]
347+
let windows_icon_path = PathBuf::from("");
340348
Ok(BundleSettings {
341349
identifier: config.identifier,
342350
icon: config.icon,
@@ -366,12 +374,12 @@ fn tauri_config_to_bundle_settings(
366374
signing_identity: config.macos.signing_identity,
367375
entitlements: config.macos.entitlements,
368376
},
369-
#[cfg(windows)]
370377
windows: WindowsSettings {
371378
timestamp_url: config.windows.timestamp_url,
372379
digest_algorithm: config.windows.digest_algorithm,
373380
certificate_thumbprint: config.windows.certificate_thumbprint,
374381
wix: config.windows.wix.map(|w| w.into()),
382+
icon_path: windows_icon_path,
375383
},
376384
updater: Some(UpdaterSettings {
377385
active: updater_config.active,

tooling/cli.rs/src/helpers/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use serde_json::Value as JsonValue;
1313
mod config_definition;
1414
pub use config_definition::*;
1515

16-
#[cfg(windows)]
1716
impl From<WixConfig> for tauri_bundler::WixSettings {
1817
fn from(config: WixConfig) -> tauri_bundler::WixSettings {
1918
tauri_bundler::WixSettings {

0 commit comments

Comments
 (0)