linux-rust: optimize for size and add cli options
This commit is contained in:
+32
-18
@@ -15,30 +15,44 @@ use crate::airpods::AirPodsDevice;
|
||||
use bluer::Address;
|
||||
use ksni::TrayMethods;
|
||||
use crate::ui::tray::MyTray;
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
#[arg(long)]
|
||||
debug: bool,
|
||||
#[arg(long)]
|
||||
no_tray: bool,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
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() {
|
||||
unsafe { env::set_var("RUST_LOG", "debug"); }
|
||||
unsafe { env::set_var("RUST_LOG", log_level); }
|
||||
}
|
||||
|
||||
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 tray_handle = if args.no_tray {
|
||||
None
|
||||
} else {
|
||||
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();
|
||||
Some(handle)
|
||||
};
|
||||
let handle = tray.spawn().await.unwrap();
|
||||
|
||||
let session = bluer::Session::new().await?;
|
||||
let adapter = session.default_adapter().await?;
|
||||
@@ -51,7 +65,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(), handle.clone()).await;
|
||||
let _airpods_device = AirPodsDevice::new(device.address(), tray_handle.clone()).await;
|
||||
}
|
||||
Err(_) => {
|
||||
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) = addr_str.parse::<Address>() else { return true; };
|
||||
info!("AirPods connected: {}, initializing", name);
|
||||
let handle_clone = handle.clone();
|
||||
let handle_clone = tray_handle.clone();
|
||||
tokio::spawn(async move {
|
||||
let _airpods_device = AirPodsDevice::new(addr, handle_clone).await;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user