Skip to content

Commit

Permalink
feat: move tauri to V2 & BLEA behind feature
Browse files Browse the repository at this point in the history
Signed-off-by: Martichou <[email protected]>
  • Loading branch information
Martichou committed Feb 29, 2024
1 parent 5b7882f commit 1187b44
Show file tree
Hide file tree
Showing 19 changed files with 5,376 additions and 1,110 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
cd ./core_lib
cargo build
build-tauri:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Install Linux dependencies
run: |
sudo apt-get update
sudo apt-get install -y libdbus-1-dev libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
sudo apt-get install -y libjavascriptcoregtk-4.1-dev libdbus-1-dev libgtk-4-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Build Vite + Tauri
run: |
cd ./frontend
Expand All @@ -54,4 +54,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: Debian Bundle
path: ${{ github.workspace }}/frontend/src-tauri/target/release/bundle/deb/r-quick-share_*_amd64.deb
path: ${{ github.workspace }}/frontend/src-tauri/target/release/bundle/deb/r-quick-share_*_amd64.*
2 changes: 1 addition & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install Linux dependencies
if: matrix.directory == './frontend/src-tauri'
run: |
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
sudo apt-get install -y libjavascriptcoregtk-4.1-dev libdbus-1-dev libgtk-4-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Clippy Check
run: |
cd ${{ matrix.directory }}
Expand Down
6 changes: 5 additions & 1 deletion core_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ path = "src/bin.rs"
[dependencies]
anyhow = "1.0"
base64 = "0.21"
bluer = { version = "0.17.0", features = ["full"] }
bluer = { version = "0.17.0", features = ["full"], optional = true }
btleplug = "0.11.5"
bytes = "1.5.0"
directories = "5.0"
Expand Down Expand Up @@ -40,3 +40,7 @@ uuid = "1.7.0"

[build-dependencies]
prost-build = "0.12"

[features]
default = []
experimental = ["bluer"]
53 changes: 0 additions & 53 deletions core_lib/src/hdl/ble.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
use std::sync::Arc;
use std::time::{Duration, SystemTime};

use anyhow::anyhow;
use bluer::adv::{Advertisement, Feature, SecondaryChannel};
use btleplug::api::{Central, CentralEvent, Manager as _, ScanFilter};
use btleplug::platform::{Adapter, Manager};
use bytes::Bytes;
use futures::stream::StreamExt;
use tokio::sync::broadcast::Sender;
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 = "BleListener";

Expand Down Expand Up @@ -86,50 +80,3 @@ impl BleListener {
Ok(())
}
}

#[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!(
"BleAdvertiser: 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!("BleAdvertiser: 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()
}
}
}
61 changes: 61 additions & 0 deletions core_lib/src/hdl/blea.rs
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()
}
}
}
4 changes: 4 additions & 0 deletions core_lib/src/hdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use crate::utils::RemoteDeviceInfo;

mod ble;
pub use ble::*;
#[cfg(feature = "experimental")]
mod blea;
#[cfg(feature = "experimental")]
pub use blea::*;
mod inbound;
pub use inbound::*;
pub(crate) mod info;
Expand Down
4 changes: 3 additions & 1 deletion core_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extern crate log;

use channel::ChannelMessage;
#[cfg(feature = "experimental")]
use hdl::BleAdvertiser;
use mdns_sd::{ServiceDaemon, ServiceEvent};
use rand::{distributions, Rng};
Expand All @@ -23,7 +24,7 @@ mod hdl;
mod manager;
mod utils;

pub use hdl::OutboundPayload;
pub use hdl::{OutboundPayload, State};
pub use manager::SendInfo;
pub use utils::DeviceType;

Expand Down Expand Up @@ -131,6 +132,7 @@ impl RQS {
let discovery = MDnsDiscovery::new(sender)?;
self.tracker.spawn(async move { discovery.run(ctk).await });

#[cfg(feature = "experimental")]
self.tracker.spawn(async move {
let blea = match BleAdvertiser::new().await {
Ok(b) => b,
Expand Down
7 changes: 4 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
},
"dependencies": {
"@martichou/core_lib": "../core_lib",
"@tauri-apps/api": "1.5.1",
"tauri-plugin-autostart-api": "github:tauri-apps/tauri-plugin-autostart#v1",
"@tauri-apps/api": "2.0.0-beta.3",
"@tauri-apps/plugin-autostart": "2.0.0-beta.1",
"@tauri-apps/plugin-notification": "2.0.0-beta.1",
"vue": "3.3.11"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^1.6.2",
"@tailwindcss/typography": "^0.5.10",
"@tauri-apps/cli": "1.5.7",
"@tauri-apps/cli": "2.0.0-beta.6",
"@types/node": "20.10.4",
"@vitejs/plugin-vue": "4.5.2",
"@vue/devtools": "6.5.1",
Expand Down
Loading

0 comments on commit 1187b44

Please sign in to comment.