diff --git a/www/i18n/en.json b/www/i18n/en.json index 4aec6165d..ac4c87469 100644 --- a/www/i18n/en.json +++ b/www/i18n/en.json @@ -234,6 +234,7 @@ "bluetooth": { "scan-debug-title": "Bluetooth Scanner", "scan-for-bluetooth": "Scan for Devices", + "is-scanning": "Scanning...", "device-info": { "id": "ID", "name": "Name" diff --git a/www/js/bluetooth/BluetoothScanPage.tsx b/www/js/bluetooth/BluetoothScanPage.tsx index a5dc1188d..777aaa95d 100644 --- a/www/js/bluetooth/BluetoothScanPage.tsx +++ b/www/js/bluetooth/BluetoothScanPage.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { StyleSheet, Modal, ScrollView, SafeAreaView, View } from 'react-native'; import gatherBluetoothData from './blueoothScanner'; @@ -16,6 +16,7 @@ import { Appbar, useTheme, Button } from 'react-native-paper'; const BluetoothScanPage = ({ ...props }: any) => { const { t } = useTranslation(); const [logs, setLogs] = useState([]); + const [isScanning, setIsScanning] = useState(false); const { colors } = useTheme(); // Function to run Bluetooth test and update logs @@ -29,6 +30,20 @@ const BluetoothScanPage = ({ ...props }: any) => { } }; + useEffect(() => { + let intervalId; + if (isScanning) { + intervalId = setInterval(runBluetoothTest, 5000); + } else { + clearInterval(intervalId); + } + return () => clearInterval(intervalId); + }, [isScanning]); + + const handleToggle = () => { + setIsScanning(!isScanning); + }; + const BlueScanContent = (
{ - diff --git a/www/js/control/BluetoothScanSettingRow.tsx b/www/js/control/BluetoothScanSettingRow.tsx index efbae279a..5af6ff25f 100644 --- a/www/js/control/BluetoothScanSettingRow.tsx +++ b/www/js/control/BluetoothScanSettingRow.tsx @@ -12,9 +12,9 @@ const BluetoothScanSettingRow = ({}) => { // Check and prompt for bluetooth scan permission try { let response = await window['cordova'].plugins.BEMDataCollection.bluetoothScanPermissions(); - if (response == "OK") setBluePageVisible(true) + if (response == 'OK') setBluePageVisible(true); } catch (e) { - displayError(e, "Insufficient Permissions"); + displayError(e, 'Insufficient Permissions'); } }