slgobinath / SafeEyes

Protect your eyes from eye strain using this simple and beautiful, yet extensible break reminder
http://slgobinath.github.io/SafeEyes/
GNU General Public License v3.0
1.46k stars 164 forks source link

The required plugin 'Tray Icon' is missing dependencies! on autostart even when all dependencies are installed #636

Closed antoninkriz closed 1 month ago

antoninkriz commented 2 months ago

Describe the bug

I'm getting the error message as in the title of this issue:
image

This started happening very recently (few days ago?), possibly due to some update, although I'm not sure. I had AppIndicator and KStatusNotifierItem packages installed and enables as GNOME extension. I tried to reinstall both the Safe Eyes AUR package and these packages without success. Later I installed snixembed as another option I found in the How to install backend for Safe Eyes tray icon tutorial, also without success.

This error happens only when the app auto starts as an Startup Application, enabled in the GNOME Tweaks app. When I launch the app by clicking the icon in app menu or from terminal everything works correctly and there aren't any problems apparent in the debug log.

This error feels similar to https://github.com/nix-community/home-manager/issues/5728, but I'm not using Nix and with Nix the issue might be somewhere else, possibly really because of missing dependencies. I'm just linking this issue here since it might be interesting.

To Reproduce Steps to reproduce the behavior:

  1. Turn on computer
  2. Login
  3. Safe Eyes autostarts with the error :(

Steps NOT to reproduce the behavior:

  1. Close Safe Eyes error
  2. Start Safe Eyes manually by clicking the icon in app menu
  3. Safe Eyes starts correctly

Expected behavior Safe Eyes not displaying error and launching correctly

Desktop (please complete the following information):

Debug Log

2024-08-14 14:48:37,311 [DEBUG]:[MainThread] Initialize the platform
2024-08-14 14:48:37,339 [INFO]:[MainThread] Starting Safe Eyes
2024-08-14 14:48:37,358 [INFO]:[MainThread] Starting up Application
2024-08-14 14:48:37,376 [INFO]:[MainThread] Initialize the break screen
2024-08-14 14:48:37,376 [INFO]:[MainThread] Load all the plugins
2024-08-14 14:48:37,376 [INFO]:[MainThread] Initialize the core
2024-08-14 14:48:37,378 [INFO]:[MainThread] Successfully loaded <module 'donotdisturb.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/donotdisturb/plugin.py'>
2024-08-14 14:48:37,379 [INFO]:[MainThread] Successfully loaded <module 'notification.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/notification/plugin.py'>
2024-08-14 14:48:37,380 [INFO]:[MainThread] Successfully loaded <module 'audiblealert.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/audiblealert/plugin.py'>
2024-08-14 14:48:37,383 [INFO]:[MainThread] Successfully loaded <module 'trayicon.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/trayicon/plugin.py'>
2024-08-14 14:48:37,385 [INFO]:[MainThread] Successfully loaded <module 'smartpause.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/smartpause/plugin.py'>
2024-08-14 14:48:37,386 [INFO]:[MainThread] Successfully loaded <module 'screensaver.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/screensaver/plugin.py'>
2024-08-14 14:48:37,388 [ERROR]:[MainThread] Error in loading the plugin healthstats: No module named 'croniter'
2024-08-14 14:48:37,389 [INFO]:[MainThread] Successfully loaded <module 'mediacontrol.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/mediacontrol/plugin.py'>
2024-08-14 14:48:37,389 [INFO]:[MainThread] Successfully loaded <module 'limitconsecutiveskipping.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/limitconsecutiveskipping/plugin.py'>
2024-08-14 14:48:37,389 [DEBUG]:[MainThread] Initialize Skip Fullscreen plugin
2024-08-14 14:48:37,390 [DEBUG]:[MainThread] Initialize Notification plugin
2024-08-14 14:48:37,390 [DEBUG]:[MainThread] Initialize Audible Alert plugin
2024-08-14 14:48:37,390 [DEBUG]:[MainThread] Initialize Tray Icon plugin
2024-08-14 14:48:37,396 [DEBUG]:[MainThread] Initialize Smart Pause plugin
2024-08-14 14:48:37,396 [DEBUG]:[MainThread] Initialize Screensaver plugin
2024-08-14 14:48:37,396 [DEBUG]:[MainThread] Initialize Limit consecutive skipping plugin
2024-08-14 14:48:37,396 [INFO]:[MainThread] Setting up an RPC server on port 7200
2024-08-14 14:48:37,397 [INFO]:[MainThread] Start the RPC server
2024-08-14 14:48:37,397 [DEBUG]:[MainThread] Start Smart Pause plugin
2024-08-14 14:48:37,397 [INFO]:[MainThread] Start Safe Eyes core
2024-08-14 14:48:37,398 [INFO]:[WorkThread] Waiting for 15 minutes until next break
2024-08-14 14:48:37,399 [INFO]:[MainThread] Application activated
2024-08-14 14:48:37,399 [INFO]:[MainThread] Update next break information
2024-08-14 14:48:50,820 [INFO]:[MainThread] Quit Safe Eyes
2024-08-14 14:48:50,820 [INFO]:[MainThread] Close the break screen(s)
2024-08-14 14:48:50,820 [INFO]:[MainThread] Unlock the keyboard
2024-08-14 14:48:50,820 [INFO]:[MainThread] Disable Safe Eyes
2024-08-14 14:48:50,821 [DEBUG]:[MainThread] Stop Smart Pause plugin
2024-08-14 14:48:50,821 [INFO]:[MainThread] Stop Safe Eyes core
2024-08-14 14:48:50,821 [DEBUG]:[MainThread] Stop Notification plugin
2024-08-14 14:48:50,821 [INFO]:[WorkThread] Pre-break waiting is over
2024-08-14 14:48:50,821 [INFO]:[MainThread] Stop the RPC server
archisman-panigrahi commented 2 months ago

@antoninkriz In GNOME you will need this extension https://extensions.gnome.org/extension/615/appindicator-support/

snixembed or other tweaks will not work there.

It seems that in your system, safeeyes is starting before the extension does. The solution is to add a 10 second delay for the safeeyes startup.

Please let us know if that works

Add X-GNOME-Autostart-Delay=10 to the safeeyes desktop file in .config/autostart.

If it works, we can add the delay to the startup file safeeyes creates, so that no one will experience this bug.

What do you think @deltragon

antoninkriz commented 2 months ago

In GNOME you will need this extension

I have this extension installed (gnome-shell-extension-appindicator package in Manjaro) and enabled.

It seems that in your system, safeeyes is starting before the extension does. The solution is to add a 10 second delay for the safeeyes startup.

This was right! Good catch! Sadly X-GNOME-Autostart-Delay=10 (not even with X-GNOME-Autostart-enabled=true as some people suggested in some Reddit / StackOverflow threads) did not work. Some people report it doesn't work for them as well. I tried changing the Exec=... line so it contains some variant of sleep 10 && ... but without much success (although without much effort as well :smile:) so I decided to drop in

import time
time.sleep(10)

in the beginning of the sleepeyes executable script and it works, although it's quite ugly.

If needed I would be happy to help with fixing this bug.

archisman-panigrahi commented 2 months ago

While it works for you, I am against adding a sleep timer to the core safeeyes code.

Let's do more research about how to add a timer to the desktop file.

Cinnamon has an inbuilt delay option for startup apps and I don't use GNOME. I will download Ubuntu with GNOME in a VM and check if Cinnamon's solution works there.

deltragon commented 2 months ago

I do think that it may make sense to add logic to the Smartpause plugin to try again after a few seconds (maybe even something like retrying first after one second, then after two more, then after 5 more, and then error). In the working scenario, this will not change anything - in the error scenario it will only delay the error a little bit. But it would make this kind of situation less likely to happen. Adding a delay to the startup file will delay it in all cases, even when it would have worked otherwise. (As an aside, it would also be interesting to check how libappindicator handled this situation - did it also have some kind of retry/exponential backoff logic?)

archisman-panigrahi commented 2 months ago

Alternatively, instead of adding the logic to smartpause, if we add the following logic to the system tray plugin, that will also work.

Try to open tray icon
If doesn't work
Wait for 5 seconds
Try again
Now show the missing backend window
deltragon commented 2 months ago

Yes, that was a typo from me - I meant the trayicon plugin, not smartpause.

archisman-panigrahi commented 2 months ago

Adding X-GNOME-Autostart-Delay=10 to the desktop file delays the app during system startup in Cinnamon desktop, but does not cause any delay if the app is run manually (just as it should be).

It is sad that it does not work in GNOME

archisman-panigrahi commented 2 months ago

How about we maintain two desktop files, a special one for startup, and one for regular app opening? In the startup desktop file, we add a sleep 5 irrespective of the desktop environment? Then no special logic is necessary within the app, and it would keep things simple.

antoninkriz commented 2 months ago

This might not be viable since startup apps can be added in GNOME through the Tweaks app by selecting an app from a list.
If I'm not mistaken the list is made from the standard .desktop files used for manually opening apps.
When selecting an app to autostart the same .desktop file is just copied over to the autostart folder.

So when someone manually adds SafeEyes to startup apps the delay wouldn't be there.

I might be wrong so take this with a grain of salt.

archisman-panigrahi commented 2 months ago

When selecting an app to autostart the same .desktop file is just copied over to the autostart folder.

SafeEyes automatically copies its desktop file to the $HOME/.config/autostart folder when you run it for the first time. Can you confirm that adding X-GNOME-Autostart-Delay=10 to that still does not fix the issue?

deltragon commented 2 months ago

How about we maintain two desktop files, a special one for startup, and one for regular app opening? In the startup desktop file, we add a sleep 5 irrespective of the desktop environment? Then no special logic is necessary within the app, and it would keep things simple.

I don't think that's a viable solution - .desktop files are handled by the desktop environment in many places, and I assume none of them are expecting an app to have multiple ones.

fdev31 commented 2 months ago

I don't think that's a viable solution - .desktop files are handled by the desktop environment in many places, and I assume none of them are expecting an app to have multiple ones.

It's expected that the ~/.config/ overrides the system one, that's how it works as far as I know.

ahkole commented 2 months ago

After upgrading my safeeyes I am having the same issue but I am running i3-wm as my window manager. According to the tray icon backend install page it should work out of the box for i3. Contrary to @antoninkriz for me it also doesn't work if I close the error and try to manually start safeeyes. I always get the error. My debug log:

2024-08-30 16:13:30,597 [DEBUG]:[MainThread] Initialize the platform
2024-08-30 16:13:30,611 [INFO]:[MainThread] Starting Safe Eyes
2024-08-30 16:13:30,614 [INFO]:[MainThread] Starting up Application
2024-08-30 16:13:30,633 [INFO]:[MainThread] Initialize the break screen
2024-08-30 16:13:30,633 [INFO]:[MainThread] Load all the plugins
2024-08-30 16:13:30,633 [INFO]:[MainThread] Initialize the core
2024-08-30 16:13:30,634 [INFO]:[MainThread] Successfully loaded <module 'donotdisturb.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/donotdisturb/plugin.py'>
2024-08-30 16:13:30,635 [INFO]:[MainThread] Successfully loaded <module 'notification.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/notification/plugin.py'>
2024-08-30 16:13:30,636 [INFO]:[MainThread] Successfully loaded <module 'audiblealert.plugin' from '/usr/lib/python3.12/site-packages/safeeyes/plugins/audiblealert/plugin.py'>
2024-08-30 16:13:30,638 [INFO]:[MainThread] Show RequiredPlugin dialog
2024-08-30 16:13:30,663 [INFO]:[MainThread] Setting up an RPC server on port 7200
2024-08-30 16:13:30,664 [INFO]:[MainThread] Start the RPC server
2024-08-30 16:13:30,665 [INFO]:[MainThread] Application activated
2024-08-30 16:13:32,466 [INFO]:[MainThread] Quit Safe Eyes
2024-08-30 16:13:32,467 [INFO]:[MainThread] Close the break screen(s)
2024-08-30 16:13:32,467 [INFO]:[MainThread] Unlock the keyboard
2024-08-30 16:13:32,469 [DEBUG]:[MainThread] Stop Notification plugin
2024-08-30 16:13:32,470 [INFO]:[MainThread] Stop the RPC server

System info: OS: Arch Linux i3-wm: 4.23-4 safeeyes: 2.2.2-1 (installed from AUR)

What can I do to further debug this? There do not seem to be any error messages in the debug log.

archisman-panigrahi commented 2 months ago

@ahkole Can you check if installing snixembed from the AUR, and running snixembed --fork fixes the issue?

Maybe other people who tested it in i3-wm had some backend installed for the tray icon, which you do not have.

ahkole commented 2 months ago

Can you check if installing snixembed from the AUR, and running snixembed --fork fixes the issue?

Hi @archisman-panigrahi, this indeed fixes the issue. Was this dependency on a backend added somewhere in the last year? It used to run normally without having snixembed installed.

archisman-panigrahi commented 2 months ago

Ok. You have to add snixembed --fork to your startup application for safeeyes to work smoothly.

We recently changed our backend for tray icon as a preparation of our upcoming transition to GTK4. While most full-fledged desktop interfaces support this modern backend, some WMs and DEs don't support it. snixembed acts as a bridge between the the two technologies.

Some other users reported to us that it works out-of-the box in i3. Maybe some distros have a customized i3 with more background processes to support the new trayicon, but the vanilla i3 in Arch does not support it out-of-the box. I will add it to the wiki.

ahkole commented 2 months ago

Alright, good to know. Thanks for helping me fix it. I'll add the call to snixembed to my startup config. I'll also make note of this in the AUR package for safeeyes.

archisman-panigrahi commented 2 months ago

I am the AUR package maintainer. I can add a comment that some users may need snixembed. I don't want to add it as an optional dependency, because it is not really a dependency of safeeyes, but rather a deficiency of window managers. Full fledged DEs like KDE don't have a problem.

I updated the wiki for information about i3

On Fri, Aug 30, 2024, 12:57 PM Arnold Kole @.***> wrote:

Alright, good to know. Thanks for helping me fix it. I'll add the call to snixembed to my startup config. I'll also make note of this in the AUR package for safeeyes.

— Reply to this email directly, view it on GitHub https://github.com/slgobinath/SafeEyes/issues/636#issuecomment-2321976032, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXL2XA2SRGI7OT4PWOUGPDZUCQAVAVCNFSM6AAAAABMSCRUWCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRRHE3TMMBTGI . You are receiving this because you were mentioned.Message ID: @.***>

ahkole commented 2 months ago

Ah okay, sounds good!