feat(core): improve tray icon read error messages (#4850)

This commit is contained in:
Lucas Fernandes Nogueira 2022-08-03 11:38:43 -03:00 committed by GitHub
parent fa23310f23
commit 52f0c8bb83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
"tauri-codegen": patch
---
Improve tray icon read error message.

View File

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