Skip to content

fix: read port from server config instead of hardcoding 5600#122

Merged
ErikBjare merged 4 commits intoActivityWatch:masterfrom
TimeToBuildBob:fix/config-port
Mar 2, 2026
Merged

fix: read port from server config instead of hardcoding 5600#122
ErikBjare merged 4 commits intoActivityWatch:masterfrom
TimeToBuildBob:fix/config-port

Conversation

@TimeToBuildBob
Copy link
Contributor

@TimeToBuildBob TimeToBuildBob commented Feb 28, 2026

Summary

  • Reads the port from server config instead of hardcoding 5600/5666
  • Supports both aw-server-rust and aw-server (Python) configs
  • Falls back to defaults if config doesn't exist or port isn't explicitly set
  • Fixes the issue where "Open Dashboard" always opens port 5600 regardless of server config

Fixes #79

Changes

  • config.py: Refactored into _read_server_rust_port() and _read_aw_server_port() helpers, coordinated by _read_server_port(); exposed as AwQtSettings.port
    • aw-server-rust: reads ~/.config/activitywatch/aw-server-rust/config.toml (or config-testing.toml)
    • aw-server: reads ~/.config/activitywatch/aw-server/aw-server.toml ([server] or [server-testing] section)
    • Priority: aw-server-rust → aw-server → hardcoded default
  • main.py: Passes config.port to trayicon.run()
  • trayicon.py: Accepts port parameter instead of hardcoding the value

Test plan

  • Verify default behavior unchanged (port 5600 when no custom config)
  • Set port = 5700 in ~/.config/activitywatch/aw-server-rust/config.toml and verify tray icon opens correct URL
  • Set port = 5700 in [server] section of ~/.config/activitywatch/aw-server/aw-server.toml and verify tray icon opens correct URL
  • Verify testing mode uses correct config files and defaults to 5666

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 2c498cf in 10 seconds. Click for details.
  • Reviewed 104 lines of code in 3 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_e0Zla4YJDPj4l74g

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 28, 2026

Greptile Summary

This PR successfully fixes the hardcoded port issue by reading the port configuration from server config files. The implementation cleanly refactors port reading into separate helper functions with proper priority (aw-server-rust → aw-server → defaults) and includes appropriate error handling and fallbacks.

  • Properly prioritizes aw-server-rust config over aw-server (Python) config
  • Correctly handles testing mode with different config files and default ports
  • Includes defensive fallback in trayicon.py for backward compatibility
  • Uses int(str(...)) conversion for tomlkit Item types (mypy compatibility)
  • Gracefully handles missing config files and parsing errors with logging

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The implementation is clean, well-structured, and handles all edge cases properly. Error handling is appropriate with fallback behavior, and the code maintains backward compatibility. The recent commits show that type issues were already addressed.
  • No files require special attention

Important Files Changed

Filename Overview
aw_qt/config.py Added port reading logic from aw-server-rust and aw-server configs with proper fallbacks
aw_qt/main.py Passes config.port to trayicon.run() - simple integration change
aw_qt/trayicon.py Accepts port parameter instead of hardcoding, maintains backward compatibility with fallback

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[aw-qt starts] --> B[AwQtSettings.__init__]
    B --> C[_read_server_port]
    C --> D{Check aw-server-rust config}
    D -->|port found| E[Return rust port]
    D -->|not found| F{Check aw-server config}
    F -->|port found| G[Return Python port]
    F -->|not found| H[Return default<br/>5600 or 5666]
    E --> I[config.port set]
    G --> I
    H --> I
    I --> J[main.py passes port to trayicon.run]
    J --> K[TrayIcon.__init__ receives port]
    K --> L[Constructs root_url with port]
    L --> M[Open Dashboard uses correct URL]
Loading

Last reviewed commit: a0cbfda

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.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ErikBjare
Copy link
Member

Only reads aw-server-rust config. Servers should probably manage these defaults themselves (with --testing support), not have aw-qt reading server configs.

@TimeToBuildBob
Copy link
Contributor Author

Fair point. The ideal approach would be for aw-server-rust to write a runtime port file on startup (e.g. ~/.local/state/activitywatch/aw-server/port) that aw-qt reads — keeping the server as the source of truth for its own config.

However, that requires changes to aw-server-rust, and this PR at least fixes the concrete problem (hardcoded 5600) with a reasonable fallback chain. Should I:

  1. Keep this PR as-is as an incremental improvement, or
  2. Close this and open a server-side PR to have aw-server-rust write a port file, then have aw-qt read that instead?

Option 2 is cleaner architecturally but requires cross-repo coordination. Option 1 works today and can be replaced later.

@ErikBjare
Copy link
Member

Oh, I misunderstood when I wrote:

Servers should probably manage these defaults themselves (with --testing support), not have aw-qt reading server configs.

I thought this was setting explicit --port for started servers, but I see now this is about the "Open Dashboard" using whichever port is configured. I see two ways of solving this: read aw-server (e.g. the two server and server-testing sections in ~/.config/activitywatch/aw-server/aw-server.toml) & aw-server-rust (~/.config/activitywatch/aw-server-rust/config.toml & ~/.config/activitywatch/aw-server-rust/config-testing.toml) configs (respectively, depending on running server), or somehow detect which port the running server is bound to (might be easy on Linux/macOS systems with lsof, could be trickier on Windows).

Given my misunderstanding, complete this PR (should support both aw-server and aw-server-rust).

@ErikBjare
Copy link
Member

@TimeToBuildBob Get going

Test User and others added 2 commits March 2, 2026 16:23
Reads the port from aw-server-rust's config.toml (or config-testing.toml)
so that users running on a non-default port get the correct dashboard URL
when clicking "Open Dashboard" in the tray icon.

Falls back to the defaults (5600/5666) if the config file doesn't exist
or can't be parsed.

Fixes ActivityWatch#79
Extends port detection to support both aw-server and aw-server-rust:
- aw-server-rust: ~/.config/activitywatch/aw-server-rust/config.toml
- aw-server: ~/.config/activitywatch/aw-server/aw-server.toml ([server]/[server-testing] sections)

Tries aw-server-rust first, falls back to aw-server, then to hardcoded defaults.
@TimeToBuildBob
Copy link
Contributor Author

Done — extended to support both server types:

  • aw-server-rust: ~/.config/activitywatch/aw-server-rust/config.toml (or config-testing.toml)
  • aw-server: ~/.config/activitywatch/aw-server/aw-server.toml ([server] / [server-testing] sections)

Priority is aw-server-rust → aw-server → default. Also rebased onto master.

@ErikBjare
Copy link
Member

@greptileai review

@ErikBjare ErikBjare merged commit 2074cbf into ActivityWatch:master Mar 2, 2026
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.

Use port from config

2 participants