linux-rust: add tray icon

This commit is contained in:
Kavish Devar
2025-11-10 13:32:47 +05:30
parent 43bfbda21e
commit cf2a242d7c
7 changed files with 1186 additions and 22 deletions
+23 -3
View File
@@ -1,6 +1,7 @@
mod bluetooth;
mod airpods;
mod media_controller;
mod ui;
use std::env;
use log::{debug, info};
@@ -12,6 +13,8 @@ use std::collections::HashMap;
use crate::bluetooth::discovery::find_connected_airpods;
use crate::airpods::AirPodsDevice;
use bluer::Address;
use ksni::TrayMethods;
use crate::ui::tray::MyTray;
#[tokio::main]
async fn main() -> bluer::Result<()> {
@@ -21,6 +24,22 @@ async fn main() -> bluer::Result<()> {
env_logger::init();
let tray = MyTray {
conversation_detect_enabled: None,
battery_l: None,
battery_l_status: None,
battery_r: None,
battery_r_status: None,
battery_c: None,
battery_c_status: None,
connected: false,
listening_mode: None,
allow_off_option: None,
command_tx: None,
};
let handle = tray.spawn().await.unwrap();
let session = bluer::Session::new().await?;
let adapter = session.default_adapter().await?;
adapter.set_powered(true).await?;
@@ -32,7 +51,7 @@ async fn main() -> bluer::Result<()> {
Ok(device) => {
let name = device.name().await?.unwrap_or_else(|| "Unknown".to_string());
info!("Found connected AirPods: {}, initializing.", name);
let _airpods_device = AirPodsDevice::new(device.address()).await;
let _airpods_device = AirPodsDevice::new(device.address(), handle.clone()).await;
}
Err(_) => {
info!("No connected AirPods found.");
@@ -41,7 +60,7 @@ async fn main() -> bluer::Result<()> {
let conn = Connection::new_system()?;
let rule = MatchRule::new_signal("org.freedesktop.DBus.Properties", "PropertiesChanged");
conn.add_match(rule, |_: (), conn, msg| {
conn.add_match(rule, move |_: (), conn, msg| {
let Some(path) = msg.path() else { return true; };
if !path.contains("/org/bluez/hci") || !path.contains("/dev_") {
return true;
@@ -68,8 +87,9 @@ async fn main() -> bluer::Result<()> {
let Ok(addr_str) = proxy.get::<String>("org.bluez.Device1", "Address") else { return true; };
let Ok(addr) = addr_str.parse::<Address>() else { return true; };
info!("AirPods connected: {}, initializing", name);
let handle_clone = handle.clone();
tokio::spawn(async move {
let _airpods_device = AirPodsDevice::new(addr).await;
let _airpods_device = AirPodsDevice::new(addr, handle_clone).await;
});
true
})?;