Documentation
¶
Overview ¶
Package gui is MyToken's native interface: the main window and the tray panel, drawn with MyGo's ui package.
Look: opaque, quiet surfaces; color is reserved for money, quota and the tools themselves. Motion is limited to a few places where it carries meaning (quota rings, rolling figures, charts morphing between ranges, the tray's burn band) and is paint-only wherever MyGo allows it.
Index ¶
- Constants
- func Lang() string
- func SetLang(l string)
- func SetSystemLang(locale string)
- type App
- type CatalogInfo
- type CustomPrice
- type DBInfo
- type Deps
- type Exporter
- type Login
- type Maintenance
- type Prefs
- type Prices
- type Query
- type Quota
- type QuotaDay
- type QuotaWindow
- type Source
- type Sources
- type Updates
Constants ¶
const ( PrefLang = "ui.lang" // "", "zh", "en" PrefAppearance = "ui.appearance" // "", "light", "dark" PrefTrayTitle = "tray.title" // "cost" (default), "rate", "hit", "quota", "none" )
Preference keys.
const ( // TrafficLightX and TrafficLightY place macOS's window buttons inside // the sidebar, above the logo. TrafficLightX = 18 TrafficLightY = 18 )
Window geometry the app's main.go uses.
const ( // PrefTimezone is the IANA zone days and months are counted in; "" // follows the system. The adapter applies it to the data layer when it // is set, before the GUI reloads. PrefTimezone = "ui.timezone" // PrefCurrency is the display currency code; "" or "USD" shows prices // as they are published. PrefFXRate is units of it per US dollar. PrefCurrency = "ui.currency" PrefFXRate = "ui.fxrate" )
More preference keys (see data.go for the first ones).
const ( TrayWidth = 340 TrayHeight = 520 )
The tray panel's size.
Variables ¶
This section is empty.
Functions ¶
func SetLang ¶
func SetLang(l string)
SetLang sets the interface language ("zh", "en", "" = system).
func SetSystemLang ¶
func SetSystemLang(locale string)
SetSystemLang lets main pass the locale the OS reports, for when the environment does not carry one (apps launched from Finder).
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the interface's state. Every field is read and written on the UI thread only: data is computed by background jobs whose results are applied through Deps.Post, so a view never waits on the index.
func (*App) PanelView ¶
PanelView is the tray panel: today's spend, the sessions running now and the quotas, nearest to running out first. Its window is translucent; the panel draws on the desktop's frosted material.
func (*App) QuotasChanged ¶
func (a *App) QuotasChanged()
QuotasChanged reloads the quota cards; call it from any goroutine.
type CatalogInfo ¶
CatalogInfo describes the bundled official price list.
type CustomPrice ¶
CustomPrice is a user price for a model, USD per million tokens.
type Deps ¶
type Deps struct {
Query Query
Quotas func() []Quota
Sources Sources
Prices Prices
Maint Maintenance
Prefs Prefs
Version string
// Post runs fn on the UI thread and redraws the windows.
Post func(fn func())
// Now is the clock; nil means time.Now.
Now func() time.Time
OpenMain func()
HidePanel func()
Quit func()
Reveal func(path string)
PickFolder func(start string) (string, bool)
SetTrayTitle func(title string)
// Login, Export and SaveFile are optional; their settings hide
// without them. SaveFile asks where to save a file named name.
Login Login
// SetLocale tells the toolkit the language picked ("zh", "en", "").
SetLocale func(lang string)
Updates Updates
Export Exporter
SaveFile func(name string) (string, bool)
}
Deps is everything the interface talks to. Any field may be nil except Query; the matching controls then hide.
type Maintenance ¶
type Maintenance interface {
Info(ctx context.Context) (DBInfo, error)
// Rebuild empties the index and reads every source again.
Rebuild(ctx context.Context) error
// Compact gives free pages back to the file system.
Compact(ctx context.Context) error
}
Maintenance acts on the local index.
type Prices ¶
type Prices interface {
Unpriced(ctx context.Context) ([]query.UnpricedModel, error)
Aliases(ctx context.Context) ([]query.ModelAlias, error)
SetAliases(ctx context.Context, aliases []query.ModelAlias) error
CustomPrices(ctx context.Context) ([]CustomPrice, error)
SetCustomPrices(ctx context.Context, prices []CustomPrice) error
SearchCatalog(ctx context.Context, q string, limit int) ([]string, error)
Catalog() CatalogInfo
}
Prices is the pricing side of the settings.
type Query ¶
type Query interface {
Totals(ctx context.Context, f query.Filter) (query.Totals, error)
Daily(ctx context.Context, f query.Filter) ([]query.Point, error)
ByHarness(ctx context.Context, f query.Filter) ([]query.Bucket, error)
ByModel(ctx context.Context, f query.Filter) ([]query.Bucket, error)
ByProvider(ctx context.Context, f query.Filter) ([]query.Bucket, error)
ByProject(ctx context.Context, f query.Filter) ([]query.Bucket, error)
Usage(ctx context.Context, f query.Filter) ([]query.UsageRow, error)
// HourlyUsage is Usage by local clock hour.
HourlyUsage(ctx context.Context, f query.Filter) ([]query.UsageRow, error)
Sessions(ctx context.Context, f query.Filter, sort string, limit, offset int) ([]query.SessionRow, int, error)
Session(ctx context.Context, h model.Harness, id string) (query.SessionRow, []query.SessionRow, []query.AttributedEvent, error)
// Subscribe notifies (throttled) whenever new data is committed.
Subscribe() (<-chan struct{}, func())
}
Query is the read API the interface needs: a subset of query.Service, so that the demo data and tests can stand in for the index.
type Quota ¶
type Quota struct {
ID, Name string // provider id ("claude") and display name ("Claude")
Plan string // "Max 20x", "Pro", "" when unknown
Windows []QuotaWindow
// Source is "api": figures are always asked of the service, with the
// tool's stored login.
Source string
FetchedAt time.Time
Err string // last fetch error, shown beside a stale snapshot
// SignIn is set when the service turned the stored login away: the
// tool needs signing in again (MyToken never refreshes a login).
SignIn bool
// Daily is what a credit balance lost each day, oldest first, for the
// last two weeks; empty when unknown.
Daily []QuotaDay
}
Quota is one plan quota a tool reports, such as Claude's 5-hour window.
type QuotaWindow ¶
type QuotaWindow struct {
Name string // "5h", "week", "month", "credits", or a tool's own label
UsedPercent float64
// Used and Limit are absolute amounts in Unit when the tool states
// them ("usd", "requests", "credits"); 0 when it only gives a percent.
Used, Limit float64
Unit string
// Balance marks credits without a fixed cap (top-ups, gift packs):
// Remaining is what is left and there is no percent.
Balance bool
Remaining float64
ResetsAt time.Time
ExpiresAt time.Time // when the soonest of the remaining credits expire
}
QuotaWindow is one window of a plan quota, or a credit balance.
type Source ¶
type Source struct {
Harness model.Harness
Detected bool // the tool's data was found where it keeps it
Enabled bool
Roots []string // the directories read
Override string // a directory the user chose instead; "" = automatic
Problem string // why the source cannot be read, in plain words
// NeedsKey marks a tool that encrypts its database and keeps the key out of
// reach; HasKey says whether the user already gave it.
NeedsKey bool
HasKey bool
Requests int64
LastSeen time.Time
}
Source is one tool MyToken can read and how it is set up.
type Sources ¶
type Sources interface {
List(ctx context.Context) ([]Source, error)
SetEnabled(ctx context.Context, h model.Harness, on bool) error
// SetRoot checks that dir holds the tool's data and reads it from there;
// "" goes back to the automatic location.
SetRoot(ctx context.Context, h model.Harness, dir string) error
// SetKey stores the key an encrypted tool needs; "" forgets it. A key that
// does not open the tool's database is an error, not a stored secret.
SetKey(ctx context.Context, h model.Harness, key string) error
// CaptureKey asks the tool's own application for its key, which is the only
// copy: it opens the tool once, reads the key from memory, stores it and
// closes the tool again. progress may be nil and reports step tokens.
CaptureKey(ctx context.Context, h model.Harness, progress func(string)) error
Rescan(ctx context.Context) error
}
Sources manages the tools that are read.