Skip to content

Commit

Permalink
feat(core): improve tray icon read error messages (#4850)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 3, 2022
1 parent fa23310 commit 52f0c8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changes/improve-tray-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-codegen": patch
---

Improve tray icon read error message.
12 changes: 6 additions & 6 deletions core/tauri-codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,14 @@ fn ico_icon<P: AsRef<Path>>(

let path = path.as_ref();
let bytes = std::fs::read(&path)
.unwrap_or_else(|_| panic!("failed to read icon {}", path.display()))
.unwrap_or_else(|e| panic!("failed to read icon {}: {}", path.display(), e))
.to_vec();
let icon_dir = ico::IconDir::read(std::io::Cursor::new(bytes))
.unwrap_or_else(|_| panic!("failed to parse icon {}", path.display()));
.unwrap_or_else(|e| panic!("failed to parse icon {}: {}", path.display(), e));
let entry = &icon_dir.entries()[0];
let rgba = entry
.decode()
.unwrap_or_else(|_| panic!("failed to decode icon {}", path.display()))
.unwrap_or_else(|e| panic!("failed to decode icon {}: {}", path.display(), e))
.rgba_data()
.to_vec();
let width = entry.width();
Expand Down Expand Up @@ -459,7 +459,7 @@ fn raw_icon<P: AsRef<Path>>(out_dir: &Path, path: P) -> Result<TokenStream, Embe

let path = path.as_ref();
let bytes = std::fs::read(&path)
.unwrap_or_else(|_| panic!("failed to read icon {}", path.display()))
.unwrap_or_else(|e| panic!("failed to read icon {}: {}", path.display(), e))
.to_vec();

let out_path = out_dir.join(path.file_name().unwrap());
Expand Down Expand Up @@ -491,12 +491,12 @@ fn png_icon<P: AsRef<Path>>(

let path = path.as_ref();
let bytes = std::fs::read(&path)
.unwrap_or_else(|_| panic!("failed to read icon {}", path.display()))
.unwrap_or_else(|e| panic!("failed to read icon {}: {}", path.display(), e))
.to_vec();
let decoder = png::Decoder::new(std::io::Cursor::new(bytes));
let mut reader = decoder
.read_info()
.unwrap_or_else(|_| panic!("failed to read icon {}", path.display()));
.unwrap_or_else(|e| panic!("failed to read icon {}: {}", path.display(), e));
let mut buffer: Vec<u8> = Vec::new();
while let Ok(Some(row)) = reader.next_row() {
buffer.extend(row.data());
Expand Down

0 comments on commit 52f0c8b

Please sign in to comment.