Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added linux-rust/assets/animations/popup/frame_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_012.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_014.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_015.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_016.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_017.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_018.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_019.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_020.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_021.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_022.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_023.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_025.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-rust/assets/animations/popup/frame_027.png
Binary file added linux-rust/assets/animations/popup/frame_028.png
Binary file added linux-rust/assets/animations/popup/frame_029.png
Binary file added linux-rust/assets/animations/popup/frame_031.png
Binary file added linux-rust/assets/animations/popup/frame_032.png
Binary file added linux-rust/assets/animations/popup/frame_033.png
Binary file added linux-rust/assets/animations/popup/frame_034.png
Binary file added linux-rust/assets/animations/popup/frame_035.png
Binary file added linux-rust/assets/animations/popup/frame_036.png
Binary file added linux-rust/assets/animations/popup/frame_037.png
Binary file added linux-rust/assets/animations/popup/frame_039.png
Binary file added linux-rust/assets/animations/popup/frame_041.png
Binary file added linux-rust/assets/animations/popup/frame_042.png
Binary file added linux-rust/assets/animations/popup/frame_043.png
Binary file added linux-rust/assets/animations/popup/frame_044.png
Binary file added linux-rust/assets/animations/popup/frame_045.png
Binary file added linux-rust/assets/animations/popup/frame_046.png
Binary file added linux-rust/assets/animations/popup/frame_047.png
Binary file added linux-rust/assets/animations/popup/frame_049.png
Binary file added linux-rust/assets/animations/popup/frame_050.png
Binary file added linux-rust/assets/animations/popup/frame_051.png
Binary file added linux-rust/assets/animations/popup/frame_052.png
Binary file added linux-rust/assets/animations/popup/frame_054.png
Binary file added linux-rust/assets/animations/popup/frame_056.png
Binary file added linux-rust/assets/animations/popup/frame_057.png
Binary file added linux-rust/assets/animations/popup/frame_058.png
Binary file added linux-rust/assets/animations/popup/frame_059.png
Binary file added linux-rust/assets/animations/popup/frame_060.png
Binary file added linux-rust/assets/animations/popup/frame_061.png
Binary file added linux-rust/assets/animations/popup/frame_062.png
Binary file added linux-rust/assets/animations/popup/frame_063.png
Binary file added linux-rust/assets/animations/popup/frame_064.png
Binary file added linux-rust/assets/animations/popup/frame_065.png
Binary file added linux-rust/assets/animations/popup/frame_066.png
Binary file added linux-rust/assets/animations/popup/frame_067.png
Binary file added linux-rust/assets/animations/popup/frame_068.png
Binary file added linux-rust/assets/animations/popup/frame_069.png
Binary file added linux-rust/assets/animations/popup/frame_070.png
Binary file added linux-rust/assets/animations/popup/frame_071.png
Binary file added linux-rust/assets/animations/popup/frame_072.png
Binary file added linux-rust/assets/animations/popup/frame_073.png
Binary file added linux-rust/assets/animations/popup/frame_075.png
Binary file added linux-rust/assets/animations/popup/frame_076.png
Binary file added linux-rust/assets/animations/popup/frame_077.png
Binary file added linux-rust/assets/animations/popup/frame_080.png
Binary file added linux-rust/assets/animations/popup/frame_081.png
Binary file added linux-rust/assets/animations/popup/frame_082.png
Binary file added linux-rust/assets/animations/popup/frame_083.png
Binary file added linux-rust/assets/animations/popup/frame_084.png
Binary file added linux-rust/assets/animations/popup/frame_085.png
Binary file added linux-rust/assets/animations/popup/frame_086.png
Binary file added linux-rust/assets/animations/popup/frame_087.png
Binary file added linux-rust/assets/animations/popup/frame_089.png
Binary file added linux-rust/assets/animations/popup/frame_090.png
Binary file added linux-rust/assets/animations/popup/frame_091.png
Binary file added linux-rust/assets/animations/popup/frame_092.png
Binary file added linux-rust/assets/animations/popup/frame_093.png
Binary file added linux-rust/assets/animations/popup/frame_094.png
Binary file added linux-rust/assets/animations/popup/frame_095.png
Binary file added linux-rust/assets/animations/popup/frame_096.png
Binary file added linux-rust/assets/animations/popup/frame_097.png
Binary file added linux-rust/assets/animations/popup/frame_099.png
Binary file added linux-rust/assets/animations/popup/frame_100.png
Binary file added linux-rust/assets/animations/popup/frame_101.png
Binary file added linux-rust/assets/animations/popup/frame_102.png
Binary file added linux-rust/assets/animations/popup/frame_103.png
Binary file added linux-rust/assets/animations/popup/frame_104.png
Binary file added linux-rust/assets/animations/popup/frame_105.png
Binary file added linux-rust/assets/animations/popup/frame_106.png
Binary file added linux-rust/assets/animations/popup/frame_107.png
Binary file added linux-rust/assets/animations/popup/frame_108.png
Binary file added linux-rust/assets/animations/popup/frame_109.png
Binary file added linux-rust/assets/animations/popup/frame_110.png
Binary file added linux-rust/assets/animations/popup/frame_111.png
Binary file added linux-rust/assets/animations/popup/frame_113.png
Binary file added linux-rust/assets/animations/popup/frame_114.png
Binary file added linux-rust/assets/animations/popup/frame_115.png
Binary file added linux-rust/assets/animations/popup/frame_116.png
Binary file added linux-rust/assets/animations/popup/frame_117.png
Binary file added linux-rust/assets/animations/popup/frame_118.png
Binary file added linux-rust/assets/animations/popup/frame_119.png
Binary file added linux-rust/assets/animations/popup/frame_120.png
Binary file added linux-rust/assets/animations/popup/frame_121.png
Binary file added linux-rust/assets/animations/popup/frame_122.png
Binary file added linux-rust/assets/animations/popup/frame_123.png
Binary file added linux-rust/assets/animations/popup/frame_124.png
Binary file added linux-rust/assets/animations/popup/frame_125.png
Binary file added linux-rust/assets/animations/popup/frame_126.png
Binary file added linux-rust/assets/animations/popup/frame_127.png
Binary file added linux-rust/assets/animations/popup/frame_128.png
Binary file added linux-rust/assets/animations/popup/frame_129.png
Binary file added linux-rust/assets/animations/popup/frame_131.png
Binary file added linux-rust/assets/animations/popup/frame_132.png
Binary file added linux-rust/assets/animations/popup/frame_133.png
Binary file added linux-rust/assets/animations/popup/frame_134.png
Binary file added linux-rust/assets/animations/popup/frame_135.png
Binary file added linux-rust/assets/animations/popup/frame_136.png
Binary file added linux-rust/assets/animations/popup/frame_137.png
Binary file added linux-rust/assets/animations/popup/frame_138.png
Binary file added linux-rust/assets/animations/popup/frame_139.png
Binary file added linux-rust/assets/animations/popup/frame_140.png
Binary file added linux-rust/assets/animations/popup/frame_141.png
Binary file added linux-rust/assets/animations/popup/frame_142.png
Binary file added linux-rust/assets/animations/popup/frame_143.png
Binary file added linux-rust/assets/animations/popup/frame_144.png
Binary file added linux-rust/assets/animations/popup/frame_145.png
Binary file added linux-rust/assets/animations/popup/frame_146.png
Binary file added linux-rust/assets/animations/popup/frame_147.png
Binary file added linux-rust/assets/animations/popup/frame_148.png
Binary file added linux-rust/assets/animations/popup/frame_149.png
Binary file added linux-rust/assets/animations/popup/frame_151.png
Binary file added linux-rust/assets/animations/popup/frame_152.png
Binary file added linux-rust/assets/animations/popup/frame_153.png
Binary file added linux-rust/assets/animations/popup/frame_154.png
Binary file added linux-rust/assets/animations/popup/frame_155.png
Binary file added linux-rust/assets/animations/popup/frame_156.png
Binary file added linux-rust/assets/animations/popup/frame_157.png
Binary file added linux-rust/assets/animations/popup/frame_158.png
Binary file added linux-rust/assets/animations/popup/frame_160.png
Binary file added linux-rust/assets/animations/popup/frame_161.png
Binary file added linux-rust/assets/animations/popup/frame_162.png
Binary file added linux-rust/assets/animations/popup/frame_163.png
Binary file added linux-rust/assets/animations/popup/frame_164.png
Binary file added linux-rust/assets/animations/popup/frame_165.png
Binary file added linux-rust/assets/animations/popup/frame_167.png
Binary file added linux-rust/assets/animations/popup/frame_168.png
Binary file added linux-rust/assets/animations/popup/frame_170.png
Binary file added linux-rust/assets/animations/popup/frame_171.png
Binary file added linux-rust/assets/animations/popup/frame_172.png
Binary file added linux-rust/assets/animations/popup/frame_173.png
Binary file added linux-rust/assets/animations/popup/frame_174.png
Binary file added linux-rust/assets/animations/popup/frame_175.png
Binary file added linux-rust/assets/animations/popup/frame_176.png
Binary file added linux-rust/assets/animations/popup/frame_177.png
Binary file added linux-rust/assets/animations/popup/frame_178.png
Binary file added linux-rust/assets/animations/popup/frame_179.png
Binary file added linux-rust/assets/animations/popup/frame_180.png
21 changes: 17 additions & 4 deletions linux-rust/src/bluetooth/aacp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,13 @@ impl AACPManager {
}

