From ed460761ff6642b98d36e96261782806e5c42ae9 Mon Sep 17 00:00:00 2001 From: Smittix Date: Wed, 21 Jan 2026 15:50:03 +0000 Subject: [PATCH] Prioritize bleak over DBus for Flask compatibility DBus/BlueZ requires a GLib main loop which Flask doesn't have. Reordered backend priority: bleak > hcitool > bluetoothctl > dbus Removed DBus option from UI since it won't work with Flask. Co-Authored-By: Claude Opus 4.5 --- templates/partials/modes/bluetooth.html | 5 ++--- utils/bluetooth/capability_check.py | 18 +++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/templates/partials/modes/bluetooth.html b/templates/partials/modes/bluetooth.html index 583cde4..e9911ae 100644 --- a/templates/partials/modes/bluetooth.html +++ b/templates/partials/modes/bluetooth.html @@ -17,10 +17,9 @@
diff --git a/utils/bluetooth/capability_check.py b/utils/bluetooth/capability_check.py index 1a68497..3609dac 100644 --- a/utils/bluetooth/capability_check.py +++ b/utils/bluetooth/capability_check.py @@ -270,18 +270,15 @@ def _check_capabilities_permission(caps: SystemCapabilities) -> None: def _determine_recommended_backend(caps: SystemCapabilities) -> None: """Determine the recommended scanning backend.""" - # Prefer DBus/BlueZ if available and working - if caps.has_dbus and caps.has_bluez and caps.adapters: - if not caps.is_soft_blocked and not caps.is_hard_blocked: - caps.recommended_backend = 'dbus' - return + # NOTE: DBus/BlueZ requires a GLib main loop which Flask doesn't have. + # For Flask applications, we prefer bleak or subprocess-based tools. - # Fallback to bleak (cross-platform) + # Prefer bleak (cross-platform, works in Flask) if caps.has_bleak: caps.recommended_backend = 'bleak' return - # Fallback to hcitool (requires root) + # Fallback to hcitool (requires root on Linux) if caps.has_hcitool and caps.is_root: caps.recommended_backend = 'hcitool' return @@ -291,6 +288,13 @@ def _determine_recommended_backend(caps: SystemCapabilities) -> None: caps.recommended_backend = 'bluetoothctl' return + # DBus is last resort - won't work properly with Flask but keep as option + # for potential future use with a separate scanning daemon + if caps.has_dbus and caps.has_bluez and caps.adapters: + if not caps.is_soft_blocked and not caps.is_hard_blocked: + caps.recommended_backend = 'dbus' + return + caps.recommended_backend = 'none' if not caps.issues: caps.issues.append('No suitable Bluetooth scanning backend available')