ActivityWatch / activitywatch

The best free and open-source automated time tracker. Cross-platform, extensible, privacy-focused.
https://activitywatch.net/
Mozilla Public License 2.0
11.85k stars 539 forks source link

Could not detect systray on Ubuntu #258

Closed zemmyang closed 5 years ago

zemmyang commented 5 years ago

Describe the bug

On startup, I get this message: "I couldn't detect any system tray on this system. Either get one or run the ActivityWatch modules from the console." However, everything works fine, tho. I can open the WebUI from the Chrome extension and all of my activity gets tracked but I don't get the AW icon in the panel.

To Reproduce

Appears on startup.

Documentation

I found this labeled "error" in the aw-watcher-window logfiles but I don't know if they're relevant

2018-12-17 01:55:15 [ERROR]: Exception thrown while trying to get active window: <class 'Xlib.error.BadWindow'>: code = 3, resource_id = <class 'Xlib.xobject.resource.Resource'>(0x02400015), sequence_number = 257, major_opcode = 20, minor_opcode = 0 (aw_watcher_window.main:68)

When I try to run aw-qt from the command line, I get this: 2019-01-01 15:33:39 [INFO ]: Using storage method: peewee (aw_server.main:26) 2019-01-01 15:33:39 [INFO ]: Starting up... (aw_server.main:31) 2019-01-01 15:33:39 [INFO ]: Using database file: /home/zemmy/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db (aw_datastore.storages.peewee:114) 2019-01-01 15:33:39 [ERROR]: [Errno 98] Address already in use (aw_server.server:75)

Environment

Additional context

I recently reformatted, I used to use Ubuntu 18.04 LTS as well, and I was using AW back then, too. I never got this error.

johan-bjareholt commented 5 years ago

Gnome which Ubuntu uses has removed support for a systray since a year back (a standard which has been available for 20+ years and they did not add any type of equivalent option). So yeah, it still runs fine but it will be harder to open the WebUI and make sure that all watchers are running. A solution to the issue would be to download this Gnome extension

https://extensions.gnome.org/extension/495/topicons/

johan-bjareholt commented 5 years ago
2019-01-01 15:33:39 [INFO ]: Using storage method: peewee (aw_server.main:26)
2019-01-01 15:33:39 [INFO ]: Starting up... (aw_server.main:31)
2019-01-01 15:33:39 [INFO ]: Using database file: /home/zemmy/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db (aw_datastore.storages.peewee:114)
2019-01-01 15:33:39 [ERROR]: [Errno 98] Address already in use (aw_server.server:75)

Also, this indicates that activitywatch is already running in the backgorund.

2018-12-17 01:55:15 [ERROR]: Exception thrown while trying to get active window: <class 'Xlib.error.BadWindow'>: code = 3, resource_id = <class 'Xlib.xobject.resource.Resource'>(0x02400015), sequence_number = 257, major_opcode = 20, minor_opcode = 0 (aw_watcher_window.main:68)

This error indicates that you have some window open which aw-watcher-window cannot recognize. aw-watcher-window does not crash because of this so it should be fine, but it would still be interesting to know which kind of window it was unable to recognize so we can find out if the window was invalidly created or if there's a rare bug in aw-watcher-window.

zemmyang commented 5 years ago

Gnome which Ubuntu uses has removed support for a systray since a year back (a standard which has been available for 20+ years and they did not add any type of equivalent option). So yeah, it still runs fine but it will be harder to open the WebUI and make sure that all watchers are running. A solution to the issue would be to download this Gnome extension

https://extensions.gnome.org/extension/495/topicons/

This fixed it, but I still find it unusual that I had to do this in the first place.

It used to work fine (without the gnome ext) when I installed AW on Ubuntu 18.04 LTS (on the same laptop) a few months ago; AW one of the first things I initially install on a fresh reformat.

johan-bjareholt commented 5 years ago

Odd that it had worked before, Ubuntu 18.04 comes with Gnome 3.28 and the systray was removed in 3.26. Ubuntu 16.04 should've worked though since it has a version lower than 3.26.

ErikBjare commented 5 years ago

@zemmyang Yeah, it's not as intended. We plan to migrate to the new thing (AppIndicator) that is replacing the old tray icon system someday, but probably not anytime soon.

Related issue: https://github.com/ActivityWatch/activitywatch/issues/238

johan-bjareholt commented 5 years ago

Also @ErikBjare, in #238 I stated that systray icons are deprecated (which they are) but I later realized that appindicators are deprecated as well! Gnome has completely removed the support for all types of tray icons because they don't find it to be a good user experience, so I have no idea at all what to actually do now.

