-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move tauri to V2 & BLEA behind feature
Signed-off-by: Martichou <[email protected]>
- Loading branch information
Showing
19 changed files
with
5,376 additions
and
1,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::sync::Arc; | ||
|
||
use bluer::adv::{Advertisement, Feature, SecondaryChannel}; | ||
use bytes::Bytes; | ||
use tokio_util::sync::CancellationToken; | ||
use uuid::uuid; | ||
use uuid::Uuid; | ||
|
||
const SERVICE_UUID_SHARING: Uuid = uuid!("0000fe2c-0000-1000-8000-00805f9b34fb"); | ||
const SERVICE_DATA: Bytes = Bytes::from_static(&[ | ||
252, 18, 142, 1, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]); | ||
|
||
const INNER_NAME: &str = "BleAdvertiser"; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct BleAdvertiser { | ||
adapter: Arc<bluer::Adapter>, | ||
} | ||
|
||
impl BleAdvertiser { | ||
pub async fn new() -> Result<Self, anyhow::Error> { | ||
let session = bluer::Session::new().await?; | ||
let adapter = session.default_adapter().await?; | ||
adapter.set_powered(true).await?; | ||
|
||
Ok(Self { | ||
adapter: Arc::new(adapter), | ||
}) | ||
} | ||
|
||
pub async fn run(&self, ctk: CancellationToken) -> Result<(), anyhow::Error> { | ||
debug!( | ||
"{INNER_NAME}: advertising on Bluetooth adapter {} with address {}", | ||
self.adapter.name(), | ||
self.adapter.address().await? | ||
); | ||
|
||
let handle = self | ||
.adapter | ||
.advertise(self.get_advertisment(SERVICE_UUID_SHARING, SERVICE_DATA)) | ||
.await?; | ||
ctk.cancelled().await; | ||
info!("{INNER_NAME}: tracker cancelled, returning"); | ||
drop(handle); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn get_advertisment(&self, service_uuid: Uuid, adv_data: Bytes) -> Advertisement { | ||
Advertisement { | ||
advertisement_type: bluer::adv::Type::Broadcast, | ||
service_uuids: vec![service_uuid].into_iter().collect(), | ||
service_data: [(service_uuid, adv_data.into())].into(), | ||
secondary_channel: Some(SecondaryChannel::OneM), | ||
system_includes: [Feature::TxPower].into(), | ||
tx_power: Some(20), | ||
..Default::default() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.