Browse Source

Debian icon no fallback, fixes #4280 (#4282)

Didrik Nordström 3 years ago
parent
commit
a6f45d5248

+ 7 - 0
.changes/linux-icon-png-only.md

@@ -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.

+ 1 - 1
tooling/bundler/Cargo.toml

@@ -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"
@@ -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]

+ 11 - 54
tooling/bundler/src/bundle/linux/debian.rs

@@ -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;
@@ -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)