Skip to content

Commit

Permalink
fix: update types and add eslint step for the generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
gmallios committed Mar 17, 2024
1 parent 88eedc3 commit f982797
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
7 changes: 4 additions & 3 deletions manager-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"version": "0.1.0",
"type": "module",
"scripts": {
"lint": "eslint ./manager-ui",
"lint:fix": "eslint --fix ./manager-ui",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"lint:fix-types": "eslint --fix ./src/types/*",
"format": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"tauri": "tauri",
"gen-types": "yarn typeshare:tauri && yarn typeshare:soundcore-lib",
"gen-types": "yarn typeshare:tauri && yarn typeshare:soundcore-lib && yarn lint:fix-types",
"typeshare:soundcore-lib": "typeshare ../soundcore-lib --lang=typescript --output-file=./src/types/soundcore-lib.d.ts",
"typeshare:tauri": "typeshare ../manager-app --lang=typescript --output-file=./src/types/tauri-backend.d.ts"
},
Expand Down
27 changes: 27 additions & 0 deletions manager-ui/src/types/soundcore-lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,30 @@ export interface DeviceStatus {
left_hearid_customdata: EQWave;
right_hearid_customdata: EQWave;
}

export type BLEAdapterEvent =
| { kind: 'deviceConnected'; value: BluetoothAdrr }
| { kind: 'deviceDisconnected'; value: BluetoothAdrr };

export enum SoundcoreFeatureFlags {
SOUND_MODE = 'SOUND_MODE',
ANC_MODE = 'ANC_MODE',
TRANS_MODE = 'TRANS_MODE',
CUSTOM_ANC = 'CUSTOM_ANC',
EQ = 'EQ',
STEREO_EQ = 'STEREO_EQ',
DRC = 'DRC',
HEARID = 'HEARID',
WEAR_DETECTION = 'WEAR_DETECTION',
CUSTOM_BUTTONS = 'CUSTOM_BUTTONS',
TOUCH_TONE = 'TOUCH_TONE',
GAME_MODE = 'GAME_MODE',
AUTO_POWER_OFF_ON = 'AUTO_POWER_OFF_ON',
InEarBeep = 'IN_EAR_BEEP',
PromptLang = 'PROMPT_LANG',
HearingProtect = 'HEARING_PROTECT',
AmbientSoundNotice = 'AMBIENT_SOUND_NOTICE',
PowerOnBatteryNotice = 'POWER_ON_BATTERY_NOTICE',
SupportTwoCnn = 'SUPPORT_TWO_CNN',
MultipleDeviceList = 'MULTIPLE_DEVICE_LIST'
}
1 change: 1 addition & 0 deletions manager-ui/src/types/tauri-backend.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ export type BridgeResponse =
| { kind: 'connectionEstablished'; payload: BluetoothAdrr }
| { kind: 'newState'; payload: NewStateResponse }
| { kind: 'disconnected'; payload: BluetoothAdrr }
| { kind: 'adapterEvent'; payload: BLEAdapterEvent }
| { kind: 'error'; payload: string };
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dev": "yarn workspace manager-ui dev",
"build": "yarn workspace manager-ui build",
"lint": "yarn workspace manager-ui lint",
"lint:fix": "yarn workspace manager-ui lint:fix",
"format": "yarn workspace manager-ui format",
"tauri": "tauri",
"gen-types": "yarn workspace manager-ui gen-types"
Expand Down
33 changes: 21 additions & 12 deletions soundcore-lib/src/ble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::time::Duration;

use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;

use crate::btaddr::BluetoothAdrr;
use crate::error::SoundcoreLibResult;
Expand Down Expand Up @@ -30,8 +31,19 @@ pub trait BLEConnectionManager {
descriptor: BLEDeviceDescriptor,
uuid_set: Option<BLEConnectionUuidSet>,
) -> SoundcoreLibResult<Arc<Self::Connection>>;

async fn adapter_events(&self) -> SoundcoreLibResult<tokio::sync::mpsc::Receiver<BLEAdapterEvent>>;
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase", tag = "kind", content = "value")]
#[typeshare]
pub enum BLEAdapterEvent {
DeviceConnected(BluetoothAdrr),
DeviceDisconnected(BluetoothAdrr),
}


#[async_trait]
pub trait BLEConnection {
fn descriptor(&self) -> BLEDeviceDescriptor;
Expand Down Expand Up @@ -63,6 +75,7 @@ pub trait DeviceDescriptor {
}

#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[typeshare]
pub struct BLEDeviceDescriptor {
pub addr: BluetoothAdrr,
pub name: String,
Expand Down Expand Up @@ -92,6 +105,14 @@ pub enum WriteType {
WithoutResponse,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct BLEConnectionUuidSet {
pub service_uuid: uuid::Uuid,
pub read_uuid: uuid::Uuid,
pub write_uuid: uuid::Uuid,
}


#[cfg(all(target_os = "windows", feature = "winrt-backend"))]
impl From<WriteType> for ::windows::Devices::Bluetooth::GenericAttributeProfile::GattWriteOption {
fn from(val: WriteType) -> Self {
Expand All @@ -102,16 +123,4 @@ impl From<WriteType> for ::windows::Devices::Bluetooth::GenericAttributeProfile:
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct BLEConnectionUuidSet {
pub service_uuid: uuid::Uuid,
pub read_uuid: uuid::Uuid,
pub write_uuid: uuid::Uuid,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum ConnectionEvent {
Connected(String),
Disconnected(String),
DataReceived(Vec<u8>),
}
3 changes: 3 additions & 0 deletions soundcore-lib/src/models/feature_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
use enumflags2::bitflags;
use serde::{Deserialize, Serialize};
use strum::EnumIter;
use typeshare::typeshare;

#[derive(
Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, EnumIter,
)]
#[bitflags]
#[repr(u32)]
#[typeshare]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum SoundcoreFeatureFlags {
SOUND_MODE,
ANC_MODE,
Expand Down

0 comments on commit f982797

Please sign in to comment.