Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
fix: Data conversion JS bluetooth
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Jul 17, 2024
1 parent 8342466 commit 4ec083e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class BlueberryRingUseCase extends ReactiveUseCase {
Future<void> getBlueberryRingBackground() async {
// if (bluetoothStatus.value == BluetoothAdapterState.off || bluetoothStatus.value = BluetoothAdapterState.unauthorized)
_bluetoothUseCase.startScanning(
// withServices: [bluetoothServiceUUID],
withNames: ['Mi Smart Band 4']
withServices: [bluetoothServiceUUID],
// withNames: ['Mi Smart Band 4'],
);

await Future.delayed(const Duration(seconds: 2), () async {
Expand Down Expand Up @@ -111,15 +111,17 @@ class BlueberryRingUseCase extends ReactiveUseCase {
collectLog('checkEstablishment');

final isBlueberryRingAvailable = selectedBlueberryRing.hasValue;
collectLog('checkEstablishment:isBlueberryRingAvailable $isBlueberryRingAvailable');

collectLog(
'checkEstablishment:isBlueberryRingAvailable $isBlueberryRingAvailable');

if (!isBlueberryRingAvailable) {
await getBlueberryRingBackground();
}

bool isBlueberryRingConnected =
selectedBlueberryRing.value?.device.isConnected ?? false;
collectLog('checkEstablishment:isBlueberryRingConnected $isBlueberryRingConnected');
collectLog(
'checkEstablishment:isBlueberryRingConnected $isBlueberryRingConnected');

if (!isBlueberryRingConnected) {
await selectedBlueberryRing.value?.device.connect();
Expand All @@ -132,7 +134,8 @@ class BlueberryRingUseCase extends ReactiveUseCase {

final isBlueberryRingCharacteristicAvailable =
blueberryRingCharacteristic.hasValue;
collectLog('checkEstablishment:isBlueberryRingCharacteristicAvailable $isBlueberryRingCharacteristicAvailable');
collectLog(
'checkEstablishment:isBlueberryRingCharacteristicAvailable $isBlueberryRingCharacteristicAvailable');
if (!isBlueberryRingCharacteristicAvailable) {
await getBlueberryRingCharacteristic();
}
Expand Down
6 changes: 2 additions & 4 deletions lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ class OpenAppPage extends HookConsumerWidget {
allowsInlineMediaPlayback: true,
),
),
gestureRecognizers: <
Factory<OneSequenceGestureRecognizer>>{
gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer(),
),
Expand All @@ -196,8 +195,7 @@ class OpenAppPage extends HookConsumerWidget {
action: PermissionRequestResponseAction.GRANT,
);
},
androidOnGeolocationPermissionsHidePrompt:
(controller) {},
androidOnGeolocationPermissionsHidePrompt: (controller) {},
androidOnGeolocationPermissionsShowPrompt:
(InAppWebViewController controller,
String origin) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
final selectedService = await getSelectedService(data['serviceUUID']);
final selectedCharacteristic =
getSelectedCharacteristic(data['this'], selectedService);
final value = Uint8List.fromList(List<int>.from(data['value']));
final value = Uint8List.fromList(List<int>.from((data['value'] as Map<String, dynamic>).values.toList()));

try {
collectLog('handleWrites:value $value');
Expand Down Expand Up @@ -1125,18 +1125,18 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
loading = false;
BluetoothDevice? responseDevice;
final scanResults = _bluetoothUseCase.scanResults.value;
if (scanResults.length > 1 || scanResults.isEmpty) {
if (scanResults.length == 1) {
// only one scan results
final scanResult = scanResults.first;
state.selectedScanResult = scanResult;
} else {
// We need to let the user to choose If two or more devices of rings are available and even If empty maybe let the user to wait
final scanResult = await showBlueberryRingsBottomSheet(
context!,
);
if (scanResult != null) {
state.selectedScanResult = scanResult;
}
} else {
// only one scan results
final scanResult = scanResults.first;
state.selectedScanResult = scanResult;
}
if (state.selectedScanResult != null) {
responseDevice = BluetoothDevice.getBluetoothDeviceFromScanResult(
Expand Down

0 comments on commit 4ec083e

Please sign in to comment.