https://wiki.gnome.org/Initiatives/StatusIconMigration

Here you can see examples of what other apps have done.

An option would be to use https://gitlab.gnome.org/World/libcloudproviders, but as far as I can see there's no way to add a shortcut to the webui anywhere there... Not sure what the best design choice would be.

Application can be used without the status icon. However, the status icon is the only way to quit and access settings. The aim is to use libcloudprovider for GNOME 3.28.

Doesn't seem like dropbox knows either what to do for the same reason, they need a shortcut to their UI from the trayicon aswell.

ErikBjare commented 5 years ago

@johan-bjareholt Well, frankly f%ck the Gnome devs then. I really don't think we should put any effort into going along with their whims.

Closing due to hopelessness.

johan-bjareholt commented 5 years ago

@ErikBjare Yeah, I kind of agree. We had a proper solution which worked and they deprecated it without a good alternative solution and I'm not interested in trying to push them to do the right thing.

But if they improve their APIs in the future so they actually fit our use-case we could re-open this, but until then let this be a waiting game. We are not the only ones with this issue (steam, dropbox etc) so it'll likely be fixed sometime.

vesatoivonen commented 5 years ago

I had a similar problem with arch and xfce. Running aw-qt from terminal worked fine but putting it on autostart gave the same error.

Fixed it by postponing the autostart a bit with a small script:

#!/bin/bash
sleep 5 && /bin/aw-qt
sojusnik commented 3 years ago

Another way to delay the autostart is to add

X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=5

in ~/.config/autostart/activitywatch.desktop

so that it looks like


[Desktop Entry]
Name=ActivityWatch
Exec=yourpath/ActivityWatch/aw-qt
Icon=yourpath/ActivityWatch/aw-server/aw_server/static/static/logo.png
Type=Application
StartupNotify=true
Hidden=false
NoDisplay=false
Terminal=false
X-GNOME-UsesNotifications=true
X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=5
AnwarShah commented 3 years ago

The app also give same error on elementary OS

lukashino commented 3 years ago

None of the proposed solutions to autostart AW worked on Ubuntu 20.04. Thus I at least added starter icon to my dock ("Favorites").

  1. create shortcut by creating file in /usr/share/applications/starter.desktop with contents:
    [Desktop Entry]
    Name=MyStarter
    Comment=
    Exec=/usr/bin/activitywatch/aw-qt
    Icon=
    Terminal=false
    Type=Application
    Encoding=UTF-8
    Categories=Application;
    MimeType=
    X-KDE-Protocols=
  2. Find it applications by name MyStarter, right-click - add to Favorites
swenzel commented 3 years ago

I'm on Ubuntu 20.04 and can confirm that the solution proposed by @sojusnik works :slightly_smiling_face:

danisztls commented 3 years ago

I'm on Arch Linux, Gnome 3, installed from AUR and had the same error. Everything works when running aw-qt from terminal. My solution was to wrote a simple systemd user service that runs aw-qt and delete the .desktop at /etc/xdg/autostart.

Also I don't think is a good idea to have the .desktop at /etc/xdg/autostart. First, it will not work properly on most systems. Second, AW use case is at user level and should not be set as a system level target for autostart.

aw-tray-error

[Unit]
Description=Activity Watcher QT tray icon and daemon
After=network.target

