buzz / volctl

Per-application volume control and OSD for Linux desktops.
https://buzz.github.io/volctl/
GNU General Public License v2.0
132 stars 19 forks source link

Wait for tray #81

Closed musjj closed 1 year ago

musjj commented 1 year ago

Is there a way to wait for the tray before erroring out? I have a service like this:

[Install]
WantedBy=tray.target

[Service]
ExecStart=/usr/bin/volctl

[Unit]
Description=Per-application volume control and OSD for Linux desktops
PartOf=tray.target

But it errors on startup because the tray is not ready yet:

Aug 28 08:36:28 $HOST volctl[1362]: PulseAudio connected
Aug 28 08:36:28 $HOST volctl[1362]: Warning: Could not embed Gtk.StatusIcon.
Aug 28 08:36:28 $HOST volctl[1362]: Fatal error: Could not create a status icon. Are you sure you have a working notification area?
Aug 28 08:36:28 $HOST volctl[1362]: pulseaudio disconnected
Aug 28 08:36:28 $HOST systemd[1324]: volctl.service: Main process exited, code=killed, status=14/ALRM
Aug 28 08:36:28 $HOST systemd[1324]: volctl.service: Failed with result 'signal'.

Other tray services does not seem to have this problem. Is there a way to handle this problem?

raven2cz commented 1 year ago

This issue has surfaced approximately four weeks ago. It seems likely that the root cause may be a modification in PulseAudio, its API, or some other related library. This is noteworthy because Volctl, which has been stable for several years, hasn't undergone any changes that could explain this new problem. Unfortunately, due to time constraints, I haven't been able to investigate the cause of this unexpected behavior.

musjj commented 1 year ago

It looks like the problem is not with pulseaudio but with it failing to create a status icon. Can you clarify?

Looks like that it's an old problem: https://github.com/buzz/volctl/issues/56

As the commenter mentioned, other tray applications doesn't suffer from this problem. I wonder what do they do differently?

raven2cz commented 1 year ago

A few weeks ago, something changed that affected the functionality, but not within Volctl itself. The link you provided is relevant; I'm experiencing the same issue now. As a temporary solution, I've had to adjust the initialization settings of Volctl and set a waiting time. However, this is merely a workaround and not a proper solution to the problem.

musjj commented 1 year ago

Looks like the fix is pretty simple. The culprit is this line:

https://github.com/buzz/volctl/blob/cf0f7edc9da2735d2e1565cb5d2a43d92d917412/volctl/status_icon.py#L119

Removing it fixes the problem.

It tries to check if icon is embedded or not, but I'm not really sure if it's necessary. It'll automatically embed itself when the tray is ready.

I'm guessing that it's intended to check if there's a problem, but isn't there a better way? I'd assume that as long as Gtk.StatusIcon() isn't throwing any exceptions, things should work just fine.

raven2cz commented 1 year ago

Nice! Try to create PR and @buzz look on it, thx!

musjj commented 1 year ago

I'm not really sure how well it works with Wayland though. What happens when statusnotifier isn't installed when volctl is launched? Will Gtk.StatusIcon fail silently or does it correctly throw an error?

buzz commented 1 year ago

I'm not really sure how well it works with Wayland though. What happens when statusnotifier isn't installed when volctl is launched? Will Gtk.StatusIcon fail silently or does it correctly throw an error?

This issue is not related to Wayland. Check #39 instead.

buzz commented 1 year ago

Closing this issue, as it is a dup of #56. I reopened the original issue and kindly ask to continue the discussion there.

musjj commented 1 year ago

I think you misunderstood my comment. What I am asking is the impact of the change I proposed above on Wayland systems. The solution above works perfectly on X for me, but since I don't use Wayland, I can't predict what kind of impact it would have.

But it seems that volctl isn't actually supported on Wayland at all, so I guess it doesn't really matter.