tray: a card with more than two windows shows them all, in columns of two (jen_celeus on X)

This commit is contained in:
yetone
2026-11-15 01:11:08 +08:00
parent e513cba54a
commit 1edebf0500
7 changed files with 183 additions and 27 deletions
+1 -1
View File
@@ -690,7 +690,7 @@ covers it in both engines, every language and a narrow window.
- The menu bar can show magpie's own totals beside the allowances (#1984): `usage:today` and `usage:7d` in `settings.TrayUsages`, offered after the cards in the same picker. `trayUsageCards` sums them with `usage.QueryPage(p, Filter{}, 0, 1).Sum` (the Requests tab's and the panel's cached ledger sum, gateway and session-file calls together) and asks no vendor when only totals are picked; `trayTotalCard` makes every token (in, out and cache, as `allTokens`), marked `Σ` so it doesn't read as the input, over the cost in Settings' currency (with *By provider*, `settings.CurrencyByProvider`, in the currency picked for totals, `TotalCostIn`: a sum of every provider has no one currency of its own; Settings › Usage › Advanced › *Menu bar currency*, `settings.TrayCurrency`, per computer through `KeepOwn`, sets the menu bar's and its tooltip's apart, `TrayCostIn`, while Bark's daily message stays in the totals'; the currency rows are drawn by `currencyprefs.js`, imported when Settings draws its usage prefs), `+` when some calls had no price, the cost row left out when none had one. The Mac draws them as plain cells, the bird beside them saying whose. A click opens the Requests tab at the period (`quotaView`, `?tab=requests&period=`) or the panel's Usage tab (`panelUseFocus`). No 3-day total: the Usage page has no such window. See `TestTrayTotals` and `tray-totals.test.cjs`. With *By provider*, the tray panel's Usage tab and the Requests tab show each cost that is one provider's in that provider's currency (`ledProv` in app.js): a ranking row and its line in the chart's tooltip, a model every provider of which sells in one currency (from `by.modelAt`), and the whole page while it is filtered to one provider (`Ledger.provider`, `usageapi.LedgerPage`); a sum, the chart's axis and a model served in both currencies are in the totals' (onkashiko on X; `TestLedgerSaysItsOneProvider`, `panel-currency-provider.test.cjs`). Settings › *Menu bar cost* (`settings.TrayNoCost`, on by default, on every OS, per computer through `KeepOwn`) turned off leaves the money out (BussanQ on Discord): `trayMoney` drops the total's cost and its count of unpriced calls before `trayTotalCard` and the no-card tooltip `trayIdleTip` see it, so the cards, their tooltip and the idle tooltip say the tokens and requests alone. A relay's or subscription's balance card is money itself and stays. See `TestTrayNoCost` and `tray-cost.test.cjs`.
- The tray's icon is the bird alone where the bar's other icons are glyphs: the Mac's menu bar takes `tray.png` as a template image, and a Linux bar (StatusNotifierItem `IconPixmap`) gets the same silhouette in one colour on transparency (`trayIconFor`, `linuxTrayIcon` in [`trayglyph.go`](../../internal/gui/trayglyph.go)), so a bar that tints its icons by their alpha tints the bird, not a tile (ylorn on Discord). A bar that doesn't tint shows it light, or dark when the portal's `org.freedesktop.appearance` `color-scheme` prefers light (`traySchemeLight`), and it is drawn again when that changes (`watchTrayScheme`). No `IconName` is set: a host that found a `-symbolic` name and drew it untinted would show a black bird on a dark bar, with no pixmap to fall back on. Windows' tray keeps the app's coloured icon, unless a card is in the menu bar: Windows' notification area shows no text beside an icon, so the icon itself is the first card's figure (Benjaminliang_1 on X; `trayIconFigure`, `trayNumberIcon` in [`traynumber.go`](../../internal/gui/traynumber.go)). It is the first row of the first card whose first row is a percentage, used or left as Allowance display has it, through *Menu bar windows*' pick, its digits alone, drawn in Segoe UI Semibold (Go's bold where the font can't be read) at `SM_CXSMICON`, white on a dark taskbar and near black on a light one, as tall as fits with a pixel above and below, centred by its ink, and three digits narrowed into the square. A balance or magpie's totals are skipped for the next card; with none the icon is the bird. It is drawn again when the figure, the icon size or the taskbar's theme changes (`SystemThemeChanged` wakes the loop); the tooltip still says every card. Settings › *Tray icon number* (`settings.TrayNoNumber`, Windows' alone, on by default) keeps the bird when off. One icon is set for the current theme, not a light and a dark one: Wails' Windows tray shares one handle between them. Linux keeps its label and tooltip; the Mac its cells. See `TestTrayIconFigure`, `TestTrayNumberIcon` and `tray-windows.test.cjs`. With no cards in the menu bar the tooltip is magpie over today's total (`trayIdleTip`: every token, split into input, output and cache as the today card's tooltip is, then the cost and the requests), brought up to date with the cards' refresh; the tray's menu stays Open, the version and Quit. Wails sets the tooltip only on Windows: on Linux `setTrayTip` sets the StatusNotifierItem's `ToolTip` and sends `NewToolTip` ([`traytip_linux.go`](../../internal/gui/traytip_linux.go)), and on the Mac it is the status item's button's `toolTip` (`trayTipNative` in [`trayimage_darwin.go`](../../internal/gui/trayimage_darwin.go); NextCommit on Discord: no hover there showed anything). See `TestTrayIconPerOS`, `TestTrayIdleTip` and `TestMacTrayTipIsSet`. Every tooltip, the idle one, magpie's totals' and each card's (its use or what is left, the pace, when it resets, "as of …"), is in magpie's language, as the tray menu is: `watchTrayUsage` passes `trayLang(settings.Lang, systemLang)` to `trayCardsView`, `trayUsageCards` and `trayIdleTip`, whose words are in `trayWords` beside the menu's, and a change of language in Settings refreshes it at once (`onTrayUsage`). A window's name and an error are the card's own (yi_time on Discord: English on a Windows magpie set to Chinese; `TestTrayTooltipFollowsMagpiesLanguage`).
- A window's Pace is a number on its card's reset line (fflake33 on Discord): the share used less the share of the window gone by, in points, "Pace +12%" over an even pace and "−8%" under it, turned with the meter when it shows what is left, amber while more is used than an even pace would have (`quotaPace`, `paceLine`). The window's start is the gateway's, `startsAt` from `provider.WithWindowStarts` (its reset less its span, `QuotaWindow.Bounds`); a window whose span isn't known, with no limit, or a past cycle has none. Settings › *Menu bar pace* (`settings.TrayPace`, off by default, hidden on Windows, whose tray shows no text but the first card's figure as its icon) puts the same number beside each figure in the menu bar and in its tooltip (`trayPace`, `QuotaWindow.Pace`). See `TestWindowPace`, `TestTrayUsagePace` and `quota-pace.test.cjs`.
- Settings › *Menu bar windows* (`settings.TrayWindows`, StrikingRaw on X) picks which of a subscription's windows its menu bar card shows, keyed by provider id (every account of it, the in-use `|*` card too) and by window kind, not position: `trayWindowKind` names a window by its span ("5h", "1d", "7d", "month", "15m"), by `name:` its name when the span isn't known. Unset shows every window, as before; a pick none of whose kinds the card still has shows every window again (`trayShownKinds`), never an empty card. Only the bar's rows, the Linux label and Windows' icon figure are filtered; the tooltip still says every window. One row draws in the menu bar's own font (13pt regular), two stacked rows in 10pt regular, both with digits of one width (`mpRowFont`, `TestTrayRowFont`; qingnianxiaozhe on X found the old 9.5pt semibold and 11pt medium heavier than Surge's and iStat Menus' figures beside them). The GUI learns the kinds from `trayKind` on `/api/usage/quotas` (`withTrayKinds`; model and aside windows get none). The row lists a pill per ticked subscription with two or more kinds, opening the app's menu (All windows, then each kind), shown on Windows too, where the first card's pick decides the tray icon's figure; its code is in `traywindows.js`, imported when Settings draws ticked cards. Per computer through `KeepOwn`. See `TestTrayWindowsPicked`, `TestTrayWindowsKept` and `tray-windows.test.cjs`.
- Settings › *Menu bar windows* (`settings.TrayWindows`, StrikingRaw on X) picks which of a subscription's windows its menu bar card shows, keyed by provider id (every account of it, the in-use `|*` card too) and by window kind, not position: `trayWindowKind` names a window by its span ("5h", "1d", "7d", "month", "15m"), by `name:` its name when the span isn't known. Unset shows every window, as before; a pick none of whose kinds the card still has shows every window again (`trayShownKinds`), never an empty card. Only the bar's rows, the Linux label and Windows' icon figure are filtered; the tooltip still says every window. Every window shown is drawn, not the first two (jen_celeus on X: Antigravity's four windows, two in the bar): a card with more than two has them in columns of two stacked rows, `mpColGap` apart, the shortest windows in the first column, a third alone on its column's top line (`mpRows`, `TestTrayImageColumns`, `TestTrayEveryWindow`); the Linux label lists them all. One row draws in the menu bar's own font (13pt regular), two or more stacked rows in 10pt regular, both with digits of one width (`mpRowFont`, `TestTrayRowFont`; qingnianxiaozhe on X found the old 9.5pt semibold and 11pt medium heavier than Surge's and iStat Menus' figures beside them). The GUI learns the kinds from `trayKind` on `/api/usage/quotas` (`withTrayKinds`; model and aside windows get none). The row lists a pill per ticked subscription with two or more kinds, opening the app's menu (All windows, then each kind), shown on Windows too, where the first card's pick decides the tray icon's figure; its code is in `traywindows.js`, imported when Settings draws ticked cards. Per computer through `KeepOwn`. See `TestTrayWindowsPicked`, `TestTrayWindowsKept` and `tray-windows.test.cjs`.
- In Usage → Allowances, Trends → Cycle offers each account's own recorded cycle menu beside its curve (`quotaCurve`, `quotaRecordedCycles` in [`app.js`](../../internal/gui/assets/app.js)). The longest window (usually weekly) owns the menu; shorter windows are drawn over the selected dates with their own reset breaks. `/api/usage/quotas/history?days=45` supplies all retained readings, including remote cards. Completed cycles come from observed boundaries, not seven-day arithmetic; an early reset ends the previous cycle at the vendor's new start if it fits between readings, otherwise at the first new reading. Each menu option gives its observed duration, so an early reset is not labelled as a full seven days. The selected meters, plot, legend, tooltip and dashed pace use that cycle's last readings, never today's percentages. A window without a reading in the selected interval says so instead of showing a current value. A local account's past cycle asks `/api/usage/quotas/history/holds?provider=&user=&from=&to=` once per selection (`quotaCycleHoldsOf`), which asks no vendor (#2009, NorethSea): `HistoricalWindowHolds` in [`window_holds_history.go`](../../internal/usage/window_holds_history.go) reckons each window's whole at its own last reading in that cycle, from the request log up to that reading, so the 5-hour figure is the cycle's last 5-hour window, never its short windows added up. Its tooltip names that window's start and the reading's time. It shows "Loading…" until the answer comes. A window it can't reckon says "not enough data" with the reason, as a current card does; a reply that comes after another cycle was picked is dropped, and a card's Refresh or an asked read reckons again. Historical meters show the cycle end and sampling time; current account actions, balances and policies are left out until returning to the current view. Accounts are independent, and a selection survives card refreshes in the same page. Trends → 2 days temporarily shows recent readings; Off removes the curves; the tray always shows its current cycle. See `quota-curve.test.cjs` and the [history limits and reset inference](providers-accounts.md#constraints-and-failure-behavior).
- The Usage page's cards are packed into columns, never all stretched to a row's height (`packUsage`, #860): each card in that order goes to the leftmost column that ends highest, on 1px grid rows, so short cards stack beside a tall one. Every card is as tall as what it holds, the last in a column too: ikunbots on X had each column's last reach down to the tallest's end, which left a card with no windows (OpenCode Zen) as tall as Claude's beside it, mostly empty, and jen_celeus on X asked for cards as tall as their content. A head with nothing under it keeps no margin below. The page's order (DOM, dragging, Alt+arrows) stays `UsageOrder`. The column count is the most 260px columns that fit, or one fewer when that leaves much less empty room; it is chosen again only when the cards change or the width fits another number of columns, so a card opened or folded stays where it is, even as the scrollbar comes in. See `usage-pack.test.cjs`.
- The Providers page has a search box over its list (#1614, `findProviders` in [`app.js`](../../internal/gui/assets/app.js)): the words typed keep the rows, on and off, whose text or data say them all: name, id, preset, addresses, every model's id and name, the account's user and plan and each login's, account names and key names. The Turned off fold stays open while searching; Escape or clearing the box shows every row and the fold as it was. A row that is on reorders by dragging its logo, Alt+↑/↓, Alt+Shift+↑/↓ (top, bottom) or its right-click menu (`openProviderMenu`: Move to top, Move up, Move down, Move to bottom). While searching, a step or a drop moves it among the rows shown (it takes the place of the row it passes, `stepProvider`, `shownToOn`) and the hidden ones keep their order; Move to top and Move to bottom go to the ends of the whole list. Every move saves the whole order through `POST /api/providers/arrange`. See `provider-find.test.cjs` and `provider-order.test.cjs`.
+83
View File
@@ -0,0 +1,83 @@
package gui
import (
"bytes"
"image"
"image/png"
"os"
"path/filepath"
"testing"
"time"
"github.com/yetone/magpie/internal/provider"
)
// A card with four windows draws, through AppKit, two columns of two
// stacked rows (jen_celeus on X), in light and dark: as high as a card
// with two, up to about twice as wide, with a gap of no ink between its
// columns; with three, the third alone on the top line of its column.
func TestTrayImageColumns(t *testing.T) {
bird, err := os.ReadFile("tray.png")
if err != nil {
t.Fatal(err)
}
now := time.Date(2026, 11, 15, 3, 0, 0, 0, time.UTC)
q := antigravityPools()
four, _, _ := trayCardsView("en", []provider.SubscriptionQuota{q}, now, false, false, nil)
var kinds []string
for _, w := range withTrayKinds([]provider.SubscriptionQuota{q})[0].Windows {
kinds = append(kinds, w.TrayKind)
}
two, _, _ := trayCardsView("en", []provider.SubscriptionQuota{q}, now, false, false, map[string][]string{"antigravity": {kinds[1], kinds[3]}})
three, _, _ := trayCardsView("en", []provider.SubscriptionQuota{q}, now, false, false, map[string][]string{"antigravity": {kinds[1], kinds[3], kinds[0]}})
if len(four[0].Rows) != 4 || len(two[0].Rows) != 2 || len(three[0].Rows) != 3 {
t.Fatalf("rows %q %q %q", four[0].Rows, two[0].Rows, three[0].Rows)
}
out := os.Getenv("MAGPIE_TRAY_PREVIEW")
for _, dark := range []bool{false, true} {
_, w0, _ := trayImagePNG(nil, bird, 22, 2, dark, false)
_, w2, _ := trayImagePNG(two, bird, 22, 2, dark, false)
b, w4, h := trayImagePNG(four, bird, 22, 2, dark, false)
img, err := png.Decode(bytes.NewReader(b))
if err != nil || h != 44 {
t.Fatalf("dark %v: %v, %dx%d", dark, err, w4, h)
}
// the digits after the logo (14pt and 3pt, at 2x)
digits2, digits4 := w2-w0-34, w4-w0-34
if digits4 < digits2+30 || digits4 > digits2*2+20 {
t.Errorf("dark %v: four windows' digits are %d px wide, two's %d", dark, digits4, digits2)
}
left := image.Rect(w0+34, 0, w0+34+digits4/2-6, h)
right := image.Rect(w0+34+digits4/2+6, 0, w4, h)
if l, r := inkBands(img, left, dark), inkBands(img, right, dark); l != 2 || r != 2 {
t.Errorf("dark %v: the columns draw %d and %d lines, want 2 and 2", dark, l, r)
}
// a gap of no ink between the columns
gap := false
for x := w0 + 34 + digits4/4; x < w4-digits4/4; x++ {
if inkIn(img, image.Rect(x, 0, x+1, h), dark) == 0 {
gap = true
break
}
}
if !gap {
t.Errorf("dark %v: no gap between the columns", dark)
}
b3, w3, _ := trayImagePNG(three, bird, 22, 2, dark, false)
img3, _ := png.Decode(bytes.NewReader(b3))
top := inkIn(img3, image.Rect(w3-10, 0, w3, h/2), dark)
bottom := inkIn(img3, image.Rect(w3-10, h/2+2, w3, h), dark)
if top < 20 || bottom != 0 {
t.Errorf("dark %v: the third window's column: %d px of ink on top, %d below", dark, top, bottom)
}
if out != "" {
for name, cs := range map[string][]trayCell{"two": two, "three": three, "four": four, "plain": trayPlain(four)} {
bg, _, _ := trayImagePNG(cs, bird, 22, 2, dark, true)
f := filepath.Join(out, "tray-columns-"+name+map[bool]string{false: "-light.png", true: "-dark.png"}[dark])
if err := os.WriteFile(f, bg, 0o644); err != nil {
t.Fatal(err)
}
}
}
}
}
+36 -18
View File
@@ -16,16 +16,19 @@ typedef struct {
int plain; // no logo: the rows alone, a thin line before
const char *id;
const char *letter;
const char *rows; // one or two, a newline between
const char *rows; // one or more, a newline between
} mpTrayCell;
// Metrics, in points: the menu bar is 22 high (24 beside a notch), and a
// cell is a 14pt logo with its two windows beside it, stacked as small
// digits, each window's figures right-aligned over the other's. A cell
// digits, each window's figures right-aligned over the other's. A card
// with more windows than two (Antigravity's four, jen_celeus on X) has
// them in columns of two, mpColGap apart, the first two over each other
// as before, then the next two, the shortest windows first. A cell
// without its logo is the digits alone, a hairline mpSepGap either side
// between it and the one before.
static const CGFloat mpLogo = 14, mpLogoGap = 3, mpCellGap = 8, mpBirdGap = 2, mpRowGap = 3.5,
mpPlainGap = 3, mpSepGap = 5, mpSep = 1, mpSepHigh = 13;
mpColGap = 4, mpPlainGap = 3, mpSepGap = 5, mpSep = 1, mpSepHigh = 13;
// mpRowFont is the digits' font, in the weight the menu bar's other
// figures use (Surge's speeds, iStat Menus'): two stacked rows in the small
@@ -79,19 +82,28 @@ static NSArray *mpCells(mpTrayCell *cells, int n) {
c[@"mono"] = @(cells[i].mono != 0);
c[@"plain"] = @(cells[i].plain != 0);
c[@"letter"] = [NSString stringWithUTF8String:cells[i].letter ? cells[i].letter : ""];
NSArray *rows = [[NSString stringWithUTF8String:cells[i].rows ? cells[i].rows : ""] componentsSeparatedByString:@"\n"];
if (rows.count > 2) rows = [rows subarrayWithRange:NSMakeRange(0, 2)];
c[@"rows"] = rows;
c[@"rows"] = [[NSString stringWithUTF8String:cells[i].rows ? cells[i].rows : ""] componentsSeparatedByString:@"\n"];
[out addObject:c];
}
return out;
}
static CGFloat mpColumn(NSDictionary *c) {
// mpColWidth is the width of column j of a cell's digits: its rows 2j
// and 2j+1, or the one row of a card with one window.
static CGFloat mpColWidth(NSDictionary *c, NSUInteger j) {
NSArray *rows = c[@"rows"];
NSDictionary *attrs = @{NSFontAttributeName: mpRowFont((int)rows.count)};
CGFloat w = 0;
for (NSString *r in rows) w = MAX(w, ceil([r sizeWithAttributes:attrs].width));
for (NSUInteger i = 2 * j; i < MIN(rows.count, 2 * j + 2); i++) w = MAX(w, ceil([rows[i] sizeWithAttributes:attrs].width));
return w;
}
// mpColumn is the width of a cell's digits: its columns of two rows each,
// mpColGap between them.
static CGFloat mpColumn(NSDictionary *c) {
NSUInteger n = ([c[@"rows"] count] + 1) / 2;
CGFloat w = 0;
for (NSUInteger j = 0; j < n; j++) w += (j ? mpColGap : 0) + mpColWidth(c, j);
return w;
}
@@ -225,21 +237,27 @@ static void mpMasked(NSImage *glyph, BOOL tile, NSRect r) {
mpTinted(glyph, fit);
}
// mpRows draws a cell's digits in its column from x: the digits (cap
// height) centred as a block, each row right-aligned; drawAtPoint takes the
// line's top, its baseline an ascender below.
// mpRows draws a cell's digits from x, in columns of two rows: the digits
// (cap height) of a column centred as a block, each row right-aligned in
// its column (a third window alone in its column sits on the top line);
// drawAtPoint takes the line's top, its baseline an ascender below.
static void mpRows(NSDictionary *c, CGFloat x, CGFloat h, NSColor *ink) {
NSArray *rows = c[@"rows"];
NSFont *f = mpRowFont((int)rows.count);
NSDictionary *a = @{NSFontAttributeName: f, NSForegroundColorAttributeName: ink};
CGFloat col = mpColumn(c);
NSUInteger lines = MIN(rows.count, (NSUInteger)2);
CGFloat cap = f.capHeight;
CGFloat top = (h - (cap * rows.count + mpRowGap * (rows.count - 1))) / 2;
for (NSUInteger i = 0; i < rows.count; i++) {
NSString *r = rows[i];
CGFloat base = top + cap * (i + 1) + mpRowGap * i;
CGFloat w = [r sizeWithAttributes:a].width;
[r drawAtPoint:NSMakePoint(x + col - w, base - f.ascender) withAttributes:a];
CGFloat top = (h - (cap * lines + mpRowGap * (lines - 1))) / 2;
for (NSUInteger j = 0; 2 * j < rows.count; j++) {
CGFloat col = mpColWidth(c, j);
for (NSUInteger i = 2 * j; i < MIN(rows.count, 2 * j + 2); i++) {
NSString *r = rows[i];
NSUInteger line = i - 2 * j;
CGFloat base = top + cap * (line + 1) + mpRowGap * line;
CGFloat w = [r sizeWithAttributes:a].width;
[r drawAtPoint:NSMakePoint(x + col - w, base - f.ascender) withAttributes:a];
}
x += col + mpColGap;
}
}
+3 -5
View File
@@ -23,7 +23,8 @@ import (
// Settings → Allowances in the menu bar: the windows of the subscriptions and
// plans ticked there, beside the tray icon, for keeping an eye on them
// without opening magpie. The Mac's menu bar draws each as its logo with
// its two windows stacked, "42%" over "18%", side by side (trayimage), or
// its two windows stacked, "42%" over "18%", side by side (trayimage), and
// every window of a card with more in columns of two, or
// as the windows alone, a thin line between cards, when Settings turns the
// logos off; a tray elsewhere gets them as text ("42% · 18% | 10% · 5%"), Windows' in
// the icon's tooltip only, having no room for any.
@@ -328,9 +329,6 @@ func trayCardText(lang string, q provider.SubscriptionQuota, now time.Time, left
}
long = append(long, line)
}
if len(short) > 2 {
short = short[:2]
}
return strings.Join(short, " · "), q.Name + "\n" + strings.Join(long, "\n") + trayAsOf(lang, q)
}
@@ -734,7 +732,7 @@ func trayName(q provider.SubscriptionQuota) string {
// trayCell is a card as the Mac's menu bar draws it: its logo, and its
// label's parts stacked, the shortest window over the longer ("42%" over
// "18%"), or its balance alone.
// "18%"), in columns of two when it has more, or its balance alone.
type trayCell struct {
ID string // stable provider/account identity, captured with the drawn cell
Icon []byte // the logo as the Usage page has it (SVG or PNG); nil for none
+57
View File
@@ -0,0 +1,57 @@
package gui
import (
"slices"
"testing"
"time"
"github.com/yetone/magpie/internal/provider"
)
// antigravityPools is an Antigravity card whose two pools each have a
// 5-hour and a weekly window: four windows, all set aside by routing.
func antigravityPools() provider.SubscriptionQuota {
week, five := 7*24*time.Hour, 5*time.Hour
return provider.SubscriptionQuota{Provider: "antigravity", Name: "Antigravity", Icon: "antigravity-color", User: "someone@gmail.com",
Windows: []provider.QuotaWindow{
{Name: "Weekly", Pool: "Gemini", Used: 12, Span: week, Aside: true},
{Name: "5 hours", Pool: "Gemini", Used: 40, Span: five, Aside: true},
{Name: "Weekly", Pool: "Claude & GPT", Used: 63, Span: week, Aside: true},
{Name: "5 hours", Pool: "Claude & GPT", Used: 100, Span: five, Aside: true},
}}
}
// Every window a card has is in the menu bar, not its first two
// (jen_celeus on X: Antigravity's four windows, two shown): the Mac draws
// them in columns of two (mpRows), the shortest first, so the first
// column is the 5-hour windows, the second the weekly ones. Windows
// picked in Settings › Menu bar windows are still the only ones shown,
// however many.
func TestTrayEveryWindow(t *testing.T) {
now := time.Date(2026, 11, 15, 3, 0, 0, 0, time.UTC)
q := antigravityPools()
cells, label, _ := trayCardsView("en", []provider.SubscriptionQuota{q}, now, false, false, nil)
if len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"40%", "100%", "12%", "63%"}) {
t.Fatalf("cells %+v", cells)
}
if label != "40% · 100% · 12% · 63%" {
t.Fatalf("label %q", label)
}
var kinds []string
for _, w := range withTrayKinds([]provider.SubscriptionQuota{q})[0].Windows {
kinds = append(kinds, w.TrayKind)
}
for _, tc := range []struct {
pick []string
rows []string
}{
{[]string{kinds[1], kinds[3], kinds[0]}, []string{"40%", "100%", "12%"}},
{[]string{kinds[0], kinds[2]}, []string{"12%", "63%"}},
{[]string{kinds[2]}, []string{"63%"}},
} {
cells, _, _ := trayCardsView("en", []provider.SubscriptionQuota{q}, now, false, false, map[string][]string{"antigravity": tc.pick})
if len(cells) != 1 || !slices.Equal(cells[0].Rows, tc.rows) {
t.Errorf("picked %q: rows %q, want %q", tc.pick, cells[0].Rows, tc.rows)
}
}
}
+1 -1
View File
@@ -93,7 +93,7 @@ func TestTrayModelWindows(t *testing.T) {
q.Windows = slices.DeleteFunc(q.Windows, func(w provider.QuotaWindow) bool { return w.Pool != "" })
q.Windows[3].Used = 40 // Gemini 3 Flash, the family's tightest
cells, _, tip := trayCardsView("en", []provider.SubscriptionQuota{q}, now, false, false, nil)
if len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"100%", "100%"}) {
if len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"100%", "100%", "40%"}) {
t.Fatalf("cells %+v", cells)
}
for _, s := range []string{"Claude Opus 4.6 (Thinking) 100% used", "Gemini 3 Flash 40% used", "GPT-OSS · GPT-OSS 120B"} {
+2 -2
View File
@@ -38,14 +38,14 @@ func TestTrayUsageText(t *testing.T) {
t.Errorf("id %q", id)
}
// no lengths known: the vendor's order, two at most, clamped, its own count
// no lengths known: the vendor's order, every window (jen_celeus on X), clamped, its own count
q = provider.SubscriptionQuota{Provider: "zcode", Name: "ZCode", Windows: []provider.QuotaWindow{
{Name: "5 小时", Used: 120, Display: "1.2k / 1k"},
{Name: "Weekly", Used: -3, ResetSecs: 90},
{Name: "Monthly", Used: 1},
}}
label, tip = trayUsageText(q, now, false, false)
if label != "100% · 0%" {
if label != "100% · 0% · 1%" {
t.Errorf("label %q", label)
}
if want := "ZCode\n5 小时 1.2k / 1k · 100% used\nWeekly 0% used · resets in 2m\nMonthly 1% used"; tip != want {