onWatch icon indicating copy to clipboard operation
onWatch copied to clipboard

feat: Linux menubar companion (GTK3 + WebKitGTK)

Open prakersh opened this issue 8 months ago • 2 comments

Summary

Ports the macOS-only menubar companion to Linux using CGO + GTK3 + WebKitGTK. The existing architecture already uses fyne.io/systray (which supports Linux via libayatana-appindicator3), so the main work is implementing the native popover window and extracting shared code from darwin-only build tags.

  • Extracts platform-agnostic companion logic into shared companion_unix.go (was companion_darwin.go)
  • Implements GTK3 popup window + WebKitGTK WebView for the Linux popover (same HTML/CSS/JS frontend)
  • Produces two Linux binary variants: headless (existing, no CGO) and desktop (with menubar)
  • macOS behavior unchanged - verified by building and running on macOS with all tests passing

Testing on Linux

Prerequisites

Ubuntu 22.04+ or Debian Bookworm+ (for webkit2gtk-4.1).

sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libayatana-appindicator3-dev

On Fedora 38+:

sudo dnf install -y gtk3-devel webkit2gtk4.1-devel libayatana-appindicator-gtk3-devel

Build

# Desktop build (with menubar)
CGO_ENABLED=1 go build -tags menubar,desktop,production \
  -ldflags="-s -w" -o onwatch .

# Headless build (no menubar, no CGO - unchanged)
CGO_ENABLED=0 go build -ldflags="-s -w" -o onwatch .

Or use the build script (auto-detects GTK/WebKit):

./app.sh --build

Run

./onwatch --debug
# Tray icon should appear in GNOME/KDE panel
# Click tray icon -> popover with quota dashboard
# Click outside popover -> dismisses

Run tests

# Headless (xvfb required for GTK tests)
xvfb-run go test -tags menubar -race ./internal/menubar/...

# Or without menubar tag (tests shared code only)
go test -race ./...

Test plan

  • [ ] macOS: ./app.sh --build && ./app.sh --test - no regressions
  • [ ] macOS: menubar companion starts, popover opens/closes, tray icon updates
  • [ ] Linux (GNOME): desktop build produces tray icon in panel
  • [ ] Linux (GNOME): clicking tray icon opens popover with dashboard
  • [ ] Linux (GNOME): clicking outside popover dismisses it
  • [ ] Linux (KDE): same as GNOME checks above
  • [ ] Linux: headless build works without GTK libs installed
  • [ ] CI: xvfb-run go test -tags menubar -race ./internal/menubar/... passes on ubuntu-latest

Reporting issues

If something doesn't work on your Linux setup, please open an issue with:

  1. Distro and version (cat /etc/os-release)
  2. Desktop environment (GNOME, KDE, etc.)
  3. Build command used
  4. Debug logs: ./onwatch --debug 2>&1 | head -100

Important: Mask any API keys before sharing logs or config files. Replace key values with *** in .env files and log output.

Runtime dependencies (Linux desktop variant)

  • libayatana-appindicator3-1 (system tray)
  • libwebkit2gtk-4.1-0 (WebView rendering)
  • libgtk-3-0 (windowing)

prakersh avatar Mar 18 '26 04:03 prakersh

Codecov Report

:x: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
menubar_runtime.go 0.00% 1 Missing :warning:

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Mar 18 '26 05:03 codecov[bot]

Starting the review now, gonna send updates soon

xyz-rainbow avatar Mar 18 '26 05:03 xyz-rainbow