🐛 fix(bluetooth): use rfkill as fallback to enable/disable bluetooth

This commit is contained in:
sankalp committed 2025-08-16 13:38:47 +05:45
1 parent 73f3839d85
commit 75a87f9134
1 file changed
+16 -11
+16 -11
View File
@@ -2,7 +2,7 @@ import subprocess
import gi import gi
from fabric.bluetooth import BluetoothClient, BluetoothDevice from fabric.bluetooth import BluetoothClient, BluetoothDevice
from fabric.utils import exec_shell_command, get_relative_path from fabric.utils import get_relative_path, exec_shell_command
from fabric.widgets.box import Box from fabric.widgets.box import Box
from fabric.widgets.button import Button from fabric.widgets.button import Button
from fabric.widgets.centerbox import CenterBox from fabric.widgets.centerbox import CenterBox
@@ -12,10 +12,9 @@ from fabric.widgets.revealer import Revealer
from fabric.widgets.scrolledwindow import ScrolledWindow from fabric.widgets.scrolledwindow import ScrolledWindow
from fabric.widgets.separator import Separator from fabric.widgets.separator import Separator
from fabric.widgets.svg import Svg from fabric.widgets.svg import Svg
from gi.repository import Gdk, GLib, Gtk from gi.repository import Gdk, Gtk, GLib
from loguru import logger
from services.battery import Battery from services.battery import Battery
from loguru import logger
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0") gi.require_version("Gdk", "3.0")
@@ -28,14 +27,20 @@ def set_bluetooth_enabled_with_fallback(client, enabled: bool):
except Exception as e: except Exception as e:
logger.warning(f"Fabric bluetooth set_enabled({enabled}) failed: {e}") logger.warning(f"Fabric bluetooth set_enabled({enabled}) failed: {e}")
# Fallback to bluetoothctl using exec_shell_command # Fallback to rfkill to unblock/block bluetooth
power_state = "on" if enabled else "off" if enabled:
command = f"bluetoothctl power {power_state}" command = "rfkill unblock bluetooth"
else:
command = "rfkill block bluetooth"
try: result = exec_shell_command(command)
exec_shell_command(command) if result is False:
except Exception as fallback_e: logger.error(f"rfkill fallback failed: command '{command}' returned False")
logger.error(f"bluetoothctl fallback failed: {fallback_e}") elif isinstance(result, str) and result.strip():
# If result is a non-empty string, it might be an error message
logger.warning(f"rfkill command output: {result.strip()}")
else:
logger.info(f"rfkill fallback succeeded: {command}")
class BluetoothDeviceSlot(CenterBox): class BluetoothDeviceSlot(CenterBox):