From 4ec083ecc7dd54a8339e15c65f42d9041f706bb8 Mon Sep 17 00:00:00 2001 From: reasje Date: Wed, 17 Jul 2024 08:21:00 +0330 Subject: [PATCH] fix: Data conversion JS bluetooth --- .../domain/blueberry_ring_use_case.dart | 15 +++++++++------ .../subfeatures/open_dapp/open_dapp_page.dart | 6 ++---- .../open_dapp/open_dapp_presenter.dart | 12 ++++++------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/features/common/packages/bluetooth/blueberry_ring/domain/blueberry_ring_use_case.dart b/lib/features/common/packages/bluetooth/blueberry_ring/domain/blueberry_ring_use_case.dart index b9091042..721697db 100644 --- a/lib/features/common/packages/bluetooth/blueberry_ring/domain/blueberry_ring_use_case.dart +++ b/lib/features/common/packages/bluetooth/blueberry_ring/domain/blueberry_ring_use_case.dart @@ -54,8 +54,8 @@ class BlueberryRingUseCase extends ReactiveUseCase { Future 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 { @@ -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(); @@ -132,7 +134,8 @@ class BlueberryRingUseCase extends ReactiveUseCase { final isBlueberryRingCharacteristicAvailable = blueberryRingCharacteristic.hasValue; - collectLog('checkEstablishment:isBlueberryRingCharacteristicAvailable $isBlueberryRingCharacteristicAvailable'); + collectLog( + 'checkEstablishment:isBlueberryRingCharacteristicAvailable $isBlueberryRingCharacteristicAvailable'); if (!isBlueberryRingCharacteristicAvailable) { await getBlueberryRingCharacteristic(); } diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart index 6572524b..e6ea06ca 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart @@ -180,8 +180,7 @@ class OpenAppPage extends HookConsumerWidget { allowsInlineMediaPlayback: true, ), ), - gestureRecognizers: < - Factory>{ + gestureRecognizers: >{ Factory( () => VerticalDragGestureRecognizer(), ), @@ -196,8 +195,7 @@ class OpenAppPage extends HookConsumerWidget { action: PermissionRequestResponseAction.GRANT, ); }, - androidOnGeolocationPermissionsHidePrompt: - (controller) {}, + androidOnGeolocationPermissionsHidePrompt: (controller) {}, androidOnGeolocationPermissionsShowPrompt: (InAppWebViewController controller, String origin) async { diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index 8762add6..28418532 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -846,7 +846,7 @@ class OpenDAppPresenter extends CompletePresenter { final selectedService = await getSelectedService(data['serviceUUID']); final selectedCharacteristic = getSelectedCharacteristic(data['this'], selectedService); - final value = Uint8List.fromList(List.from(data['value'])); + final value = Uint8List.fromList(List.from((data['value'] as Map).values.toList())); try { collectLog('handleWrites:value $value'); @@ -1125,7 +1125,11 @@ class OpenDAppPresenter extends CompletePresenter { 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!, @@ -1133,10 +1137,6 @@ class OpenDAppPresenter extends CompletePresenter { 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(