Skip to content

fix(menubar): open dashboard on configured port, not hardcoded 9211#66

Merged
prakersh merged 1 commit intomainfrom
claude/investigate-issue-65-1YV9n
Apr 23, 2026
Merged

fix(menubar): open dashboard on configured port, not hardcoded 9211#66
prakersh merged 1 commit intomainfrom
claude/investigate-issue-65-1YV9n

Conversation

@prakersh
Copy link
Copy Markdown
Contributor

Summary

Fixes #65. On macOS, clicking "Open Dashboard" inside the menubar popover opened http://localhost:9211 regardless of the configured port, so users running with ONWATCH_PORT=7777 (or --port) got a dead URL.

The bug was a single hardcoded literal in internal/menubar/popover_darwin.m:429:

NSURL *url = [NSURL URLWithString:@"http://localhost:9211"];

The Go-side tray menu item ("Open Dashboard" via right-click) was already correct - it goes through c.dashboardURL() which honors cfg.Port. Only the popover's in-page button was broken.

Approach

Derive the dashboard origin from the WKWebView's own loaded URL rather than threading the port through CGO or accepting one from JS:

NSURL *current = self.webView.URL;                           // http://localhost:<cfg.Port>/menubar
NSURLComponents *c = [NSURLComponents componentsWithURL:current
                                 resolvingAgainstBaseURL:NO];
c.path = @""; c.query = nil; c.fragment = nil;
NSURL *dashboardURL = c.URL;                                 // http://localhost:<cfg.Port>

Why this over alternatives:

  • vs. hardcoded default: follows the actual runtime port, not a compile-time constant.
  • vs. reading ONWATCH_PORT env in Obj-C: env is a config input; the webview's origin reflects the resolved port (after flag override, auto-fallback, etc.). Env-reading would also duplicate Go's resolution rules in C.
  • vs. new CGO setter pushing cfg.Port into Obj-C state: no new C symbols, no second copy of the port to keep in sync, no ordering rule ("call setter before show"). The WKWebView already holds the authoritative URL.
  • vs. letting JS send the URL in the postMessage body: no JS contract change, and we don't trust page-supplied URLs.

isLocalURL: (already present in this file) still guards against a non-local origin.

Test plan

  • go vet ./... clean.
  • go test -race -count=1 ./internal/menubar/... ./internal/web/... passes (the web package asserts the JS still fires sendNativeAction("open_dashboard") - unchanged).
  • Audited remaining 9211 and open_dashboard references - only the legit DefaultConfig() default, CLI banner tests, marketing copy, and the action-name string itself remain.
  • Requires macOS verification - the modified file is //go:build menubar && darwin && cgo, so Linux can't compile or exercise the Obj-C path. Manual check needed: run ONWATCH_PORT=7777 onwatch, open the menubar popover, click "Open Dashboard", confirm the browser opens http://localhost:7777 (not :9211).

Fixes #65


Generated by Claude Code

The macOS menubar popover's "Open Dashboard" button used a hardcoded
http://localhost:9211 URL, ignoring ONWATCH_PORT / --port. If the user
ran onWatch on any other port (e.g. 7777), clicking Open Dashboard in
the popover opened a dead URL.

Fix by deriving the dashboard origin from the WKWebView's own current
URL (which was loaded from http://localhost:<cfg.Port>/menubar by the
Go side) and stripping path/query/fragment. No new CGO symbol, no JS
contract change, no second copy of the port to keep in sync - the
webview's loaded origin is already the authoritative value.

Fixes #65
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@prakersh prakersh merged commit b73f913 into main Apr 23, 2026
6 checks passed
@prakersh prakersh deleted the claude/investigate-issue-65-1YV9n branch April 23, 2026 23:02
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.

The port of the dashboard from menu bar is fixed with 9211 on mac.

2 participants