From 0387633582ba46ddb3a3d5c74d1fd3083b49782e Mon Sep 17 00:00:00 2001 From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:31:56 -0700 Subject: [PATCH] Merged `bluetooth_scanner` into `ble_scanner` --- package.cordovabuild.json | 2 +- setup/android_sdk_packages | 1 - www/js/bluetooth/BluetoothCard.tsx | 4 ++-- www/js/bluetooth/BluetoothScanPage.tsx | 23 +++++-------------- ...blueoothScanner.ts => bluetoothScanner.ts} | 11 ++++----- 5 files changed, 14 insertions(+), 27 deletions(-) rename www/js/bluetooth/{blueoothScanner.ts => bluetoothScanner.ts} (92%) diff --git a/package.cordovabuild.json b/package.cordovabuild.json index a3c4a191e..c3f7ec8d3 100644 --- a/package.cordovabuild.json +++ b/package.cordovabuild.json @@ -121,7 +121,7 @@ "cordova-plugin-app-version": "0.1.14", "cordova-plugin-customurlscheme": "5.0.2", "cordova-plugin-device": "2.1.0", - "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.8.2", + "cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.8.3", "cordova-plugin-em-opcodeauth": "git+https://github.com/e-mission/cordova-jwt-auth.git#v1.7.2", "cordova-plugin-em-server-communication": "git+https://github.com/e-mission/cordova-server-communication.git#v1.2.6", "cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.2", diff --git a/setup/android_sdk_packages b/setup/android_sdk_packages index a62d6b18a..a870852f1 100644 --- a/setup/android_sdk_packages +++ b/setup/android_sdk_packages @@ -4,7 +4,6 @@ build-tools;33.0.2 build-tools;34.0.0 emulator extras;google;google_play_services -patcher;v4 platform-tools platforms;android-30 platforms;android-31 diff --git a/www/js/bluetooth/BluetoothCard.tsx b/www/js/bluetooth/BluetoothCard.tsx index bd7450b45..a8c2a4e08 100644 --- a/www/js/bluetooth/BluetoothCard.tsx +++ b/www/js/bluetooth/BluetoothCard.tsx @@ -3,14 +3,14 @@ import { Card, List } from 'react-native-paper'; import { StyleSheet } from 'react-native'; type Props = any; -const BluetoothCard = (device: Props) => { +const BluetoothCard = ({ device }: Props) => { return ( } + left={() => } /> ); diff --git a/www/js/bluetooth/BluetoothScanPage.tsx b/www/js/bluetooth/BluetoothScanPage.tsx index 311652c94..8f0b62dbf 100644 --- a/www/js/bluetooth/BluetoothScanPage.tsx +++ b/www/js/bluetooth/BluetoothScanPage.tsx @@ -1,9 +1,8 @@ import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { StyleSheet, Modal, ScrollView, SafeAreaView, View, Text } from 'react-native'; -import { gatherBluetoothData, startBLEScanning } from './blueoothScanner'; +import { StyleSheet, Modal, ScrollView, SafeAreaView, View } from 'react-native'; +import { gatherBluetoothData, startBLEScanning } from './bluetoothScanner'; import { logWarn, displayError, displayErrorMsg } from '../plugin/logger'; -import { getConfig } from '../config/dynamicConfig'; import BluetoothCard from './BluetoothCard'; import { Appbar, useTheme, Button } from 'react-native-paper'; @@ -25,28 +24,18 @@ const BluetoothScanPage = ({ ...props }: any) => { // Function to run Bluetooth Classic test and update logs const runBluetoothClassicTest = async () => { - let permissionFunction; - // Depending on user platform, handle requesting the permissions differently - if (window['cordova'].platformId == 'android') { - permissionFunction = window['cordova'].plugins.BEMDataCollection.bluetoothScanPermissions(); - } else { - permissionFunction = window['bluetoothClassicSerial'].initializeBluetooth(); - } - if (!permissionFunction) { - displayErrorMsg('PlatformID Not Found', 'OSError'); + // Classic not currently supported on iOS + if (window['cordova'].platformId == 'ios') { + displayErrorMsg('Sorry, iOS is not supported!', 'OSError'); return; } try { - const response = await permissionFunction(); + let response = await window['cordova'].plugins.BEMDataCollection.bluetoothScanPermissions(); if (response != 'OK') { displayErrorMsg('Please Enable Bluetooth!', 'Insufficient Permissions'); return; } - if (window['cordova'].platformId == 'ios') { - displayErrorMsg('Sorry, iOS is not supported!', 'OSError'); - return; - } } catch (e) { displayError(e, 'Insufficient Permissions'); return; diff --git a/www/js/bluetooth/blueoothScanner.ts b/www/js/bluetooth/bluetoothScanner.ts similarity index 92% rename from www/js/bluetooth/blueoothScanner.ts rename to www/js/bluetooth/bluetoothScanner.ts index 82ca96f5f..d3a6cebc0 100644 --- a/www/js/bluetooth/blueoothScanner.ts +++ b/www/js/bluetooth/bluetoothScanner.ts @@ -27,19 +27,18 @@ export function gatherBluetoothData(t): Promise { logDebug('Running bluetooth discovery test!'); // Device List "I/O" - function handleLogs(pairingType: Boolean, devices: Array) { - let logs: string[] = []; + function updatePairingStatus(pairingType: boolean, devices: Array) { devices.forEach((device) => { - device.is_paired; + device.is_paired = pairingType; }); - return logs; + return devices; } // Plugin Calls const unpairedDevicesPromise = new Promise((res, rej) => { window['bluetoothClassicSerial'].discoverUnpaired( (devices: Array) => { - res(handleLogs(false, devices)); + res(updatePairingStatus(false, devices)); }, (e: Error) => { displayError(e, 'Error'); @@ -51,7 +50,7 @@ export function gatherBluetoothData(t): Promise { const pairedDevicesPromise = new Promise((res, rej) => { window['bluetoothClassicSerial'].list( (devices: Array) => { - res(handleLogs(true, devices)); + res(updatePairingStatus(true, devices)); }, (e: Error) => { displayError(e, 'Error');