Skip to content

Commit

Permalink
feat(bundler): add icon path config instead of enforcing icons/icon.i…
Browse files Browse the repository at this point in the history
…co (#1698)

* feat(bundler): add icon path config instead of enforcing icons/icon.ico

* fix: build on unix
  • Loading branch information
lucasfernog authored May 4, 2021
1 parent 2747bb6 commit 314936e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changes/bundler-windows-icon-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---

Adds `icon_path` field to the `WindowsSettings` struct (defaults to `icons/icon.ico`).
16 changes: 15 additions & 1 deletion tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub struct WixSettings {
}

/// The Windows bundle settings.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct WindowsSettings {
/// The file digest algorithm to use for creating file signatures. Required for code signing. SHA-256 is recommended.
pub digest_algorithm: Option<String>,
Expand All @@ -204,6 +204,20 @@ pub struct WindowsSettings {
pub timestamp_url: Option<String>,
/// WiX configuration.
pub wix: Option<WixSettings>,
/// The path to the application icon. Defaults to `./icons/icon.ico`.
pub icon_path: PathBuf,
}

impl Default for WindowsSettings {
fn default() -> Self {
Self {
digest_algorithm: None,
certificate_thumbprint: None,
timestamp_url: None,
wix: None,
icon_path: PathBuf::from("icons/icon.ico"),
}
}
}

/// The bundle settings of the BuildArtifact we're bundling.
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/windows/msi/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn copy_icon(settings: &Settings) -> crate::Result<PathBuf> {
std::fs::create_dir_all(&resource_dir)?;
let icon_target_path = resource_dir.join("icon.ico");

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

copy_file(
icon_path,
Expand Down
16 changes: 12 additions & 4 deletions tooling/cli.rs/src/build/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ use anyhow::Context;
use serde::Deserialize;

use crate::helpers::{app_paths::tauri_dir, config::Config};
#[cfg(windows)]
use tauri_bundler::WindowsSettings;
use tauri_bundler::{
AppCategory, BundleBinary, BundleSettings, DebianSettings, MacOsSettings, PackageSettings,
UpdaterSettings,
UpdaterSettings, WindowsSettings,
};

/// The `workspace` section of the app configuration (read from Cargo.toml).
Expand Down Expand Up @@ -337,6 +335,16 @@ fn tauri_config_to_bundle_settings(
config: crate::helpers::config::BundleConfig,
updater_config: crate::helpers::config::UpdaterConfig,
) -> crate::Result<BundleSettings> {
#[cfg(windows)]
let windows_icon_path = PathBuf::from(
config
.icon
.as_ref()
.and_then(|icons| icons.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("");
Ok(BundleSettings {
identifier: config.identifier,
icon: config.icon,
Expand Down Expand Up @@ -366,12 +374,12 @@ fn tauri_config_to_bundle_settings(
signing_identity: config.macos.signing_identity,
entitlements: config.macos.entitlements,
},
#[cfg(windows)]
windows: WindowsSettings {
timestamp_url: config.windows.timestamp_url,
digest_algorithm: config.windows.digest_algorithm,
certificate_thumbprint: config.windows.certificate_thumbprint,
wix: config.windows.wix.map(|w| w.into()),
icon_path: windows_icon_path,
},
updater: Some(UpdaterSettings {
active: updater_config.active,
Expand Down
1 change: 0 additions & 1 deletion tooling/cli.rs/src/helpers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use serde_json::Value as JsonValue;
mod config_definition;
pub use config_definition::*;

#[cfg(windows)]
impl From<WixConfig> for tauri_bundler::WixSettings {
fn from(config: WixConfig) -> tauri_bundler::WixSettings {
tauri_bundler::WixSettings {
Expand Down

0 comments on commit 314936e

Please sign in to comment.