diff --git a/blueman/gui/applet/PluginDialog.py b/blueman/gui/applet/PluginDialog.py
index d6579501f..17566a2ba 100644
--- a/blueman/gui/applet/PluginDialog.py
+++ b/blueman/gui/applet/PluginDialog.py
@@ -57,17 +57,17 @@ def __init__(self, inst: AppletPlugin, orientation: Gtk.Orientation = Gtk.Orient
self.show_all()
def construct_settings(self) -> None:
- for k, v in self.inst.__class__.__options__.items():
- if len(v) > 2:
-
- label = Gtk.Label(label=v["name"])
+ for name, option in self.inst.__class__.__options__.items():
+ # Skip options without name and description in the plugin dialog.
+ if "desc" in option and "name" in option:
+ label = Gtk.Label(label=option["name"])
label.props.xalign = 0.0
- w = self.get_control_widget(k, v)
+ w = self.get_control_widget(name, option)
self.pack_start(w, False, False, 0)
- label = Gtk.Label(label="" + v["desc"] + "", wrap=True, use_markup=True, xalign=0.0)
+ label = Gtk.Label(label="" + option["desc"] + "", wrap=True, use_markup=True, xalign=0.0)
self.pack_start(label, False, False, 0)
def handle_change(self, widget: Gtk.Widget, opt: str, params: Option, prop: str) -> None:
diff --git a/blueman/plugins/applet/PowerManager.py b/blueman/plugins/applet/PowerManager.py
index 4ef00f90f..c9b5f698a 100644
--- a/blueman/plugins/applet/PowerManager.py
+++ b/blueman/plugins/applet/PowerManager.py
@@ -35,6 +35,24 @@ class PowerManager(AppletPlugin, StatusIconProvider):
__icon__ = "gnome-power-manager-symbolic"
__dbus_iface_name__ = "org.blueman.Applet.PowerManager"
+ __gsettings__ = {
+ "schema": "org.blueman.plugins.powermanager",
+ "path": None
+ }
+
+ __options__ = {
+ "last-power-state": {
+ "type": bool,
+ "default": False
+ },
+ "restore-power-state": {
+ "type": bool,
+ "default": False,
+ "name": "Restore power state",
+ "desc": "Restore the last known power state of bluetooth."
+ }
+ }
+
class State(Enum):
ON = 2
OFF = 1
@@ -64,7 +82,13 @@ def CurrentState(self) -> bool:
def on_manager_state_changed(self, state: bool) -> None:
if state:
def timeout() -> bool:
- self.request_power_state(self.get_adapter_state())
+ if self.get_option("restore-power-state"):
+ new_power_state = self.get_option("last-power-state")
+ logging.info(f"Restoring last known bluetooth power state {new_power_state}")
+ else:
+ new_power_state = self.get_adapter_state()
+
+ self.request_power_state(new_power_state)
return False
GLib.timeout_add(1000, timeout)
@@ -85,7 +109,7 @@ def set_adapter_state(self, state: bool) -> None:
self.adapter_state = state
except Exception:
- logging.error("Exception occurred", exc_info=True)
+ logging.error(f"Failed to set new power state: {state}", exc_info=True)
class Callback:
def __init__(self, parent: "PowerManager", state: bool):
@@ -166,6 +190,7 @@ def update_power_state(self) -> None:
if self.current_state != new_state:
logging.info(f"Signalling {new_state}")
self.current_state = new_state
+ self.set_option("last-power-state", self.current_state)
self._emit_dbus_signal("BluetoothStatusChanged", new_state)
for plugin in self.parent.Plugins.get_loaded_plugins(PowerStateListener):
diff --git a/data/org.blueman.gschema.xml b/data/org.blueman.gschema.xml
index 023a7dcf7..36a060e63 100644
--- a/data/org.blueman.gschema.xml
+++ b/data/org.blueman.gschema.xml
@@ -200,4 +200,12 @@
If this is set to true clicking the system tray icon will toggle the manager instead of focusing on it.
+
+
+ false
+
+
+ nothing
+
+