nwg-piotr / nwg-panel

GTK3-based panel for sway and Hyprland Wayland compositors
MIT License
624 stars 42 forks source link

[BUG] Discord tray icon stopped working after sytem update #224

Closed r7eyes closed 3 weeks ago

r7eyes commented 1 year ago

Describe the bug The Discord tray icon stopped showing on my system after a system update, while others still work. I mainly use the Discord flatpak, but I tried installing the discord AUR package, as well as the Webcord flatpak, and all of them have the same issue.

journalctl shows an error as follows:

May 17 10:40:46 XXXX sway[1436]: time="2023-05-17T10:40:46+08:00" level=info msg="env vars: [--branch=stable --arch=x86_64 --command=discord]; command: '/usr/bin/flatpak'; args: [run --branch=stable --arch=x86_64 --command=discord com.discordapp.Discord]\n"
May 17 10:40:46 XXXX systemd[658]: Started app-flatpak-com.discordapp.Discord-8957.scope.
May 17 10:40:46 XXXX systemd[658]: Started app-flatpak-com.discordapp.Discord-8997.scope.
May 17 10:40:47 XXXX sway[9047]: The XKEYBOARD keymap compiler (xkbcomp) reports:
May 17 10:40:47 XXXX sway[9047]: > Warning:          Unsupported maximum keycode 708, clipping.
May 17 10:40:47 XXXX sway[9047]: >                   X11 cannot support keycodes above 255.
May 17 10:40:47 XXXX sway[9047]: Errors from xkbcomp are not fatal to the X server
May 17 10:40:47 XXXX sway[1438]: Traceback (most recent call last):
May 17 10:40:47 XXXX sway[1438]:   File "/usr/lib/python3.11/site-packages/dasbus/client/observer.py", line 88, in _name_appeared_callback
May 17 10:40:47 XXXX sway[1438]:     callback(name_owner, *callback_args)
May 17 10:40:47 XXXX sway[1438]:   File "/usr/lib/python3.11/site-packages/dasbus/client/observer.py", line 230, in _service_name_appeared_callback
May 17 10:40:47 XXXX sway[1438]:     self._enable_service()
May 17 10:40:47 XXXX sway[1438]:   File "/usr/lib/python3.11/site-packages/dasbus/client/observer.py", line 220, in _enable_service
May 17 10:40:47 XXXX sway[1438]:     self._service_available.emit(self)
May 17 10:40:47 XXXX sway[1438]:   File "/usr/lib/python3.11/site-packages/dasbus/signal.py", line 53, in emit
May 17 10:40:47 XXXX sway[1438]:     callback(*args, **kwargs)
May 17 10:40:47 XXXX sway[1438]:   File "/usr/lib/python3.11/site-packages/nwg_panel/modules/sni_system_tray/item.py", line 63, in item_available_handler
May 17 10:40:47 XXXX sway[1438]:     self.item_proxy.NewTitle.connect(
May 17 10:40:47 XXXX sway[1438]:     ^^^^^^^^^^^^^^^^^^^^^^^^
May 17 10:40:47 XXXX sway[1438]:   File "/usr/lib/python3.11/site-packages/dasbus/client/proxy.py", line 161, in __getattr__
May 17 10:40:47 XXXX sway[1438]:     member = self._get_member(self._get_interface(name), name)
May 17 10:40:47 XXXX sway[1438]:                               ^^^^^^^^^^^^^^^^^^^^^^^^^
May 17 10:40:47 XXXX sway[1438]:   File "/usr/lib/python3.11/site-packages/dasbus/client/proxy.py", line 223, in _get_interface
May 17 10:40:47 XXXX sway[1438]:     raise AttributeError(
May 17 10:40:47 XXXX sway[1438]: AttributeError: DBus object has no attribute 'NewTitle'.

To Reproduce Steps to reproduce the behavior:

  1. Launch Discord.

Expected behavior All system tray icons should work.

Screenshots N/A

Desktop (please complete the following information):

Additional context My suspicions is that it might have something to do with Arch updating to Python 3.11 from 3.10, where AUR packages that depends on Python break, and which before that the Discord tray icon still worked. I've rebuilt all my AUR packages that use Python (including python-dasbus) and all other system tray icons work from what I've tested so far, so I'm not sure why Discord specifically is having problems.

nwg-piotr commented 1 year ago

No idea at the moment. The python-dasbus package has been flagged out of date some time ago ("Need to Rebuild"). Maybe this is going to help?

nwg-piotr commented 1 year ago

BTW: running Discord from the terminal reveals plenty of error messages, e.g.:

Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")

nwg-piotr commented 1 year ago

This module exceeds my skills by the way. @christian-schulze - any idea?

blauch commented 12 months ago

I experience this issue as well as mentioned in #248.

I wonder if my other issue is also related - are desktop notifications affected as well? For some apps it does not show the app icons but a placeholder. For example Slack and Network Manager notifications do not have proper icons next to the notification while notifications from the browser do. Please see the screenshot below

image

nwg-piotr commented 12 months ago

It affects all Electron apps, as far as I know.

If it comes to notifications: swaync is a third party app, so you need to ask for help on their repository.

Schievel1 commented 10 months ago

Interestingly enough the icon for nextcloud also does not show up. To my knowledge it isn't an electron app. I don't know if this is related, because it behaves slightly differently. Discord show a blank space that can not be clicked as an icon, whereas nextcloud shows nothing.

I have to icon of gnome-encfs-manager working, so I know it works at least.

nergdron commented 8 months ago

just ran into this one with the latest nwg-shell packages on hyprland. in addition to electron packages, I've found that heroic game launcher's tray icon doesn't work, as well as blueberry-tray for bluetooth management.

nwg-piotr commented 8 months ago

Electron apps stopped displaying tray icons months ago. See several other issues. Unfortunately we still have no solution. :(

kellerman commented 8 months ago

Electron apps stopped displaying tray icons months ago. See several other issues. Unfortunately we still have no solution. :(

BTW. Great piece of software! Nicely done and quick and easy to configure! I'm now using drawer, panel, dock, displays bits from your repository! This issue is probably a tiny issue, just a problem to debug I suppose. Unfortunately I can' t really help either.

agentx3 commented 8 months ago

I don't have much experience with using DBUS, so apologies in advanced as I might be using very incorrect terminology, but maybe the info I found will be useful? From listening to the dbus while having nwg-panel and waybar both activated I was able to follow and see if I could get the StatusNotifierItem properties. Basically there's an extra step that nwg-panel needs to follow.

Current behavior:

When discord starts up, nwg-panel tries to register the StatusNotifierItem (https://github.com/nwg-piotr/nwg-panel/blob/master/nwg_panel/modules/sni_system_tray/host.py#L78) using a service name that looks like org.kde.StatusNotifierItem-xxxxxx-1 where the x is some number, and object_path of /StatusNotifierItem. This results in nothing.

What I did:

We need to call the DBUS to GetNameOwner of that service, then we call that service directly with GetAll to get the properties of the StatusNotifierItem. I introduced a simple if-block that achieves it:

service_name, object_path = get_service_name_and_object_path(full_service_service)
# Handle the case for Discord  
if object_path == "/StatusNotifierItem":
    dbus = self.session_bus.get_proxy('org.freedesktop.DBus', '/org/freedesktop/DBus')
    owner_name = dbus.GetNameOwner(service_name)
    # Results in some thing like `:1.xxxx`
    print(f"Owner of {service_name} is {owner_name}")
    object_path = '/StatusNotifierItem'  
    sni_proxy = self.session_bus.get_proxy(owner_name, object_path)
    sni_properties = sni_proxy.GetAll('org.kde.StatusNotifierItem')
    for property_name, property_value in sni_properties.items():
        # Prints the properties like "IconPixmap, Status, etc."
        print(f"{property_name}: {property_value}")

if self.find_item(service_name, object_path) is None:
    item = StatusNotifierItem(service_name, object_path)
    item.set_on_loaded_callback(self.item_loaded_handler)
    item.set_on_updated_callback(self.item_updated_handler)
    self._statusNotifierItems.append(item)

However I'm not sure how to integrate this into the library, because of how we need to get a proxy and then call "GetAll" on it to get the properties, while it looks like the current implementation is able to access the properties directly on the proxy.

nwg-piotr commented 8 months ago

BTW. Great piece of software! Nicely done and quick and easy to configure! I'm now using drawer, panel, dock, displays bits from your repository! This issue is probably a tiny issue, just a problem to debug I suppose. Unfortunately I can' t really help either.

Thank you! I had no idea how to fix it so far, but let's learn what @agentx3 comes up with.

nwg-piotr commented 8 months ago

I don't have much experience with using DBUS, so apologies in advanced as I might be using very incorrect (...)

Thank you very much for your effort. It's too late tonight, but I'll check out your findings tomorrow.

nwg-piotr commented 8 months ago

while it looks like the current implementation is able to access the properties directly on the proxy

Well, for Discord NewTitle, NewIcon, NewAttentionIcon, NewIconThemePath and NewStatus properties are missing from item_proxy. I have no idea how to make use of your sni_properties. :/

agentx3 commented 8 months ago

Ah, yeah you'll have to tell me what is needed. I looked at the interaction between waybar and discord, and this seems to be the behavior when the icon updates (when first started, it's the simple icon, but I have unread messages, so once it logs me in the icon changes, and this is the beginning of that sequence)

Here, :1.47 is waybar, :1.917 is discord. I'll add comments with a #

# discord sends a dbus signal to listeners that its properties has changed
signal time=1705549945.844904 sender=:1.917 -> destination=(null destination) serial=21 path=/StatusNotifierItem; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.kde.StatusNotifierItem" 
   array [
   ]
   array [
   # Icon has changed
      string "IconPixmap"
   ]
# Discord signals to listeners about NewIcon
signal time=1705549945.844916 sender=:1.917 -> destination=(null destination) serial=22 path=/StatusNotifierItem; interface=org.kde.StatusNotifierItem; member=NewIcon 
# Waybar presumably detects the signal, and invokes GetAll to get the new properties
method call time=1705549945.855221 sender=:1.47 -> destination=:1.917 serial=10920 path=/StatusNotifierItem; interface=org.freedesktop.DBus.Properties; member=GetAll
   string "org.kde.StatusNotifierItem"
method call time=1705549945.855231 sender=:1.47 -> destination=:1.917 serial=10921 path=/StatusNotifierItem; interface=org.freedesktop.DBus.Properties; member=GetAll
   string "org.kde.StatusNotifierItem"
method call time=1705549945.855241 sender=:1.47 -> destination=:1.917 serial=10922 path=/StatusNotifierItem; interface=org.freedesktop.DBus.Properties; member=GetAll
   string "org.kde.StatusNotifierItem"
method return time=1705549945.855372 sender=:1.917 -> destination=:1.47 serial=23 reply_serial=10920
# <The same  properties of sni_proxy from the python block are returned>

I would imagine that it works similarly for the other properties, but I can look into it more if it turns out that's not the case. Is this information pertinent to your concerns?

Side note, python syntax highlighting worked surprisingly well for that code block

nwg-piotr commented 8 months ago

Ah, yeah you'll have to tell me what is needed.

Wish I knew. I not the author of this module.

agentx3 commented 8 months ago

Ah darn. Well I might get around to hacking at it more eventually. For anyone that's interested reading this, I believe this might be the solution: I think we need to use GLibClient.subscribe_signal as defined here. We have most of the args, not sure what connection is but presumably that'd be pretty easy to get. Flags might be tricky if needed. But other than that, we should be able to use that in lieu of the current implementation of detecting property changes

nwg-piotr commented 8 months ago

Thanks in advance if you'd like to devote your time to this.

FakeMichau commented 3 months ago

Just wanted to chime in to show my support for this feature being added/improved. The project as a whole seems to be amazing, would love to move to using it over waybar. The issue is that not seeing half of my apps on the tray bar simply makes it unusable for me as apps like Feishin can only be brought back using the tray.

I did look at the code but it's sadly beyond my abilities and willingness to get familiar with the codebase.

progandy commented 3 weeks ago

I looked at it for another electron application (mullvad-vpn) and it is missing the introspection data. dasbus relies on that to create the properties. One option would be to manually read the properties using .GetAll with the correct interface or add the interface definition using some internal dasbus knowlege:

_SNI_XML = """
## contents of https://github.com/Alexays/Waybar/blob/26329b660af3169b9daad533017964f35ba98726/protocol/dbus-status-notifier-item.xml
"""
    def item_available_handler(self, _observer):
        self.item_proxy = self.session_bus.get_proxy(self.service_name, self.object_path)
        try:
            spec = self.item_proxy._handler.specification
            if spec is not None:
                if not any("StatusNotifierItem" in ifname for ifname in spec.interfaces):
                    DBusSpecificationParser._parse_xml(spec, _SNI_XML)
        except:
            pass
        if hasattr(self.item_proxy, "PropertiesChanged"):
...
nwg-piotr commented 3 weeks ago

PRs welcome :)

Antiz96 commented 3 weeks ago

@nwg-piotr Any plan on tagging a new release including the fix? If not, I can backport the fix in the current Arch package.

nwg-piotr commented 3 weeks ago

Sure, could be done in a minute, if you want.

Antiz96 commented 3 weeks ago

Sure, could be done in a minute, if you want.

I mean, it's up to you. Either way I can include the fix in the Arch package :) But if you're fine tagging a new release, then let's do it I guess :D

nwg-piotr commented 3 weeks ago

Ready.

Antiz96 commented 3 weeks ago

Thanks!

nergdron commented 3 weeks ago

just wanted to confirm that this fixes two problematic system tray apps for me (discord and heroic game launcher), really appreciate the work that went into this ticket, y'all. :sparkling_heart: