mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-04-28 09:07:14 +00:00
linux-rust: optimize for size and add cli options
This commit is contained in:
2950
linux-rust/Cargo.lock
generated
2950
linux-rust/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -11,9 +11,20 @@ uuid = "1.18.1"
|
|||||||
log = "0.4.28"
|
log = "0.4.28"
|
||||||
dbus = "0.9.9"
|
dbus = "0.9.9"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
iced = {version = "0.13.1", features = ["tokio", "auto-detect-theme"]}
|
# iced = {version = "0.13.1", features = ["tokio", "auto-detect-theme"]}
|
||||||
libpulse-binding = "2.30.1"
|
libpulse-binding = "2.30.1"
|
||||||
ksni = "0.3.1"
|
ksni = "0.3.1"
|
||||||
image = "0.25.8"
|
image = "0.25.8"
|
||||||
imageproc = "0.25.0"
|
imageproc = "0.25.0"
|
||||||
ab_glyph = "0.2.32"
|
ab_glyph = "0.2.32"
|
||||||
|
clap = { version = "4.5.50", features = ["derive"] }
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = "s"
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
|
[profile.release-stripped]
|
||||||
|
inherits = "release"
|
||||||
|
strip = true
|
||||||
@@ -18,7 +18,7 @@ pub struct AirPodsDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AirPodsDevice {
|
impl AirPodsDevice {
|
||||||
pub async fn new(mac_address: Address, tray_handle: Handle<MyTray>) -> Self {
|
pub async fn new(mac_address: Address, tray_handle: Option<Handle<MyTray>>) -> Self {
|
||||||
info!("Creating new AirPodsDevice for {}", mac_address);
|
info!("Creating new AirPodsDevice for {}", mac_address);
|
||||||
let mut aacp_manager = AACPManager::new();
|
let mut aacp_manager = AACPManager::new();
|
||||||
aacp_manager.connect(mac_address).await;
|
aacp_manager.connect(mac_address).await;
|
||||||
@@ -26,7 +26,9 @@ impl AirPodsDevice {
|
|||||||
// let mut att_manager = ATTManager::new();
|
// let mut att_manager = ATTManager::new();
|
||||||
// att_manager.connect(mac_address).await.expect("Failed to connect ATT");
|
// att_manager.connect(mac_address).await.expect("Failed to connect ATT");
|
||||||
|
|
||||||
tray_handle.update(|tray: &mut MyTray| tray.connected = true).await;
|
if let Some(handle) = &tray_handle {
|
||||||
|
handle.update(|tray: &mut MyTray| tray.connected = true).await;
|
||||||
|
}
|
||||||
|
|
||||||
info!("Sending handshake");
|
info!("Sending handshake");
|
||||||
aacp_manager.send_handshake().await.expect(
|
aacp_manager.send_handshake().await.expect(
|
||||||
@@ -69,7 +71,9 @@ impl AirPodsDevice {
|
|||||||
let (command_tx, mut command_rx) = tokio::sync::mpsc::unbounded_channel();
|
let (command_tx, mut command_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
|
|
||||||
aacp_manager.set_event_channel(tx).await;
|
aacp_manager.set_event_channel(tx).await;
|
||||||
tray_handle.update(|tray: &mut MyTray| tray.command_tx = Some(command_tx.clone())).await;
|
if let Some(handle) = &tray_handle {
|
||||||
|
handle.update(|tray: &mut MyTray| tray.command_tx = Some(command_tx.clone())).await;
|
||||||
|
}
|
||||||
|
|
||||||
let aacp_manager_clone = aacp_manager.clone();
|
let aacp_manager_clone = aacp_manager.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
@@ -90,10 +94,12 @@ impl AirPodsDevice {
|
|||||||
let tray_handle_clone = tray_handle.clone();
|
let tray_handle_clone = tray_handle.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(value) = listening_mode_rx.recv().await {
|
while let Some(value) = listening_mode_rx.recv().await {
|
||||||
tray_handle_clone.update(|tray: &mut MyTray| {
|
if let Some(handle) = &tray_handle_clone {
|
||||||
|
handle.update(|tray: &mut MyTray| {
|
||||||
tray.listening_mode = Some(value[0]);
|
tray.listening_mode = Some(value[0]);
|
||||||
}).await;
|
}).await;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let (allow_off_tx, mut allow_off_rx) = tokio::sync::mpsc::unbounded_channel();
|
let (allow_off_tx, mut allow_off_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
@@ -101,10 +107,12 @@ impl AirPodsDevice {
|
|||||||
let tray_handle_clone = tray_handle.clone();
|
let tray_handle_clone = tray_handle.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(value) = allow_off_rx.recv().await {
|
while let Some(value) = allow_off_rx.recv().await {
|
||||||
tray_handle_clone.update(|tray: &mut MyTray| {
|
if let Some(handle) = &tray_handle_clone {
|
||||||
|
handle.update(|tray: &mut MyTray| {
|
||||||
tray.allow_off_option = Some(value[0]);
|
tray.allow_off_option = Some(value[0]);
|
||||||
}).await;
|
}).await;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let (conversation_detect_tx, mut conversation_detect_rx) = tokio::sync::mpsc::unbounded_channel();
|
let (conversation_detect_tx, mut conversation_detect_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
@@ -112,10 +120,12 @@ impl AirPodsDevice {
|
|||||||
let tray_handle_clone = tray_handle.clone();
|
let tray_handle_clone = tray_handle.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(value) = conversation_detect_rx.recv().await {
|
while let Some(value) = conversation_detect_rx.recv().await {
|
||||||
tray_handle_clone.update(|tray: &mut MyTray| {
|
if let Some(handle) = &tray_handle_clone {
|
||||||
|
handle.update(|tray: &mut MyTray| {
|
||||||
tray.conversation_detect_enabled = Some(value[0] == 0x01);
|
tray.conversation_detect_enabled = Some(value[0] == 0x01);
|
||||||
}).await;
|
}).await;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let (owns_connection_tx, mut owns_connection_rx) = tokio::sync::mpsc::unbounded_channel();
|
let (owns_connection_tx, mut owns_connection_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
@@ -146,7 +156,8 @@ impl AirPodsDevice {
|
|||||||
}
|
}
|
||||||
AACPEvent::BatteryInfo(battery_info) => {
|
AACPEvent::BatteryInfo(battery_info) => {
|
||||||
debug!("Received BatteryInfo event: {:?}", battery_info);
|
debug!("Received BatteryInfo event: {:?}", battery_info);
|
||||||
tray_handle.update(|tray: &mut MyTray| {
|
if let Some(handle) = &tray_handle {
|
||||||
|
handle.update(|tray: &mut MyTray| {
|
||||||
for b in &battery_info {
|
for b in &battery_info {
|
||||||
match b.component as u8 {
|
match b.component as u8 {
|
||||||
0x02 => {
|
0x02 => {
|
||||||
@@ -165,6 +176,7 @@ impl AirPodsDevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).await;
|
}).await;
|
||||||
|
}
|
||||||
debug!("Updated tray with new battery info");
|
debug!("Updated tray with new battery info");
|
||||||
}
|
}
|
||||||
AACPEvent::ControlCommand(status) => {
|
AACPEvent::ControlCommand(status) => {
|
||||||
|
|||||||
@@ -15,16 +15,28 @@ use crate::airpods::AirPodsDevice;
|
|||||||
use bluer::Address;
|
use bluer::Address;
|
||||||
use ksni::TrayMethods;
|
use ksni::TrayMethods;
|
||||||
use crate::ui::tray::MyTray;
|
use crate::ui::tray::MyTray;
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
struct Args {
|
||||||
|
#[arg(long)]
|
||||||
|
debug: bool,
|
||||||
|
#[arg(long)]
|
||||||
|
no_tray: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> bluer::Result<()> {
|
async fn main() -> bluer::Result<()> {
|
||||||
|
let args = Args::parse();
|
||||||
|
let log_level = if args.debug { "debug" } else { "info" };
|
||||||
if env::var("RUST_LOG").is_err() {
|
if env::var("RUST_LOG").is_err() {
|
||||||
unsafe { env::set_var("RUST_LOG", "debug"); }
|
unsafe { env::set_var("RUST_LOG", log_level); }
|
||||||
}
|
}
|
||||||
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
|
let tray_handle = if args.no_tray {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
let tray = MyTray {
|
let tray = MyTray {
|
||||||
conversation_detect_enabled: None,
|
conversation_detect_enabled: None,
|
||||||
battery_l: None,
|
battery_l: None,
|
||||||
@@ -39,6 +51,8 @@ async fn main() -> bluer::Result<()> {
|
|||||||
command_tx: None,
|
command_tx: None,
|
||||||
};
|
};
|
||||||
let handle = tray.spawn().await.unwrap();
|
let handle = tray.spawn().await.unwrap();
|
||||||
|
Some(handle)
|
||||||
|
};
|
||||||
|
|
||||||
let session = bluer::Session::new().await?;
|
let session = bluer::Session::new().await?;
|
||||||
let adapter = session.default_adapter().await?;
|
let adapter = session.default_adapter().await?;
|
||||||
@@ -51,7 +65,7 @@ async fn main() -> bluer::Result<()> {
|
|||||||
Ok(device) => {
|
Ok(device) => {
|
||||||
let name = device.name().await?.unwrap_or_else(|| "Unknown".to_string());
|
let name = device.name().await?.unwrap_or_else(|| "Unknown".to_string());
|
||||||
info!("Found connected AirPods: {}, initializing.", name);
|
info!("Found connected AirPods: {}, initializing.", name);
|
||||||
let _airpods_device = AirPodsDevice::new(device.address(), handle.clone()).await;
|
let _airpods_device = AirPodsDevice::new(device.address(), tray_handle.clone()).await;
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
info!("No connected AirPods found.");
|
info!("No connected AirPods found.");
|
||||||
@@ -87,7 +101,7 @@ async fn main() -> bluer::Result<()> {
|
|||||||
let Ok(addr_str) = proxy.get::<String>("org.bluez.Device1", "Address") else { return true; };
|
let Ok(addr_str) = proxy.get::<String>("org.bluez.Device1", "Address") else { return true; };
|
||||||
let Ok(addr) = addr_str.parse::<Address>() else { return true; };
|
let Ok(addr) = addr_str.parse::<Address>() else { return true; };
|
||||||
info!("AirPods connected: {}, initializing", name);
|
info!("AirPods connected: {}, initializing", name);
|
||||||
let handle_clone = handle.clone();
|
let handle_clone = tray_handle.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let _airpods_device = AirPodsDevice::new(addr, handle_clone).await;
|
let _airpods_device = AirPodsDevice::new(addr, handle_clone).await;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user