Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions blueman/gui/applet/PluginDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<i >" + v["desc"] + "</i>", wrap=True, use_markup=True, xalign=0.0)
label = Gtk.Label(label="<i >" + option["desc"] + "</i>", 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:
Expand Down
29 changes: 27 additions & 2 deletions blueman/plugins/applet/PowerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
__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
Expand Down Expand Up @@ -64,7 +82,13 @@
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)
Expand All @@ -85,7 +109,7 @@

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)

Check failure on line 112 in blueman/plugins/applet/PowerManager.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "logging.exception()" instead.

See more on https://sonarcloud.io/project/issues?id=blueman-project_blueman&issues=AZ4m80S6glQBaNpV41ze&open=AZ4m80S6glQBaNpV41ze&pullRequest=3244

class Callback:
def __init__(self, parent: "PowerManager", state: bool):
Expand Down Expand Up @@ -166,6 +190,7 @@
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):
Expand Down
8 changes: 8 additions & 0 deletions data/org.blueman.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,12 @@
<description>If this is set to true clicking the system tray icon will toggle the manager instead of focusing on it.</description>
</key>
</schema>
<schema id="org.blueman.plugins.powermanager" path="/org/blueman/plugins/powermanager/">
<key type="b" name="last-power-state">
<default>false</default>
</key>
<key type="mb" name="restore-power-state">
<default>nothing</default>
</key>
</schema>
</schemalist>
Loading