-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The tray menu does not appear in Windows 11 #221
Comments
Can you provide a full minimal reproduction? It's a bit hard to help without any code context. About the common-controls-v6 error, that's more or less expected. You will have to embedd a Manifest into your executable for this to work. |
I tried tao example. That doesn't work either. Here is the complete code use std::time::Duration;
use tokio::time::sleep;
use tray_icon::{
menu::{
AboutMetadata, Menu, MenuItem, PredefinedMenuItem
},
TrayIconBuilder,
};
async fn check_connection() -> Result<(), reqwest::Error>{
let res = reqwest::get("https://google.com").await;
match res {
Ok(_) => Ok(()),
Err(err) => Err(err)
}
}
fn load_icon(path: &std::path::Path) -> tray_icon::Icon {
let (icon_rgba, icon_width, icon_height) = {
let image = image::open(path)
.expect("Failed to open icon path")
.into_rgba8();
let (width, height) = image.dimensions();
let rgba = image.into_raw();
(rgba, width, height)
};
tray_icon::Icon::from_rgba(icon_rgba, icon_width, icon_height).expect("Failed to open icon")
}
#[tokio::main]
async fn main() {
let connected_icon_path = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/connected_icon.png");
let connected_icon = load_icon(std::path::Path::new(connected_icon_path));
let disconnected_icon_path = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/disconnected_icon.png");
let disconnected_icon = load_icon(std::path::Path::new(disconnected_icon_path));
let exit_item = MenuItem::new("Exit", true, None);
let menu = Menu::new();
let _ = menu.append_items(&[
&PredefinedMenuItem::about(
None,
Some(AboutMetadata {
name: Some("Mercury".to_string()),
..Default::default()
})
),
&PredefinedMenuItem::separator(),
&exit_item
]);
let tray_icon = TrayIconBuilder::new()
.with_menu(Box::new(menu))
.with_icon(connected_icon.clone())
.build()
.unwrap();
loop {
match check_connection().await {
Ok(_) => {
let _ = tray_icon.set_icon(Some(connected_icon.clone()));
}
Err(_err) => {
let _ = tray_icon.set_icon(Some(disconnected_icon.clone()));
}
}
sleep(Duration::from_secs(20)).await;
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Windows 11 20H2 build 22621.1702
Here is my code
Cargo.toml
main.rs
Nothing happens when I click the tray icon regardless of the mouse button
If I add the
common-controls-v6
feature, I get the error:The text was updated successfully, but these errors were encountered: