qdot / systray-rs

Allows rust applications to show a platform specific system tray icon and menu.
BSD 3-Clause "New" or "Revised" License
170 stars 66 forks source link

How to use set_icon_from_buffer #24

Open shayne opened 6 years ago

shayne commented 6 years ago

Looking at the example we get a reference to systray::Application which doesn't have set_icon_from_buffer. I see it in mod.rs (on Windows here).

shayne commented 6 years ago

Also what encoding does the set_icon_from_buffer expect?

daniel-abramov commented 6 years ago

It's useful when you have an icon representation in memory and want to use it. May be useful in cases when the icon is embedded in the executable (so that you don't need to ship a separate icon file) or when you downloaded an icon from internet (or any other similar scenario).

I tried to use it with PNG and ICO files and it worked for me (in Windows and Mac OS).

nicolasbauw commented 4 years ago

I tried to use it with PNG and ICO files and it worked for me (in Windows and Mac OS).

Could you please give an example ? I've tried with include_bytes!, with 128*128 ICOs and PNGs, and I always obtain an "Error setting icon from buffer". I tried on Windows.

Ciantic commented 4 years ago

I also wonder how to do this, I tried with .ico file, but it doesn't work for me in Windows 10.

let mut systray = systray::Application::new().unwrap();
let icon = include_bytes!("./icon.ico");
systray.set_icon_from_buffer(icon, 64, 64).unwrap();
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: OsError("Cannot load icon from the buffer: 0")', src\main.rs:59:5
Ciantic commented 4 years ago

I found the bug, this should contain the length:

https://github.com/qdot/systray-rs/blob/cbddc6ebf78544584945628191bd56bf6ab731f8/src/api/win32/mod.rs#L421

PR here https://github.com/qdot/systray-rs/pull/45

Btw, if you use VSCode you can monkey patch the systray: Go to definition, then just writing over the file inside the .cargo registry cache. Then just cargo clean in your project.

qdot commented 4 years ago

I've got some libappindicator updates to bring in too, so I'll try to get this in and get a new release out in the next few days.