Skip to content

Commit 7f17359

Browse files
authored
Merge pull request #73 from josepdecid/main
fix: check bluetooth enabled before accessing to avoid crash
2 parents 54ea537 + 499e2f1 commit 7f17359

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/MiScaleExporter.MAUI/Resources/Localization/AppSnippets.pl.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@
318318
<data name="PermissionLocationRequired" xml:space="preserve">
319319
<value>Do skanowania wymagane jest pozwolenie na korzystanie z funkcji Lokalizacji (Bluetooth).</value>
320320
</data>
321+
<data name="BluetoothDisabled" xml:space="preserve">
322+
<value>Bluetooth jest wyłączony. Włącz Bluetooth, aby skanować wagę Mi Scale.</value>
323+
</data>
321324
<data name="Problem" xml:space="preserve">
322325
<value>Problem</value>
323326
</data>

src/MiScaleExporter.MAUI/Resources/Localization/AppSnippets.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@
318318
<data name="PermissionLocationRequired" xml:space="preserve">
319319
<value>Permission to use Location (Bluetooth) is required to scan.</value>
320320
</data>
321+
<data name="BluetoothDisabled" xml:space="preserve">
322+
<value>Bluetooth is disabled. Please enable Bluetooth to scan for your Mi Scale.</value>
323+
</data>
321324
<data name="Problem" xml:space="preserve">
322325
<value>Problem</value>
323326
</data>

src/MiScaleExporter.MAUI/ViewModels/ScaleViewModel.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using MiScaleExporter.Services;
33
using MiScaleExporter.Permission;
44
using MiScaleExporter.MAUI.Resources.Localization;
5+
using Plugin.BLE;
6+
using Plugin.BLE.Abstractions;
57

68
namespace MiScaleExporter.MAUI.ViewModels
79
{
@@ -100,6 +102,16 @@ await Application.Current.MainPage.DisplayAlert(AppSnippets.Problem, AppSnippets
100102

101103
}
102104

105+
// Check if Bluetooth is enabled
106+
if (CrossBluetoothLE.Current.State != BluetoothState.On)
107+
{
108+
await Application.Current.MainPage.DisplayAlert(
109+
AppSnippets.Problem,
110+
AppSnippets.BluetoothDisabled,
111+
AppSnippets.OK);
112+
return false;
113+
}
114+
103115
return true;
104116

105117
}

0 commit comments

Comments
 (0)