Skip to content

fix(trayicon): wait for system tray availability on startup#116

Merged
ErikBjare merged 2 commits intoActivityWatch:masterfrom
TimeToBuildBob:fix/trayicon-wait-for-systray
Feb 27, 2026
Merged

fix(trayicon): wait for system tray availability on startup#116
ErikBjare merged 2 commits intoActivityWatch:masterfrom
TimeToBuildBob:fix/trayicon-wait-for-systray

Conversation

@TimeToBuildBob
Copy link
Contributor

@TimeToBuildBob TimeToBuildBob commented Feb 27, 2026

Summary

  • Instead of immediately exiting when the system tray isn't available, polls for up to 30 seconds
  • Calls app.processEvents() during the wait so Qt can detect when the tray becomes available
  • Falls back to the original error dialog if the tray never appears
  • Fixes the issue on KDE Plasma (and similar DEs) where autostart programs launch before the panel is loaded

Test plan

  • On KDE Plasma with aw-qt in autostart, verify it waits and successfully starts
  • On a system with a system tray, verify no delay (the check passes immediately)
  • On a headless system with no tray, verify it exits after 30s with the error dialog

Fixes #97


Important

Poll for system tray availability for up to 30 seconds on startup in run() in trayicon.py, addressing KDE Plasma startup issues.

  • Behavior:
    • In run() in trayicon.py, poll for system tray availability for up to 30 seconds on startup.
    • Call app.processEvents() during the wait to detect tray availability changes.
    • Exit with error dialog if tray is unavailable after 30 seconds.
  • Environment:
    • Fixes startup issue on KDE Plasma where autostart programs launch before the panel is loaded.

This description was created by Ellipsis for f071fe0. You can customize this summary. It will automatically update as commits are pushed.

On some desktop environments (e.g. KDE Plasma), autostart programs
launch before the system tray/panel is loaded. aw-qt would immediately
exit with an error in this case.

Now polls for up to 30 seconds with Qt event processing, giving the
desktop environment time to initialize its system tray. Falls back to
the original error if the tray never becomes available.

Fixes ActivityWatch#97
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to f071fe0 in 7 seconds. Click for details.
  • Reviewed 47 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.

Workflow ID: wflow_TUbKdbfrtL4ImxJq

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@greptile-apps
Copy link

greptile-apps bot commented Feb 27, 2026

Greptile Summary

Replaces immediate failure when system tray is unavailable with a 30-second polling mechanism. The implementation calls app.processEvents() during each 1-second interval to allow Qt to detect when the tray becomes available, solving the KDE Plasma autostart timing issue where the panel loads after applications start.

Key changes:

  • Added polling loop that checks every second for up to 30 seconds
  • Calls app.processEvents() to enable Qt event processing during the wait
  • Logs when tray becomes available and how long it took
  • Falls back to original error dialog if tray never appears
  • Properly uses for-else construct to handle timeout case

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is straightforward and well-contained. The polling logic is sound, includes appropriate logging, and maintains backward compatibility by falling back to the original error behavior. The use of app.processEvents() is necessary and safe at this point in the startup sequence. No security, performance, or logic issues identified.
  • No files require special attention

Important Files Changed

Filename Overview
aw_qt/trayicon.py Added polling mechanism to wait up to 30 seconds for system tray availability on startup, preventing immediate failure on slow-loading desktop environments

Last reviewed commit: f071fe0

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

)
sys.exit(1)
logger.info("System tray not yet available, waiting up to 30 s...")
for i in range(30):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30s seems like a lot? 10s should be more than enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — reduced to 10s in 81b5ef6.

10 seconds is sufficient for KDE Plasma to load the system tray.
Feedback from @ErikBjare.
@ErikBjare ErikBjare merged commit fccd5ca into ActivityWatch:master Feb 27, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Application exits prematurely if QSystemTrayIcon.isSystemTrayAvailable() is false

2 participants