Skip to content

Menu bar: size columns from measured text; name the local connection per platform - #195

Merged
fylorn merged 2 commits into
devfrom
fix/menubar-text-and-local-name
Sep 25, 2026
Merged

fylorn merged 2 commits into
devfrom
fix/menubar-text-and-local-name

Conversation

@fylorn

@fylorn fylorn commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Two bugs found while shooting the English product screenshots.

1. Overlapping text in the English menu bar menu

The custom rows in src-tauri/src/menubar/macos.rs assumed widths that only the Chinese strings fit:

Row Assumed English text Result
Quota reset column 92 pt "Resets in 3 days" 92.2 pt, "Resets in 42 min" 93.8 pt 31%Resets in 3 days
Today three equal cells of 93.3 pt "Requests" + "4 failed" = 93.7 pt Requests 4 failedTokens

The fix measures the text instead:

  • Quota rows: the window-name and reset columns are sized from the widest strings across every quota row in the menu, so bars stay aligned across providers. Neither column is ever narrower than before (50 pt and 92 pt). The bar takes what is left, down to 40 pt. Past that, the reset text is cut with an ellipsis.
  • Today: cells stay equal while everything fits. A cell that needs more gets its width and the others split the rest. If nothing fits, the widths follow the content and the text is cut inside its cell (share_columns).
  • In the same spirit, the header title (a remote server's name can be any length) and the name in an in-progress row are cut before the text on their right instead of running under it.
  • fit() (the ellipsis helper behind draw_clipped) allows 0.001 pt of floating-point error. A column computed as width + gap − gap can otherwise come out a hair short and cut text that fits ("4 fai…").

The Chinese layout is unchanged. Every Chinese string fits the old minimum widths. menubar_preview --png for all five states renders byte-identical Chinese PNGs before and after, along with every English state that has no quota or failure note.

Verification (English, alert state, ink runs measured on the rendered PNG; no screenshots attached):

  • Quota rows: before, 63% and Resets formed one run. After, 63% ends at 189.5 pt and Resets starts at 202.8 pt (a 13.2 pt gap). 100% and Resets in 42 min now have an 11.5 pt gap.
  • Today: before, failed and Tokens formed one run. After, there is an 11.2 pt gap.
  • The screenshot scene (menubar_shots from docs: product screenshots from a committed, deterministic pipeline #189, --today 11200000 9870000 214 4) shows the same result: 31% then an 11.5 pt gap before Resets in 3 days, and 4 failed then an 11 pt gap before Tokens.

New tests in menubar::macos measure real AppKit text. English reset times must leave TEXT_GAP after the percentage. The failure note must stay inside its cell in both languages. The Chinese columns must equal the old constants. Two more tests cover share_columns and fit. Reverting to the fixed widths makes both English tests fail: "Resets in 42 min" starts 1.8 pt inside the percentage, and the "Requests / 4 failed" cell does not fit in 93.3 pt.

2. "This Mac" on Windows and Linux

The Rust side named the built-in connection tr!("本机", "This Mac") on every platform. The English Connection submenu of the Windows and Linux tray therefore read "This Mac". The name now comes from a single function, connection::store::local_name():

  • "This Mac" on macOS
  • "This computer" on Windows and Linux
  • "本机" in Chinese on every platform

It is used by the connection list (connection::view), the menu bar and tray submenus (they read that list), and the local-connection errors in connector::test. The menubar_preview snapshot uses it too.

The interface still writes the local name itself (connText.local, same wording) so a language switch applies at once. The following changes make it consistent:

  • Every place that shows a connection's name now goes through profileName(). This includes the switch dialog (titles, the retarget report, the toast and the checkbox), the not-connected page (titles) and the delete confirmation.
  • The local name is defined once in connection.i18n.tsx (localZh / localEn, used by local and startupLocal).
  • A vitest case checks that profileName ignores the Rust-provided name for the local profile and writes "This computer" off macOS.

menubar_preview sub --en --dump now lists Connection → ✓ This Mac. The Rust test asserts "This Mac" on macOS and "This computer" on the Windows and Linux CI jobs.

Rebase note

The branch was rebased onto dev after #194 merged. In SwitchDialog.tsx, the two lines both PRs touched keep #194's notify.success(...) and disabled={busy} and use name for the connection name.

Checks run locally

  • bash scripts/version.sh, pnpm typecheck, pnpm build, pnpm test (321 passed)
  • cargo fmt --all --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test (404 passed; control_plane ran against twcore 0.47.0)

🤖 Generated with Claude Code

@fylorn
fylorn force-pushed the fix/menubar-text-and-local-name branch from 34b1b46 to a6a1353 Compare September 25, 2026 00:05
fylorn and others added 2 commits September 25, 2026 08:10
The quota rows assumed a 92 pt reset column and the Today row split its
width into equal thirds. Both fit the Chinese strings, but English runs
past them: "Resets in 3 days" (92.2 pt) and "Resets in 42 min" (93.8 pt)
ran into the percentage ("31%Resets in 3 days"), and "Requests 4 failed"
(93.7 pt) ran into the next cell ("Requests 4 failedTokens").

- Quota rows: the window-name and reset columns are measured, across
  every quota row in the menu so the bars stay aligned, and never
  narrower than before. The bar takes what is left, down to 40 pt;
  past that the reset text is cut with an ellipsis.
- Today: cells stay equal while everything fits. A cell that needs more
  gets its width and the others share the rest; if nothing fits, the
  widths follow the content and the text is cut within its cell.
- The header title (a remote server's name) and the name in an
  in-progress row are cut before the text on their right instead of
  running under it.

The Chinese strings all fit the old minimum widths, so the Chinese
menu renders byte-for-byte the same as before (checked on every
menubar_preview state).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Rust side named the built-in connection tr!("本机", "This Mac") on
every platform, so the Connection submenu of the Windows and Linux tray
said "This Mac" in English. The name now comes from one function,
connection::store::local_name(): "This Mac" on macOS, "This computer"
elsewhere, "本机" in Chinese everywhere. The connection list, the tray
and menu bar submenu and the local connect errors all use it, and the
menu bar preview shows it.

The interface keeps writing the local name itself (connText.local, same
wording) so it follows a language switch at once. Every place that
shows a connection's name now goes through profileName(), including
the switch dialog and the not-connected page, and the local name is
defined once in connection.i18n.tsx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn force-pushed the fix/menubar-text-and-local-name branch from a6a1353 to 8d43211 Compare September 25, 2026 00:12
fylorn added a commit that referenced this pull request Sep 25, 2026
Generated with `pnpm shots` on dev at 3b8638e (after the Keys, Clients,
Routing, Upstreams, Settings, Traffic and Overview redesigns, #190-#199),
core v0.47.0. Two complete runs produce byte-identical files.

- `{zh,en}/<scene>-{light,dark}.png`: 13 scenes, 2360x1540.
- `menubar-{light,dark}.png` (178x64) and `{zh,en}/menubar-menu-*.png`
  (664x1120).
- `web/`: the website variants (WebP from the dark images, and the dark
  menu bar item as PNG).

The English menu images were drawn with the menu bar layout fix from
#195 applied, which this branch does not contain: without it, "Resets in
3 days" and "4 failed" run into the text beside them. Every other image,
including the Chinese menus, is the same with or without that fix.

The old images and the README references are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 44ee413 into dev Sep 25, 2026
4 checks passed
@fylorn
fylorn deleted the fix/menubar-text-and-local-name branch September 25, 2026 01:46
fylorn added a commit that referenced this pull request Sep 25, 2026
)

* build(shots): regenerate the product screenshots from the real interface

The screenshots in docs/screenshots/ were taken with a pipeline that
lived in an ignored local directory and was lost. This one is in the
repository and runs with one command, `pnpm shots` (macOS only):

- scripts/shots/ is a separate Vite entry that mounts src/main.tsx on
  mocked IPC. It is not part of the app build, and src/index.css now
  keeps scripts/ out of Tailwind's source scan, so the app bundle is the
  same with or without it.
- The configuration views (upstreams, keys, routes, security rules,
  prices, dry runs) are what the pinned core answers for a demo
  configuration, stored in scripts/shots/core/ and regenerated by
  oracle.sh. Masking, detected protocols, rule flags and prices are
  therefore core's own, and sentences carry their real message codes.
- The clock is fixed and the traffic comes from a fixed seed, so two
  runs write byte-identical files.
- capture.swift renders each scene in the system WKWebView, the engine
  the app uses on macOS, and frames it as a macOS 26 window.
- examples/menubar_shots.rs draws the menu bar item and its menu with
  the app's own rendering code, at exactly 2x.
- finish.mjs writes 256-colour PNGs to docs/screenshots/ and the
  website's WebP variants to docs/screenshots/web/. sharp is a new dev
  dependency; its install script is not needed and not allowed to run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(shots): follow the redesigned pages and catch mock drift in CI

The Keys and Clients redesign (#190) changed `key_usage` to take
`{sinceMs, bucketMs}` and return `KeyUsage`, and `upstream_stats` gained
hourly buckets. The mock still answered the old shapes, and nothing
failed: its command handlers returned `unknown`, so the pages rendered
error states that the capture accepted.

- Every Tauri command handler now returns the type the interface reads
  (`KeyUsage`, `UpstreamStats`, `Dashboard`, `ConnView`, ...), and the
  stored core answers are checked against the core types. `pnpm
  typecheck`, which CI runs, now includes `scripts/shots/`, so a changed
  generated type fails the Frontend job. It already caught the Overview
  redesign (#196) dropping `history` from `Dashboard`.
- At capture time, a command the mock does not answer or one called
  without the arguments it expects is logged as an error and stops the
  run, instead of falling back to a default time window.
- `key_usage` and `upstream_stats` return totals plus sparse buckets, as
  tw-store's `cost_by` / `cost_buckets_by` do; `input_tokens` in the
  totals no longer includes cache reads and writes. `dashboard` computes
  latency over the same window as the summary, with tw-store's
  percentile rule, as dashboard.rs now asks for.
- The menu bar images take the page's fixed clock (`--now`) instead of
  the system clock, so runs on different days are byte-identical. Run on
  its own, `menubar_shots` uses the same instant.
- A scene with a table that does not fit the window fails instead of
  being captured with its last columns cut off. The MCP scene collapses
  the sidebar so the six client columns fit.
- Demo configuration: every secret keeps the first 5 and last 4
  characters shown in the masked views, with EXAMPLE in the middle (zeros
  for the hex control key). Cursor's key gets its own route to a
  `cheapest` group, so the routing page has three routes and three
  groups; the core answers are regenerated with oracle.sh (core v0.47.0).
- Review fixes: the hidden-text event counts 74 characters, the length of
  the text it reveals; the remote MCP finding uses tw-scan's rule id
  `remote-mcp`; CONTRIBUTING names `fetch-core.sh` and uses US spelling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(screenshots): add screenshots of the current interface

Generated with `pnpm shots` on dev at 3b8638e (after the Keys, Clients,
Routing, Upstreams, Settings, Traffic and Overview redesigns, #190-#199),
core v0.47.0. Two complete runs produce byte-identical files.

- `{zh,en}/<scene>-{light,dark}.png`: 13 scenes, 2360x1540.
- `menubar-{light,dark}.png` (178x64) and `{zh,en}/menubar-menu-*.png`
  (664x1120).
- `web/`: the website variants (WebP from the dark images, and the dark
  menu bar item as PNG).

The English menu images were drawn with the menu bar layout fix from
#195 applied, which this branch does not contain: without it, "Resets in
3 days" and "4 failed" run into the text beside them. Every other image,
including the Chinese menus, is the same with or without that fix.

The old images and the README references are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shots: wait for the traffic table's deferred render before capturing

The table body renders through useDeferredValue; on a busy machine the
capture's idle and stable-snapshot checks pass before that render commits,
and the scene is shot with only the in-flight row while the run succeeds.
Wait until the table has its rows. Images are unchanged at normal speed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Sep 25, 2026
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.

1 participant