Bluetooth check, avoid crashing

This commit is contained in:
2026-10-14 07:24:06 +08:00
parent 1ec485701a
commit b22b0df6ed
6 changed files with 118 additions and 9 deletions
+8
View File
@@ -6,6 +6,10 @@ namespace TuneBoss.Core.BLE;
/// <summary>
/// Represents a discovered BLE device before connection.
/// </summary>
/// <summary>Result of a Bluetooth-adapter check: whether BLE is ready to scan, and a
/// human-readable reason when it isn't (no adapter / no BLE support / radio off).</summary>
public readonly record struct BluetoothAvailability(bool IsReady, string Message);
public sealed record BleDeviceInfo(
ulong Address,
string Name,
@@ -69,6 +73,10 @@ public interface IBleService : IDisposable
// ── Scanning ─────────────────────────────────────────────────────────────
/// <summary>Whether a Bluetooth adapter is present and its radio is on. Call this
/// before scanning so a radio that's off gives a friendly message instead of a crash.</summary>
Task<BluetoothAvailability> CheckBluetoothAsync();
/// <summary>Starts BLE advertisement scanning. Emits discovered devices.</summary>
IObservable<BleDeviceInfo> StartScan();