@@ -60,24 +60,15 @@ fn copy_resources(resources: ResourcePaths<'_>, path: &Path) -> Result<()> {
6060
6161/// Attributes used on Windows.
6262#[ allow( dead_code) ]
63- #[ derive( Debug ) ]
63+ #[ derive( Debug , Default ) ]
6464pub struct WindowsAttributes {
65- window_icon_path : PathBuf ,
65+ window_icon_path : Option < PathBuf > ,
6666 /// The path to the sdk location. This can be a absolute or relative path. If not supplied
6767 /// this defaults to whatever `winres` crate determines is the best. See the
6868 /// [winres documentation](https://docs.rs/winres/*/winres/struct.WindowsResource.html#method.set_toolkit_path)
6969 sdk_dir : Option < PathBuf > ,
7070}
7171
72- impl Default for WindowsAttributes {
73- fn default ( ) -> Self {
74- Self {
75- window_icon_path : PathBuf :: from ( "icons/icon.ico" ) ,
76- sdk_dir : None ,
77- }
78- }
79- }
80-
8172impl WindowsAttributes {
8273 /// Creates the default attribute set.
8374 pub fn new ( ) -> Self {
@@ -88,7 +79,9 @@ impl WindowsAttributes {
8879 /// It must be in `ico` format. Defaults to `icons/icon.ico`.
8980 #[ must_use]
9081 pub fn window_icon_path < P : AsRef < Path > > ( mut self , window_icon_path : P ) -> Self {
91- self . window_icon_path = window_icon_path. as_ref ( ) . into ( ) ;
82+ self
83+ . window_icon_path
84+ . replace ( window_icon_path. as_ref ( ) . into ( ) ) ;
9285 self
9386 }
9487
@@ -230,16 +223,16 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
230223 . parent ( )
231224 . unwrap ( ) ;
232225
233- if let Some ( paths) = config. tauri . bundle . external_bin {
226+ if let Some ( paths) = & config. tauri . bundle . external_bin {
234227 copy_binaries (
235- ResourcePaths :: new ( external_binaries ( & paths, & target_triple) . as_slice ( ) , true ) ,
228+ ResourcePaths :: new ( external_binaries ( paths, & target_triple) . as_slice ( ) , true ) ,
236229 & target_triple,
237230 target_dir,
238231 ) ?;
239232 }
240233
241234 #[ allow( unused_mut) ]
242- let mut resources = config. tauri . bundle . resources . unwrap_or_default ( ) ;
235+ let mut resources = config. tauri . bundle . resources . clone ( ) . unwrap_or_default ( ) ;
243236 #[ cfg( target_os = "linux" ) ]
244237 if let Some ( tray) = config. tauri . system_tray {
245238 resources. push ( tray. icon_path . display ( ) . to_string ( ) ) ;
@@ -259,13 +252,24 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
259252 use semver:: Version ;
260253 use winres:: { VersionInfo , WindowsResource } ;
261254
262- let icon_path_string = attributes
255+ fn find_icon < F : Fn ( & & String ) -> bool > ( config : & Config , predicate : F , default : & str ) -> PathBuf {
256+ let icon_path = config
257+ . tauri
258+ . bundle
259+ . icon
260+ . iter ( )
261+ . find ( |i| predicate ( i) )
262+ . cloned ( )
263+ . unwrap_or_else ( || default. to_string ( ) ) ;
264+ icon_path. into ( )
265+ }
266+
267+ let window_icon_path = attributes
263268 . windows_attributes
264269 . window_icon_path
265- . to_string_lossy ( )
266- . into_owned ( ) ;
270+ . unwrap_or_else ( || find_icon ( & config, |i| i. ends_with ( ".ico" ) , "icons/icon.ico" ) ) ;
267271
268- if attributes . windows_attributes . window_icon_path . exists ( ) {
272+ if window_icon_path. exists ( ) {
269273 let mut res = WindowsResource :: new ( ) ;
270274 if let Some ( sdk_dir) = & attributes. windows_attributes . sdk_dir {
271275 if let Some ( sdk_dir_str) = sdk_dir. to_str ( ) {
@@ -289,17 +293,17 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
289293 res. set ( "ProductName" , product_name) ;
290294 res. set ( "FileDescription" , product_name) ;
291295 }
292- res. set_icon_with_id ( & icon_path_string , "32512" ) ;
296+ res. set_icon_with_id ( & window_icon_path . display ( ) . to_string ( ) , "32512" ) ;
293297 res. compile ( ) . with_context ( || {
294298 format ! (
295299 "failed to compile `{}` into a Windows Resource file during tauri-build" ,
296- icon_path_string
300+ window_icon_path . display ( )
297301 )
298302 } ) ?;
299303 } else {
300304 return Err ( anyhow ! ( format!(
301305 "`{}` not found; required for generating a Windows Resource file during tauri-build" ,
302- icon_path_string
306+ window_icon_path . display ( )
303307 ) ) ) ;
304308 }
305309 }
0 commit comments