Skip to content

Commit

Permalink
modif self.icons and config.icon call
Browse files Browse the repository at this point in the history
  • Loading branch information
wiiznokes committed Dec 13, 2023
1 parent 77fde10 commit 0d8c91a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
10 changes: 4 additions & 6 deletions crates/packager/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1659,15 +1659,12 @@ impl Config {
let Some(patterns) = &self.icons else {
return Ok(None);
};

let mut paths = Vec::new();

for pattern in patterns {
for icon_path in glob::glob(pattern)? {
paths.push(icon_path?);
}
}

Ok(Some(paths))
}
}
Expand Down Expand Up @@ -1754,8 +1751,8 @@ impl Config {
}

#[allow(unused)]
pub(crate) fn find_ico(&self) -> Option<PathBuf> {
self.icons
pub(crate) fn find_ico(&self) -> crate::Result<Option<PathBuf>> {
let icon = self.icons()?
.as_ref()
.and_then(|icons| {
icons
Expand All @@ -1767,7 +1764,8 @@ impl Config {
})
})
})
.map(PathBuf::from)
.map(PathBuf::from);
Ok(icon)
}

#[allow(unused)]
Expand Down
2 changes: 1 addition & 1 deletion crates/packager/src/package/wix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ fn build_wix_app_installer(ctx: &Context, wix_path: &Path) -> crate::Result<Vec<
data.insert("app_exe_source", to_json(&main_binary_path));

// copy icon from `settings.windows().icon_path` folder to resource folder near msi
if let Some(icon) = config.find_ico() {
if let Some(icon) = config.find_ico()? {
let icon_path = dunce::canonicalize(icon)?;
data.insert("icon_path", to_json(icon_path));
}
Expand Down
11 changes: 5 additions & 6 deletions crates/packager/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,15 @@ pub(crate) fn is_retina<P: AsRef<Path>>(path: P) -> bool {
pub fn create_icns_file(out_dir: &Path, config: &crate::Config) -> crate::Result<Option<PathBuf>> {
use image::GenericImageView;

if config.icons.as_ref().map(|i| i.len()).unwrap_or_default() == 0 {
let icons = config.icons()?;
if icons.as_ref().map(|i| i.len()).unwrap_or_default() == 0 {
return Ok(None);
}

// If one of the icon files is already an ICNS file, just use that.
if let Some(icons) = &config.icons {
if let Some(icons) = icons {
std::fs::create_dir_all(out_dir)?;

for icon_path in icons {
let icon_path = PathBuf::from(icon_path);
if icon_path.extension() == Some(std::ffi::OsStr::new("icns")) {
let dest_path = out_dir.join(
icon_path
Expand Down Expand Up @@ -330,8 +329,8 @@ pub fn create_icns_file(out_dir: &Path, config: &crate::Config) -> crate::Result
}

let mut images_to_resize: Vec<(image::DynamicImage, u32, u32)> = vec![];
if let Some(icons) = &config.icons {
for icon_path in icons {
if let Some(icons) = config.icons()? {
for icon_path in &icons {
let icon = image::open(icon_path)?;
let density = if is_retina(icon_path) { 2 } else { 1 };
let (w, h) = icon.dimensions();
Expand Down

0 comments on commit 0d8c91a

Please sign in to comment.