pub async fn receive_packet(&self, packet: &[u8]) {
if !packet.starts_with(&HEADER_BYTES) {
if packet.len() < 5 {
return;
}

if !packet.starts_with(&[0x04, 0x00, 0x04, 0x00]) && !packet.starts_with(&[0x01, 0x00, 0x04, 0x00]) {
debug!(
"Received packet does not start with expected header: {}",
"Received packet with unknown header: {}",
hex::encode(packet)
);
return;
Expand All @@ -509,6 +513,7 @@ impl AACPManager {

let opcode = packet[4];
let payload = &packet[4..];
debug!("Processing packet opcode={:#04x} len={}", opcode, payload.len());

match opcode {
opcodes::BATTERY_INFO => {
Expand Down Expand Up @@ -633,6 +638,7 @@ impl AACPManager {
EarDetectionStatus::OutOfEar
}
});
debug!("Received Ear Detection: {:?}", statuses);
let mut state = self.state.lock().await;
state.old_ear_detection_status = state.ear_detection_status.clone();
state.ear_detection_status = statuses.clone();
Expand Down Expand Up @@ -917,7 +923,7 @@ impl AACPManager {
opcodes::EQ_DATA => {
debug!("Received EQ Data");
}
_ => debug!("Received unknown packet with opcode {:#04x}", opcode),
_ => debug!("Received packet with header {} opcode {:#04x}, payload: {}", hex::encode(&packet[..4]), opcode, hex::encode(payload)),
}
}

Expand All @@ -928,6 +934,13 @@ impl AACPManager {
self.send_data_packet(&packet).await
}

pub async fn send_battery_request(&self) -> Result<()> {
let opcode = [opcodes::BATTERY_INFO, 0x00];
let data = [0x00]; // Request current battery status
let packet = [opcode.as_slice(), data.as_slice()].concat();
self.send_data_packet(&packet).await
}

pub async fn send_set_feature_flags_packet(&self) -> Result<()> {
let opcode = [opcodes::SET_FEATURE_FLAGS, 0x00];
// let data = [0xD7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
Expand Down Expand Up @@ -1212,7 +1225,7 @@ async fn recv_thread(manager: AACPManager, sp: Arc<SeqPacket>) {
}
Ok(n) => {
let data = &buf[..n];
debug!("Received {} bytes: {}", n, hex::encode(data));
debug!("Received raw {} bytes: {}", n, hex::encode(data));
manager.receive_packet(data).await;
}
Err(e) => {
Expand Down
73 changes: 71 additions & 2 deletions linux-rust/src/bluetooth/le.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use serde_json;
use std::collections::{HashMap, HashSet};
use std::str::FromStr;
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::Mutex;

fn decrypt(key: &[u8; 16], data: &[u8; 16]) -> [u8; 16] {
Expand Down Expand Up @@ -46,12 +47,12 @@ fn verify_rpa(addr: &str, irk: &[u8; 16]) -> bool {
hash == computed_hash
}

pub async fn start_le_monitor(tray_handle: Option<ksni::Handle<MyTray>>) -> bluer::Result<()> {
pub async fn start_le_monitor(tray_handle: Option<ksni::Handle<MyTray>>, ui_tx: tokio::sync::mpsc::UnboundedSender<crate::ui::messages::BluetoothUIMessage>) -> bluer::Result<()> {
let session = Session::new().await?;
let adapter = session.default_adapter().await?;
adapter.set_powered(true).await?;

let all_devices: HashMap<String, DeviceData> = std::fs::read_to_string(get_devices_path())
let mut all_devices: HashMap<String, DeviceData> = std::fs::read_to_string(get_devices_path())
.ok()
.and_then(|s| serde_json::from_str(&s).ok())
.unwrap_or_default();
Expand Down Expand Up @@ -122,6 +123,52 @@ pub async fn start_le_monitor(tray_handle: Option<ksni::Handle<MyTray>>) -> blue
}
}

if found_mac.is_none() {
// Try reloading devices once to see if keys were recently added
let devices_json = std::fs::read_to_string(get_devices_path()).unwrap_or_else(|_| "{}".to_string());
all_devices = serde_json::from_str(&devices_json).unwrap_or_default();

for (mac, info) in &all_devices {
if let Some(DeviceInformation::AirPods(airpods_info)) = &info.information {
if !airpods_info.le_keys.irk.is_empty() {
let irk_bytes = hex::decode(&airpods_info.le_keys.irk).unwrap_or_default();
if irk_bytes.len() == 16 {
let mut irk = [0u8; 16];
irk.copy_from_slice(&irk_bytes);
if verify_rpa(&addr.to_string(), &irk) {
info!("LE Monitor matched AirPods (cached): {} (MAC: {})", mac, addr);
found_mac = Some(mac.clone());
break;
}
}
}
}
}
}

if found_mac.is_none() {
// Try reloading devices once to see if keys were recently added
let devices_json = std::fs::read_to_string(get_devices_path()).unwrap_or_else(|_| "{}".to_string());
all_devices = serde_json::from_str(&devices_json).unwrap_or_default();

for (mac, info) in &all_devices {
if let Some(DeviceInformation::AirPods(airpods_info)) = &info.information {
if !airpods_info.le_keys.irk.is_empty() {
let irk_bytes = hex::decode(&airpods_info.le_keys.irk).unwrap_or_default();
if irk_bytes.len() == 16 {
let mut irk = [0u8; 16];
irk.copy_from_slice(&irk_bytes);
if verify_rpa(&addr.to_string(), &irk) {
info!("LE Monitor matched AirPods: {} (MAC: {})", mac, addr);
found_mac = Some(mac.clone());
break;
}
}
}
}
}
}

if let Some(mac) = found_mac {
matched_airpods_mac = Some(mac);
} else {
Expand All @@ -144,7 +191,9 @@ pub async fn start_le_monitor(tray_handle: Option<ksni::Handle<MyTray>>) -> blue
let mut events = dev.events().await?;
let tray_handle_clone = tray_handle.clone();
let connecting_macs_clone = Arc::clone(&connecting_macs);
let ui_tx_clone = ui_tx.clone();
tokio::spawn(async move {
let mut last_popup_sent: Option<Instant> = None;
while let Some(ev) = events.next().await {
match ev {
bluer::DeviceEvent::PropertyChanged(prop) => {
Expand Down Expand Up @@ -336,6 +385,26 @@ pub async fn start_le_monitor(tray_handle: Option<ksni::Handle<MyTray>>) -> blue
.await;
}

let now = Instant::now();
let is_throttled = last_popup_sent.map(|t| now.duration_since(t) < Duration::from_secs(10)).unwrap_or(false);

if case_byte != 0xff && !is_throttled {
info!("Sending ShowPopup message to UI for {}", matched_airpods_mac.as_ref().unwrap());
let _ = ui_tx_clone.send(crate::ui::messages::BluetoothUIMessage::ShowPopup {
mac: matched_airpods_mac.as_ref().unwrap().clone(),
battery_l: if left_byte == 0xff { None } else { Some(left_battery as u8) },
battery_r: if right_byte == 0xff { None } else { Some(right_battery as u8) },
battery_c: if case_byte == 0xff { None } else { Some(case_battery as u8) },
charging_l: left_charging,
charging_r: right_charging,
charging_c: case_charging,
});
last_popup_sent = Some(now);
} else if case_byte != 0xff {
debug!("Throttling ShowPopup message for {}", matched_airpods_mac.as_ref().unwrap());
}


debug!(
"Battery status: Left: {}, Right: {}, Case: {}, InEar: L:{} R:{}",
if left_byte == 0xff {
Expand Down
23 changes: 17 additions & 6 deletions linux-rust/src/devices/airpods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ impl AirPodsDevice {
let mut aacp_manager = AACPManager::new();
aacp_manager.connect(mac_address).await;

// let mut att_manager = ATTManager::new();
// att_manager.connect(mac_address).await.expect("Failed to connect ATT");
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
let (command_tx, mut command_rx) = tokio::sync::mpsc::unbounded_channel();
aacp_manager.set_event_channel(tx).await;

if let Some(handle) = &tray_handle {
handle
Expand Down Expand Up @@ -81,6 +82,20 @@ impl AirPodsDevice {
error!("Failed to request proximity keys: {}", e);
}

sleep(Duration::from_millis(300)).await;

// Claim ownership so AirPods send us BatteryInfo and EarDetection events
info!("Claiming ownership of AirPods connection");
if let Err(e) = aacp_manager
.send_control_command(
crate::bluetooth::aacp::ControlCommandIdentifiers::OwnsConnection,
&[0x01],
)
.await
{
error!("Failed to claim ownership: {}", e);
}

let app_settings_path = get_app_settings_path();
let settings = std::fs::read_to_string(&app_settings_path)
.ok()
Expand Down Expand Up @@ -123,10 +138,6 @@ impl AirPodsDevice {
local_mac.clone(),
)));
let mc_clone = media_controller.clone();
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
let (command_tx, mut command_rx) = tokio::sync::mpsc::unbounded_channel();

aacp_manager.set_event_channel(tx).await;
if let Some(handle) = &tray_handle {
handle
.update(|tray: &mut MyTray| tray.command_tx = Some(command_tx.clone()))
Expand Down
49 changes: 49 additions & 0 deletions linux-rust/src/devices/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,58 @@ pub struct AirPodsState {
pub conversation_awareness_enabled: bool,
pub personalized_volume_enabled: bool,
pub allow_off_mode: bool,
pub auto_anc_strength: u8,
pub battery: Vec<BatteryInfo>,
}

impl AirPodsState {
pub fn update_battery(&mut self, battery_info: &[BatteryInfo]) {
for b in battery_info {
if let Some(existing) = self.battery.iter_mut().find(|e| e.component == b.component) {
*existing = b.clone();
} else {
self.battery.push(b.clone());
}
}
}

pub fn is_case_open(&self) -> bool {
// Case component is 0x08. Status 4 means Disconnected (Case Closed/Off)
self.battery.iter().any(|b| b.component as u8 == 0x08 && b.status as u8 != 4)
}

pub fn get_battery_levels(&self) -> (Option<u8>, Option<u8>, Option<u8>) {
let mut l = None;
let mut r = None;
let mut c = None;
for b in &self.battery {
match b.component as u8 {
0x04 => l = Some(b.level),
0x02 => r = Some(b.level),
0x08 => c = Some(b.level),
_ => {}
}
}
(l, r, c)
}

pub fn get_charging_statuses(&self) -> (bool, bool, bool) {
let mut l = false;
let mut r = false;
let mut c = false;
for b in &self.battery {
let is_charging = b.status as u8 == 1;
match b.component as u8 {
0x04 => l = is_charging,
0x02 => r = is_charging,
0x08 => c = is_charging,
_ => {}
}
}
(l, r, c)
}
}

#[derive(Clone, Debug)]
pub enum AirPodsNoiseControlMode {
Off,
Expand Down
2 changes: 1 addition & 1 deletion linux-rust/src/devices/nothing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct NothingDevice {
impl NothingDevice {
pub async fn new(
mac_address: Address,
ui_tx: mpsc::UnboundedSender<BluetoothUIMessage>,
_ui_tx: mpsc::UnboundedSender<BluetoothUIMessage>,
) -> Self {
let mut att_manager = ATTManager::new();
att_manager
Expand Down
8 changes: 4 additions & 4 deletions linux-rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::bluetooth::managers::DeviceManagers;
use crate::devices::enums::DeviceData;
use crate::ui::messages::BluetoothUIMessage;
use crate::ui::tray::MyTray;
use crate::utils::{get_app_settings_path, get_devices_path};
use crate::utils::{get_devices_path};
use bluer::{Address, InternalErrorKind};
use clap::Parser;
use dbus::arg::{RefArg, Variant};
Expand All @@ -19,10 +19,9 @@ use dbus::blocking::stdintf::org_freedesktop_dbus::Properties;
use dbus::message::MatchRule;
use devices::airpods::AirPodsDevice;
use ksni::TrayMethods;
use log::{debug, info, warn};
use log::{info, warn};
use std::collections::HashMap;
use std::env;
use std::sync::atomic::{AtomicBool};
use std::sync::Arc;
use tokio::sync::RwLock;
use tokio::sync::mpsc::unbounded_channel;
Expand Down Expand Up @@ -154,9 +153,10 @@ async fn async_main(
adapter.set_powered(true).await?;

let le_tray_clone = tray_handle.clone();
let le_ui_tx = ui_tx.clone();
tokio::spawn(async move {
info!("Starting LE monitor...");
if let Err(e) = start_le_monitor(le_tray_clone).await {
if let Err(e) = start_le_monitor(le_tray_clone, le_ui_tx).await {
log::error!("LE monitor error: {}", e);
}
});
Expand Down
4 changes: 2 additions & 2 deletions linux-rust/src/media_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ impl MediaController {
.ear_detection_status
.contains(&EarDetectionStatus::InEar)
{
info!("Media playback started but buds not in ear, skipping takeover");
continue;
info!("Media playback started but buds not in ear, skipping takeover (BYPASSED)");
// continue;
}
info!("Media playback started, taking ownership and activating a2dp");
let _ = control_tx.send((
Expand Down
Loading