Skip to content

Commit

Permalink
Make connection notifications transient (#2573)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinz01 authored Dec 21, 2024
1 parent e9a0a7c commit 6c6fbfa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
25 changes: 19 additions & 6 deletions blueman/gui/Notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def state_changed(self, state: float) -> None:


class _NotificationDialog(Gtk.MessageDialog):
def __init__(self, summary: str, message: str, _timeout: int = -1,
def __init__(self, summary: str, message: str, _timeout: int = -1, _transient: bool = False,
actions: Iterable[tuple[str, str]] | None = None,
actions_cb: Callable[[str], None] | None = None, icon_name: str | None = None,
image_data: GdkPixbuf.Pixbuf | None = None) -> None:
Expand Down Expand Up @@ -119,7 +119,7 @@ def set_icon_from_icon_name(self, icon_name: str, size: int) -> None:


class _NotificationBubble(Gio.DBusProxy):
def __init__(self, summary: str, message: str, timeout: int = -1,
def __init__(self, summary: str, message: str, timeout: int = -1, transient: bool = False,
actions: Iterable[tuple[str, str]] | None = None,
actions_cb: Callable[[str], None] | None = None, icon_name: str | None = None,
image_data: GdkPixbuf.Pixbuf | None = None) -> None:
Expand Down Expand Up @@ -162,6 +162,12 @@ def __init__(self, summary: str, message: str, timeout: int = -1,
self._timeout = timeout
self._return_id = None

if transient:
try:
self.set_hint('transient', True)
except ValueError:
pass

if icon_name:
self._app_icon = icon_name
elif image_data:
Expand Down Expand Up @@ -267,9 +273,16 @@ def close(self) -> None:
self._return_id = None


def Notification(summary: str, message: str, timeout: int = -1, actions: Iterable[tuple[str, str]] | None = None,
actions_cb: Callable[[str], None] | None = None, icon_name: str | None = None,
image_data: GdkPixbuf.Pixbuf | None = None) -> _NotificationBubble | _NotificationDialog:
def Notification(
summary: str,
message: str,
timeout: int = -1,
transient: bool = False,
actions: Iterable[tuple[str, str]] | None = None,
actions_cb: Callable[[str], None] | None = None,
icon_name: str | None = None,
image_data: GdkPixbuf.Pixbuf | None = None
) -> _NotificationBubble | _NotificationDialog:

forced_fallback = not Gio.Settings(schema_id='org.blueman.general')['notification-daemon']
try:
Expand All @@ -289,4 +302,4 @@ def Notification(summary: str, message: str, timeout: int = -1, actions: Iterabl
else:
klass = _NotificationBubble

return klass(summary, message, timeout, actions, actions_cb, icon_name, image_data)
return klass(summary, message, timeout, transient, actions, actions_cb, icon_name, image_data)
7 changes: 4 additions & 3 deletions blueman/main/applet/BluezAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ def on_confirm_action(action: str) -> None:
notify_message += "\n" + _("Confirm value for authentication:") + f" <b>{passkey:06}</b>"
actions = [("confirm", _("Confirm")), ("deny", _("Deny"))]

self._notification = Notification("Bluetooth", notify_message, 0, actions, on_confirm_action,
icon_name="blueman")
self._notification = Notification("Bluetooth", notify_message, 0,
actions=actions, actions_cb=on_confirm_action, icon_name="blueman")
self._notification.show()

def _on_request_authorization(self, object_path: ObjectPath, ok: Callable[[], None],
Expand Down Expand Up @@ -260,6 +260,7 @@ def on_auth_action(action: str) -> None:
("accept", _("Accept")),
("deny", _("Deny"))]

n = Notification(_("Bluetooth Authentication"), notify_message, 0, actions, on_auth_action, icon_name="blueman")
n = Notification(_("Bluetooth Authentication"), notify_message, 0,
actions=actions, actions_cb=on_auth_action, icon_name="blueman")
n.show()
self._service_notifications.append(n)
10 changes: 8 additions & 2 deletions blueman/plugins/applet/ConnectionNotifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ def on_device_property_changed(self, path: ObjectPath, key: str, value: Any) ->
self._notifications[path] = notification = Notification(
device.display_name,
_('Connected'),
icon_name=device["Icon"]
icon_name=device["Icon"],
transient=True,
)
notification.show()
else:
Notification(device.display_name, _('Disconnected'), icon_name=device["Icon"]).show()
Notification(
device.display_name,
_('Disconnected'),
icon_name=device["Icon"],
transient=True,
).show()

def _on_battery_update(self, path: ObjectPath, value: int) -> None:
notification = self._notifications.pop(path, None)
Expand Down
4 changes: 2 additions & 2 deletions blueman/plugins/applet/TransferService.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def _remove() -> bool:
_("Incoming file over Bluetooth"),
_("Incoming file %(0)s from %(1)s") % {"0": "<b>" + escape(filename) + "</b>",
"1": "<b>" + escape(name) + "</b>"},
30000, [("accept", _("Accept")), ("reject", _("Reject"))], on_action,
icon_name="blueman"
30000,
actions=[("accept", _("Accept")), ("reject", _("Reject"))], actions_cb=on_action, icon_name="blueman"
)
notification.show()
# Device is trusted or was already allowed, larger file -> display a notification, but auto-accept
Expand Down

0 comments on commit 6c6fbfa

Please sign in to comment.