gui: a Linux bar's tray icon is the bird's silhouette, not the app's tile, and the tooltip says today's total (ylorn on Discord)
ylorn (Hyprland, 0.1.1241): the StatusNotifierItem's IconPixmap was the
coloured app icon on an opaque white tile, which clashed with a bar's
monochrome icons and became a solid block on bars that tint icons by
alpha; the tooltip said only "magpie".
- Linux now gets the macOS menu bar's template bird (tray.png) in one
colour on transparency (trayIconFor / linuxTrayIcon, trayglyph.go):
light, or dark when xdg-desktop-portal's org.freedesktop.appearance
color-scheme is 2 (prefer light); it is set again on the portal's
SettingChanged (watchTrayScheme, own D-Bus connection). An unreadable
portal counts as no preference (light). No IconName is set: a host
that resolves a -symbolic name but draws it untinted would show a
black bird on a dark bar with no pixmap fallback. macOS keeps its
template icon, Windows the coloured app icon.
- With no cards in the menu bar the tooltip is "magpie" over one line of
today's total, as the panel's Usage tab sums it (trayIdleTip: all
tokens, cost in Settings' currency, requests), refreshed with the
cards' loop. Cards picked: unchanged.
- The menu is unchanged (Open / version / Quit): no info lines. The
panel one click away has the models and usage, and the menu is shared
with Windows and macOS.
Run (sandbox HOME, pinned GOMODCACHE, shared GOCACHE), on origin/main
21aa40285:
- TestTrayIconPerOS fails with Linux given appIcon back ("linux:
(0,0)-(64,64), want the menu bar bird's (0,0)-(44,44)"); TestTrayIdleTip
fails with the tooltip back to plain "magpie". Both pass restored, with
TestPortalLight, TestTrayTotals, TestTrayIconSize, TestSNITipIsSafeMarkup.
- gofmt -l clean; go vet ./... (darwin), GOOS=windows go vet ./...,
GOOS=linux go vet -tags nogui ./... clean; GOOS=windows go build and
GOOS=linux go build -tags nogui OK.
- traytip_linux.go (linux && !nogui, cgo) can't be vetted from macOS: the
two new functions were copied into a darwin build and vetted there.
- go test -p 4 -timeout 40m ./...: exit 0, 53 ok, no FAIL.
- GUI: tray-*.test.cjs (Playwright 1.62.0): 112/112 pass.
Not tried on a real Linux bar (the Windows box with its WSL2/Omarchy VM
was unreachable over ssh): the pixmap, its colour on a light/dark scheme
and the tooltip on waybar/Quickshell/KDE are unverified on hardware.
This commit is contained in:
@@ -315,6 +315,7 @@ covers it.
|
||||
- The requests magpie makes by itself (a routing classifier's, a web search's, an image description's) are told apart from the agents' on the Usage page (#1839): magpie's row among the agents and its rows in the ledger carry a "magpie's own" mark (`ownBadge`), an account's, key's or model's row adds "{n} by magpie itself" from the summary's `own`, and an account's card says how many of the period's requests were magpie's own (`ownLine`, drawn again once the summary comes after the allowances). See `own-requests.test.cjs` and `TestSummaryCountsMagpiesOwnCallsApart`.
|
||||
- Opening the allowances is asking to see them (#1588, `quotasOpened` in `app.js`): the Usage page from the nav or its Overview tab picked, the window brought back to the front on the Overview, the tray panel's Allowances tab picked or the panel brought up on it, and a menu bar cell clicked each load `usage/quotas?asked=1`, as Refresh now does. An asked read makes the backend read every account again (`AskClaudeUsage`), so an opening within 30s (`QUOTAS_OPEN_GAP`) of the last asked read sends an ordinary read instead, which joins one on its way; Refresh now always asks. A panel page loaded while it is put away (hidden, or without focus) doesn't ask. The timed refresh is unchanged and never asks. See `allowance-open-read.test.cjs`.
|
||||
- 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, `+` 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`.
|
||||
- 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. With no cards in the menu bar the tooltip is magpie over a line of today's total (`trayIdleTip`: every token, the cost, the requests), brought up to date with the cards' refresh; the tray's menu stays Open, the version and Quit. See `TestTrayIconPerOS` and `TestTrayIdleTip`.
|
||||
- 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) 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`.
|
||||
- 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. 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. The last card in each column then reaches down to where the tallest column ends (a `min-height`, cleared before the cards are measured again), so cards side by side in one row are as tall as each other and a stack ends with the tall card beside it (ikunbots on X); content stays at each card's top. 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`.
|
||||
|
||||
+10
-4
@@ -41,7 +41,7 @@ var trayIcon []byte // black glyph, tinted by the macOS menu bar
|
||||
var trayFlap embed.FS
|
||||
|
||||
//go:embed icon.png
|
||||
var appIcon []byte // coloured, for other trays
|
||||
var appIcon []byte // coloured, for Windows' tray
|
||||
|
||||
// The app's own icon: the Mac's Dock (which it replaces the bundle's .icns
|
||||
// in, at up to 512pt), window icons and the about box. At 64px it was
|
||||
@@ -488,10 +488,16 @@ func Run(version string, showMain bool, link string) error {
|
||||
go dropTrayName()
|
||||
}
|
||||
h.tray.SetTooltip("magpie")
|
||||
if runtime.GOOS == "darwin" {
|
||||
h.tray.SetTemplateIcon(trayIcon)
|
||||
if icon, template := trayIconFor(runtime.GOOS, traySchemeLight()); template {
|
||||
h.tray.SetTemplateIcon(icon)
|
||||
} else {
|
||||
h.tray.SetIcon(appIcon)
|
||||
h.tray.SetIcon(icon)
|
||||
}
|
||||
if runtime.GOOS == "linux" {
|
||||
go watchTrayScheme(func(light bool) {
|
||||
icon, _ := trayIconFor("linux", light)
|
||||
h.tray.SetIcon(icon)
|
||||
})
|
||||
}
|
||||
h.tray.SetMenu(menu)
|
||||
h.tray.AttachWindow(h.panel).WindowOffset(6)
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
//go:build !nogui
|
||||
|
||||
package gui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
|
||||
"github.com/godbus/dbus/v5"
|
||||
)
|
||||
|
||||
// A Linux bar's tray icon is the menu bar's bird alone, in one colour on
|
||||
// transparency, as the icons beside it are (ylorn on Discord): the app's
|
||||
// own icon, a coloured bird on a white tile, stood out in a row of them, and
|
||||
// a bar that tints its icons to the theme by their alpha made the tile a
|
||||
// solid block. A bar that doesn't tint shows the colour given: light, as
|
||||
// most bars are dark, unless the desktop prefers light (traySchemeLight).
|
||||
var (
|
||||
trayGlyphLight = color.NRGBA{0xff, 0xff, 0xff, 0xff}
|
||||
trayGlyphDark = color.NRGBA{0x1f, 0x1f, 0x1f, 0xff}
|
||||
)
|
||||
|
||||
// trayGlyph is trayIcon, the bird's silhouette (a black glyph on
|
||||
// transparency), in c: each pixel keeps the glyph's alpha. trayIcon itself
|
||||
// when it can't be read, which is still a silhouette.
|
||||
func trayGlyph(c color.NRGBA) []byte {
|
||||
src, err := png.Decode(bytes.NewReader(trayIcon))
|
||||
if err != nil {
|
||||
return trayIcon
|
||||
}
|
||||
b := src.Bounds()
|
||||
out := image.NewNRGBA(b)
|
||||
for y := b.Min.Y; y < b.Max.Y; y++ {
|
||||
for x := b.Min.X; x < b.Max.X; x++ {
|
||||
a := color.NRGBAModel.Convert(src.At(x, y)).(color.NRGBA).A
|
||||
out.SetNRGBA(x, y, color.NRGBA{c.R, c.G, c.B, uint8(uint(a) * uint(c.A) / 0xff)})
|
||||
}
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if png.Encode(&buf, out) != nil {
|
||||
return trayIcon
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
// trayIconFor is the tray's icon on goos, and whether it is a template
|
||||
// image the system tints (the Mac's menu bar): the bird alone on the Mac
|
||||
// and Linux (linuxTrayIcon, light saying the desktop prefers a light
|
||||
// scheme), the app's coloured icon in Windows' tray, which shows apps' own.
|
||||
func trayIconFor(goos string, light bool) (icon []byte, template bool) {
|
||||
switch goos {
|
||||
case "darwin":
|
||||
return trayIcon, true
|
||||
case "linux":
|
||||
return linuxTrayIcon(light), false
|
||||
}
|
||||
return appIcon, false
|
||||
}
|
||||
|
||||
// linuxTrayIcon is the glyph for a desktop whose colour scheme preference
|
||||
// (the portal's org.freedesktop.appearance color-scheme) is light or not:
|
||||
// dark only where light is asked for; "no preference" or one that can't be
|
||||
// read is light, the bars of GNOME, Omarchy and waybar's own style being
|
||||
// dark.
|
||||
func linuxTrayIcon(light bool) []byte {
|
||||
if light {
|
||||
return trayGlyph(trayGlyphDark)
|
||||
}
|
||||
return trayGlyph(trayGlyphLight)
|
||||
}
|
||||
|
||||
// portalLight reads the portal's color-scheme value as linuxTrayIcon takes
|
||||
// it: light only for 2 (prefer light). Settings.Read wraps the value in a
|
||||
// second variant and ReadOne and SettingChanged don't, so either is
|
||||
// unwrapped; anything else is no preference.
|
||||
func portalLight(v dbus.Variant) bool {
|
||||
for range 2 {
|
||||
if in, ok := v.Value().(dbus.Variant); ok {
|
||||
v = in
|
||||
}
|
||||
}
|
||||
n, ok := v.Value().(uint32)
|
||||
return ok && n == 2
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//go:build !nogui
|
||||
|
||||
package gui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"testing"
|
||||
|
||||
"github.com/godbus/dbus/v5"
|
||||
)
|
||||
|
||||
// ylorn on Discord: a Linux bar's tray icon was the app's icon, a bird on
|
||||
// an opaque white tile, which a bar tinting its icons by their alpha
|
||||
// turned into a solid block. It is the bird's silhouette alone, in one
|
||||
// colour on transparency, light unless the desktop prefers light; the Mac
|
||||
// keeps its template and Windows the app's icon.
|
||||
func TestTrayIconPerOS(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
light bool
|
||||
want color.NRGBA
|
||||
}{{false, trayGlyphLight}, {true, trayGlyphDark}} {
|
||||
icon, template := trayIconFor("linux", c.light)
|
||||
if template {
|
||||
t.Errorf("linux: a template icon, which no Linux bar tints")
|
||||
}
|
||||
img, err := png.Decode(bytes.NewReader(icon))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
glyph, _ := png.Decode(bytes.NewReader(trayIcon))
|
||||
if img.Bounds() != glyph.Bounds() {
|
||||
t.Fatalf("linux: %v, want the menu bar bird's %v", img.Bounds(), glyph.Bounds())
|
||||
}
|
||||
b := img.Bounds()
|
||||
shown := 0
|
||||
for y := b.Min.Y; y < b.Max.Y; y++ {
|
||||
for x := b.Min.X; x < b.Max.X; x++ {
|
||||
p := color.NRGBAModel.Convert(img.At(x, y)).(color.NRGBA)
|
||||
g := color.NRGBAModel.Convert(glyph.At(x, y)).(color.NRGBA)
|
||||
if p.A != g.A {
|
||||
t.Fatalf("linux light=%v: alpha %d at %d,%d, want the bird's %d (a tile or another shape)", c.light, p.A, x, y, g.A)
|
||||
}
|
||||
if p.A > 0 {
|
||||
shown++
|
||||
if p.R != c.want.R || p.G != c.want.G || p.B != c.want.B {
|
||||
t.Fatalf("linux light=%v: %v at %d,%d, want every pixel %v", c.light, p, x, y, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if shown == 0 || shown == b.Dx()*b.Dy() {
|
||||
t.Fatalf("linux: %d of %d pixels shown, want the silhouette on transparency", shown, b.Dx()*b.Dy())
|
||||
}
|
||||
}
|
||||
if icon, template := trayIconFor("darwin", false); !template || !bytes.Equal(icon, trayIcon) {
|
||||
t.Errorf("darwin: want the template bird")
|
||||
}
|
||||
if icon, template := trayIconFor("windows", false); template || !bytes.Equal(icon, appIcon) {
|
||||
t.Errorf("windows: want the app's own icon")
|
||||
}
|
||||
if img, _ := png.Decode(bytes.NewReader(trayGlyph(trayGlyphLight))); img == nil || img.ColorModel() != color.NRGBAModel {
|
||||
t.Errorf("trayGlyph: want an NRGBA png, got %T", img)
|
||||
}
|
||||
}
|
||||
|
||||
// The portal's color-scheme: 1 prefers dark, 2 light, 0 neither; Read
|
||||
// wraps it in a second variant, ReadOne and SettingChanged don't.
|
||||
func TestPortalLight(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
v dbus.Variant
|
||||
want bool
|
||||
}{
|
||||
{dbus.MakeVariant(uint32(2)), true},
|
||||
{dbus.MakeVariant(dbus.MakeVariant(uint32(2))), true},
|
||||
{dbus.MakeVariant(uint32(1)), false},
|
||||
{dbus.MakeVariant(dbus.MakeVariant(uint32(0))), false},
|
||||
{dbus.MakeVariant("light"), false},
|
||||
} {
|
||||
if got := portalLight(c.v); got != c.want {
|
||||
t.Errorf("portalLight(%v) = %v, want %v", c.v, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/usage"
|
||||
)
|
||||
|
||||
// ylorn on Discord: with no cards in the menu bar the tooltip said only
|
||||
// "magpie". It says magpie over a line of today's total: every token, the
|
||||
// cost in Settings' currency ("+" when some calls had no price, none when
|
||||
// none had one) and the requests.
|
||||
func TestTrayIdleTip(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
t usage.Totals
|
||||
want string
|
||||
}{
|
||||
{usage.Totals{Calls: 152, Input: 912_000, Output: 318_400, CacheRead: 4_900_000, CacheWrite: 200_000, Cost: 3.4, Unpriced: 2},
|
||||
"magpie\nToday: 6.3M tokens · ≈$3.40+ · 152 requests"},
|
||||
{usage.Totals{Calls: 1, Input: 950, Output: 50},
|
||||
"magpie\nToday: 1.0K tokens · 1 request"},
|
||||
{usage.Totals{}, "magpie\nToday: no requests yet"},
|
||||
} {
|
||||
if got := trayIdleTip(c.t, "usd", 0); got != c.want {
|
||||
t.Errorf("trayIdleTip(%+v) =\n%q, want\n%q", c.t, got, c.want)
|
||||
}
|
||||
}
|
||||
// waybar reads the title as Pango markup: still safe after sniTip
|
||||
if got := sniTip(trayIdleTip(usage.Totals{Calls: 3, Input: 10, Cost: 2}, "usd", 0)); got != "magpie\nToday: 10 tokens · ≈$2.00 · 3 requests" {
|
||||
t.Errorf("sniTip: %q", got)
|
||||
}
|
||||
}
|
||||
@@ -109,3 +109,50 @@ func setTrayPassive(tray *application.SystemTray, passive bool) (ok bool) {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// traySchemeLight says whether the desktop prefers a light colour scheme,
|
||||
// as xdg-desktop-portal's Settings has it; false for dark, for no
|
||||
// preference, and when there is no portal to ask.
|
||||
func traySchemeLight() bool {
|
||||
conn, err := dbus.SessionBus()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
obj := conn.Object("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop")
|
||||
var v dbus.Variant
|
||||
if err := obj.Call("org.freedesktop.portal.Settings.Read", 0, "org.freedesktop.appearance", "color-scheme").Store(&v); err != nil {
|
||||
return false
|
||||
}
|
||||
return portalLight(v)
|
||||
}
|
||||
|
||||
// watchTrayScheme calls f with the new preference each time the desktop's
|
||||
// colour scheme changes (the portal's SettingChanged), on a connection of
|
||||
// its own so Wails' signals on the shared one aren't held up by it.
|
||||
func watchTrayScheme(f func(light bool)) {
|
||||
conn, err := dbus.ConnectSessionBus()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := conn.AddMatchSignal(
|
||||
dbus.WithMatchObjectPath("/org/freedesktop/portal/desktop"),
|
||||
dbus.WithMatchInterface("org.freedesktop.portal.Settings"),
|
||||
dbus.WithMatchMember("SettingChanged"),
|
||||
); err != nil {
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
ch := make(chan *dbus.Signal, 8)
|
||||
conn.Signal(ch)
|
||||
for s := range ch {
|
||||
if len(s.Body) < 3 {
|
||||
continue
|
||||
}
|
||||
ns, _ := s.Body[0].(string)
|
||||
key, _ := s.Body[1].(string)
|
||||
v, ok := s.Body[2].(dbus.Variant)
|
||||
if ns == "org.freedesktop.appearance" && key == "color-scheme" && ok {
|
||||
f(portalLight(v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,3 +12,8 @@ func setTrayPassive(*application.SystemTray, bool) bool { return true }
|
||||
|
||||
// trayClick: Wails places the panel by the click itself here.
|
||||
func trayClick(*application.SystemTray) (int, bool) { return 0, false }
|
||||
|
||||
// traySchemeLight, watchTrayScheme: only Linux's tray takes the bird in a
|
||||
// colour of the desktop's (linuxTrayIcon).
|
||||
func traySchemeLight() bool { return false }
|
||||
func watchTrayScheme(func(bool)) {}
|
||||
|
||||
@@ -192,10 +192,7 @@ func trayUsageCards(ctx context.Context, ids []string) []provider.SubscriptionQu
|
||||
continue
|
||||
}
|
||||
if currency == "" {
|
||||
currency = settings.Load().Currency
|
||||
if currency == "cny" {
|
||||
rate = fx.Soon().CNYPerUSD // never waited for, as the Settings page's
|
||||
}
|
||||
currency, rate = trayCurrency()
|
||||
}
|
||||
cards = append(cards, trayTotalCard(id, trayTotalSum(p), currency, rate))
|
||||
}
|
||||
@@ -260,6 +257,39 @@ func trayTotalCard(id string, t usage.Totals, currency string, rate float64) pro
|
||||
return provider.SubscriptionQuota{Provider: id, Name: tip, Balance: strings.Join(rows, " · ")}
|
||||
}
|
||||
|
||||
// trayCurrency is the currency Settings shows costs in, and the yuan's
|
||||
// rate when that is CNY.
|
||||
func trayCurrency() (currency string, rate float64) {
|
||||
currency = settings.Load().Currency
|
||||
if currency == "cny" {
|
||||
rate = fx.Soon().CNYPerUSD // never waited for, as the Settings page's
|
||||
}
|
||||
return currency, rate
|
||||
}
|
||||
|
||||
// trayIdleTip is the tooltip while the menu bar shows no cards: magpie's
|
||||
// name over a line of what went through it today, as the panel's Usage tab
|
||||
// counts it (ylorn on Discord: a Linux bar's tooltip said only "magpie").
|
||||
// The whole of today's total, spelled out, is the usage:today card's.
|
||||
func trayIdleTip(t usage.Totals, currency string, rate float64) string {
|
||||
if t.Calls == 0 {
|
||||
return "magpie\nToday: no requests yet"
|
||||
}
|
||||
line := "Today: " + trayCount(t.Tokens()+t.CacheRead+t.CacheWrite) + " tokens"
|
||||
if t.Cost > 0 {
|
||||
c := usage.FormatCost(t.Cost, currency, rate)
|
||||
if t.Unpriced > 0 {
|
||||
c += "+"
|
||||
}
|
||||
line += " · ≈" + c
|
||||
}
|
||||
n := "requests"
|
||||
if t.Calls == 1 {
|
||||
n = "request"
|
||||
}
|
||||
return fmt.Sprintf("magpie\n%s · %d %s", line, t.Calls, n)
|
||||
}
|
||||
|
||||
// trayCount is a count as the Usage page says it in English: 133M, 1.2M,
|
||||
// 456K, 8.2K, 950.
|
||||
func trayCount(n int) string {
|
||||
|
||||
@@ -12,10 +12,11 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/usage"
|
||||
)
|
||||
|
||||
// watchTrayUsage keeps the tray's cards up to date, and plain "magpie" in
|
||||
// the tooltip while there are none.
|
||||
// watchTrayUsage keeps the tray's cards up to date, and magpie's name over
|
||||
// today's total in the tooltip while there are none (trayIdleTip).
|
||||
func (h *host) watchTrayUsage() {
|
||||
wake := make(chan struct{}, 1)
|
||||
onTrayUsage = func() {
|
||||
@@ -46,7 +47,8 @@ func (h *host) watchTrayUsage() {
|
||||
cells = trayPlain(cells)
|
||||
}
|
||||
if tip == "" {
|
||||
tip = "magpie"
|
||||
currency, rate := trayCurrency()
|
||||
tip = trayIdleTip(trayTotalSum(usage.Today), currency, rate)
|
||||
}
|
||||
if runtime.GOOS != "darwin" {
|
||||
cells = nil
|
||||
|
||||
Reference in New Issue
Block a user