Skip to content

Commit

Permalink
Re-register StatusNotifierItem on name owner changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cschramm committed Jul 26, 2022
1 parent 0b07c65 commit 0bc5460
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions blueman/main/indicators/StatusNotifierItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,29 @@ def unregister(self) -> None:


class StatusNotifierItem(IndicatorInterface):
_SNI_BUS_NAME = _SNI_INTERFACE_NAME = "org.kde.StatusNotifierWatcher"

def __init__(self, icon_name: str, on_activate_menu_item: "MenuItemActivator",
on_activate_status_icon: Callable[[], None]) -> None:
self._sni = StatusNotifierItemService(icon_name, on_activate_status_icon, on_activate_menu_item)
self._sni.register()

self._bus = Gio.bus_get_sync(Gio.BusType.SESSION)

Gio.bus_watch_name(Gio.BusType.SESSION, self._SNI_BUS_NAME, Gio.BusNameWatcherFlags.NONE,
lambda *args: self._register(), None)

try:
Gio.bus_get_sync(Gio.BusType.SESSION).call_sync(
"org.kde.StatusNotifierWatcher", "/StatusNotifierWatcher", "org.kde.StatusNotifierWatcher",
"RegisterStatusNotifierItem", GLib.Variant("(s)", ("/org/blueman/sni",)),
None, Gio.DBusCallFlags.NONE, -1)
self._register()
except GLib.Error:
raise IndicatorNotAvailable

def _register(self) -> None:
Gio.bus_get_sync(Gio.BusType.SESSION).call_sync(
self._SNI_BUS_NAME, "/StatusNotifierWatcher", self._SNI_INTERFACE_NAME,
"RegisterStatusNotifierItem", GLib.Variant("(s)", ("/org/blueman/sni",)),
None, Gio.DBusCallFlags.NONE, -1)

def set_icon(self, icon_name: str) -> None:
self._sni.IconName = icon_name
self._sni.emit_signal("NewIcon")
Expand Down

0 comments on commit 0bc5460

Please sign in to comment.