Skip to content

Commit

Permalink
Debian icon no fallback, fixes #4280 (#4282)
Browse files Browse the repository at this point in the history
  • Loading branch information
betamos committed Jun 9, 2022
1 parent 2c1353f commit a6f45d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 55 deletions.
7 changes: 7 additions & 0 deletions .changes/linux-icon-png-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-bundler": patch
---

Only png files from tauri.conf.json > tauri.bundle.icon are used for app icons for linux targets.
Previously, all sizes from all source files (10 files using tauricon defaults) were used.
This also prevents unexpectedly mixed icons in cases where platform-specific icons are used.
2 changes: 1 addition & 1 deletion tooling/bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ exclude = [

[dependencies]
tauri-utils = { version = "1.0.0-rc.8", path = "../../core/tauri-utils", features = [ "resources" ] }
icns = "0.3"
image = "0.24.2"
libflate = "1.2"
anyhow = "1.0"
Expand All @@ -50,6 +49,7 @@ glob = "0.3"
zip = "0.6"

[target."cfg(target_os = \"macos\")".dependencies]
icns = "0.3"
time = { version = "0.3", features = [ "formatting" ] }

[target."cfg(any(target_os = \"macos\", target_os = \"windows\"))".dependencies]
Expand Down
65 changes: 11 additions & 54 deletions tooling/bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use super::super::common;
use crate::Settings;
use anyhow::Context;
use heck::ToKebabCase;
use image::{self, codecs::png::PngDecoder, GenericImageView, ImageDecoder};
use image::{self, codecs::png::PngDecoder, ImageDecoder};
use libflate::gzip;
use log::info;
use walkdir::WalkDir;
Expand Down Expand Up @@ -281,71 +281,28 @@ fn generate_icon_files(settings: &Settings, data_dir: &Path) -> crate::Result<BT
))
};
let mut icons = BTreeSet::new();
// Prefer PNG files.
for icon_path in settings.icon_files() {
let icon_path = icon_path?;
if icon_path.extension() != Some(OsStr::new("png")) {
continue;
}
let decoder = PngDecoder::new(File::open(&icon_path)?)?;
let width = decoder.dimensions().0;
let height = decoder.dimensions().1;
let is_high_density = common::is_retina(&icon_path);
let dest_path = get_dest_path(width, height, is_high_density);
let deb_icon = DebIcon {
width,
height,
is_high_density,
path: dest_path,
};
if !icons.contains(&deb_icon) {
common::copy_file(&icon_path, &deb_icon.path)?;
icons.insert(deb_icon);
}
}
// Fall back to non-PNG files for any missing sizes.
for icon_path in settings.icon_files() {
let icon_path = icon_path?;
if icon_path.extension() == Some(OsStr::new("png")) {
continue;
} else if icon_path.extension() == Some(OsStr::new("icns")) {
let icon_family = icns::IconFamily::read(File::open(&icon_path)?)?;
for icon_type in icon_family.available_icons() {
let width = icon_type.screen_width();
let height = icon_type.screen_height();
let is_high_density = icon_type.pixel_density() > 1;
let dest_path = get_dest_path(width, height, is_high_density);
let deb_icon = DebIcon {
width,
height,
is_high_density,
path: dest_path,
};
if !icons.contains(&deb_icon) {
if let Ok(icon) = icon_family.get_icon_with_type(icon_type) {
icon.write_png(common::create_file(&deb_icon.path)?)?;
icons.insert(deb_icon);
}
}
}
} else {
let icon = image::open(&icon_path)?;
let (width, height) = icon.dimensions();
// Put file in scope so that it's closed when copying it
let deb_icon = {
let decoder = PngDecoder::new(File::open(&icon_path)?)?;
let width = decoder.dimensions().0;
let height = decoder.dimensions().1;
let is_high_density = common::is_retina(&icon_path);
let dest_path = get_dest_path(width, height, is_high_density);
let deb_icon = DebIcon {
DebIcon {
width,
height,
is_high_density,
path: dest_path,
};
if !icons.contains(&deb_icon) {
icon.write_to(
&mut common::create_file(&deb_icon.path)?,
image::ImageOutputFormat::Png,
)?;
icons.insert(deb_icon);
}
};
if !icons.contains(&deb_icon) {
common::copy_file(&icon_path, &deb_icon.path)?;
icons.insert(deb_icon);
}
}
Ok(icons)
Expand Down

0 comments on commit a6f45d5

Please sign in to comment.