[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/usr/bin/aw-qt
ExecStop=

[Install]
WantedBy=graphical-session.target
johan-bjareholt commented 3 years ago

@lbcnz

I'm on Arch Linux, Gnome 3, installed from AUR and had the same error. Everything works when running aw-qt from terminal. My solution was to wrote a simple systemd user service that runs aw-qt and delete the .desktop at /etc/xdg/autostart.

Could you investigate further what actually makes your solution make aw-qt find a tray and continue running, because nothing in your .service file seems to indicate anything that should actually fix that. (Except for maybe "RemainAfterExit=yes" which is not appropriate for aw-qt as it would just hide issues when it fails rather than actually changing the state to "failed" when it should).

Also I don't think is a good idea to have the .desktop at /etc/xdg/autostart. First, it will not work properly on most systems. Second, AW use case is at user level and should not be set as a system level target for autostart.

I'm not sure what you mean with "will not work properly on most systems", could you give an example? The only time it should not work is if a DE is used that does not support XDG autostart at all and in those cases it's likely not a DE being used rather than just a WM, so that's by design and choice of the user. Gnome also supports XDG autostart fine, it just doesn't support GNOME (unless you install a tray extension).

Also, files in /etc/xdg/autostart are not system level targets, they are simply the system default autostart applications for DEs to use. Take a look at the Arch Linux Wiki for more info about XDG autostart and how /etc/xdg/autostart works. https://wiki.archlinux.org/index.php/XDG_Autostart

danisztls commented 3 years ago

Could you investigate further what actually makes your solution make aw-qt find a tray and continue running, because nothing in your .service file seems to indicate anything that should actually fix that. (Except for maybe "RemainAfterExit=yes" which is not appropriate for aw-qt as it would just hide issues when it fails rather than actually changing the state to "failed" when it should).

Sorry. Indeed it dit not work properly and I had to create a timer to fix that.

[Timer]
OnBootSec=1min

 [Install]
 WantedBy=graphical-session.target

I'm not sure what you mean with "will not work properly on most systems", could you give an example? The only time it should not work is if a DE is used that does not support XDG autostart at all and in those cases it's likely not a DE being used rather than just a WM, so that's by design and choice of the user. Gnome also supports XDG autostart fine, it just doesn't support GNOME (unless you install a tray extension).

Also, files in /etc/xdg/autostart are not system level targets, they are simply the system default autostart applications for DEs to use. Take a look at the Arch Linux Wiki for more info about XDG autostart and how /etc/xdg/autostart works. https://wiki.archlinux.org/index.php/XDG_Autostart

As it is having it will not launch the QT tray icon properly and will display a warning for every user using GNOME unless they install that extension. Problem is that in a computer with multiple users: 1- they all will have AW running by default at startup without having a choicet. 2- Each of them will have to install a third-party extension that may not work properly. System level target was a poor choice of words from me to refer to having that setting as a system global instead of a user local. Possibly it can be disabled by default and users could copy the .desktop to ~/.config/autostart. Alternatively, if the service and timer is installed at /usr/lib/service, they can run: systemctl --user enable aw.timer to enable it at graphical login and systemctl --user start aw.service to start it without delay.

myounus96 commented 3 years ago

Another way to delay the autostart is to add

X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=5

in ~/.config/autostart/activitywatch.desktop

so that it looks like


[Desktop Entry]
Name=ActivityWatch
Exec=yourpath/ActivityWatch/aw-qt
Icon=yourpath/ActivityWatch/aw-server/aw_server/static/static/logo.png
Type=Application
StartupNotify=true
Hidden=false
NoDisplay=false
Terminal=false
X-GNOME-UsesNotifications=true
X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=5

Thank you. I on ubuntu 20.04 and can confirm that this solution works.

coabr commented 3 years ago

Another way to delay the autostart is to add

X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=5

in ~/.config/autostart/activitywatch.desktop

so that it looks like


[Desktop Entry]
Name=ActivityWatch
Exec=yourpath/ActivityWatch/aw-qt
Icon=yourpath/ActivityWatch/aw-server/aw_server/static/static/logo.png
Type=Application
StartupNotify=true
Hidden=false
NoDisplay=false
Terminal=false
X-GNOME-UsesNotifications=true
X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=5

Could you explain how to do it step by step on terminal? I tried: $ sudo gedit ~/.config/autostart/activitywatch.desktop The file opened but it was empty. So I included the text you told above: image

But still, when I save I get this message: "(gedit:5336): Tepl-WARNING **: 19:29:41.693: GVfs metadata is not supported. Fallback to TeplMetadataManager. Either GVfs is not correctly installed or GVfs metadata are not supported on this platform. In the latter case, you should configure Tepl with --disable-gvfs-metadata." And on restart, I get the message still: image

ErikBjare commented 3 years ago

@COAB1 Have a look at the documentation for a different way to run ActivityWatch on Gnome which works around aw-qt and therefore deals with that particular error message: https://docs.activitywatch.net/en/latest/running-on-gnome.html

johan-bjareholt commented 2 years ago

There is apparently a new trayicon spec in the works, which has the aim to be supported by GNOME Shell. Hopefully it will land in a not too distant future!

https://gitlab.freedesktop.org/xdg/xdg-specs/-/issues/84

johan-bjareholt commented 1 year ago

There's also a "background apps" freedesktop spec in the works, which gnome-shell seem to be recommending.

Doesn't really replace a trayicon fully, but together with e.g. an application shortcut to start the web-ui and a window rather than a trayicon menu to handle the modules, this is a solvable problem.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2624 https://gitlab.gnome.org/Teams/Design/os-mockups/-/issues/191

Humam-Hamdan commented 2 months ago

so no fix yet... :)