From 6c96bf5c47a5eaa4f5aae909c5a08419581267e9 Mon Sep 17 00:00:00 2001 From: Gregory Mallios Date: Sun, 17 Mar 2024 17:50:52 +0200 Subject: [PATCH] fix: update types and add eslint step for the generated files --- manager-ui/package.json | 7 ++--- manager-ui/src/types/soundcore-lib.d.ts | 27 +++++++++++++++++++ manager-ui/src/types/tauri-backend.d.ts | 1 + package.json | 1 + soundcore-lib/src/ble.rs | 33 ++++++++++++++--------- soundcore-lib/src/models/feature_flags.rs | 3 +++ 6 files changed, 57 insertions(+), 15 deletions(-) diff --git a/manager-ui/package.json b/manager-ui/package.json index 7af7cf1..7c1a0f7 100644 --- a/manager-ui/package.json +++ b/manager-ui/package.json @@ -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" }, diff --git a/manager-ui/src/types/soundcore-lib.d.ts b/manager-ui/src/types/soundcore-lib.d.ts index 0c2a33d..97049cf 100644 --- a/manager-ui/src/types/soundcore-lib.d.ts +++ b/manager-ui/src/types/soundcore-lib.d.ts @@ -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' +} diff --git a/manager-ui/src/types/tauri-backend.d.ts b/manager-ui/src/types/tauri-backend.d.ts index 9b149f5..29fb588 100644 --- a/manager-ui/src/types/tauri-backend.d.ts +++ b/manager-ui/src/types/tauri-backend.d.ts @@ -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 }; diff --git a/package.json b/package.json index 01cfd6d..2a1df5e 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/soundcore-lib/src/ble.rs b/soundcore-lib/src/ble.rs index dbc3df4..4636438 100644 --- a/soundcore-lib/src/ble.rs +++ b/soundcore-lib/src/ble.rs @@ -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; @@ -30,8 +31,19 @@ pub trait BLEConnectionManager { descriptor: BLEDeviceDescriptor, uuid_set: Option, ) -> SoundcoreLibResult>; + + async fn adapter_events(&self) -> SoundcoreLibResult>; +} + +#[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; @@ -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, @@ -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 for ::windows::Devices::Bluetooth::GenericAttributeProfile::GattWriteOption { fn from(val: WriteType) -> Self { @@ -102,16 +123,4 @@ impl From 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), -} diff --git a/soundcore-lib/src/models/feature_flags.rs b/soundcore-lib/src/models/feature_flags.rs index 9795efa..176c388 100644 --- a/soundcore-lib/src/models/feature_flags.rs +++ b/soundcore-lib/src/models/feature_flags.rs @@ -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,