gui

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	PrefLang       = "ui.lang"       // "", "zh", "en"
	PrefAppearance = "ui.appearance" // "", "light", "dark"
	PrefTrayTitle  = "tray.title"    // "cost" (default), "rate", "hit", "quota", "none"
)

Preference keys.

View Source
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.

View Source
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).

View Source
const (
	TrayWidth  = 340
	TrayHeight = 520
)

The tray panel's size.

Variables

This section is empty.

Functions

func Lang

func Lang() string

Lang is the interface language in use: "zh" or "en".

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 New

func New(d Deps) *App

New returns the interface over d. Call Start to begin loading.

func (*App) GoTo

func (a *App) GoTo(page string)

GoTo shows a page: "overview", "sessions", "ranking", "projects" or "settings".

func (*App) MainView

func (a *App) MainView(c *ui.Context)

MainView is the main window's content.

func (*App) PanelView

func (a *App) PanelView(c *ui.Context)

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.

func (*App) Start

func (a *App) Start()

Start loads the first data and follows the index. It must be called on the UI thread.

func (*App) Stop

func (a *App) Stop()

Stop ends the background work.

func (*App) TrayTitle

func (a *App) TrayTitle() string

TrayTitle is the menu bar text the user chose.

type CatalogInfo

type CatalogInfo struct {
	Version string
	Models  int
}

CatalogInfo describes the bundled official price list.

type CustomPrice

type CustomPrice struct {
	Model                                string
	Input, Output, CacheRead, CacheWrite float64
}

CustomPrice is a user price for a model, USD per million tokens.

type DBInfo

type DBInfo struct {
	Path           string
	Bytes          int64
	Events         int64
	Sessions       int64
	Oldest, Newest time.Time
}

DBInfo describes the local index.

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.

func Demo

func Demo(d Deps, lang string) Deps

Demo swaps d's data for the synthetic set: nothing is read from or written to an index. Its clock starts at 15:30 today, a busy afternoon, and runs on from there. Preferences live in memory and start in lang ("en", "zh" or "" for the system's).

type Exporter

type Exporter interface {
	Export(ctx context.Context, path string) error
}

Exporter writes every request as CSV to path.

type Login

type Login interface {
	OpenAtLogin() bool
	SetOpenAtLogin(on bool) error
}

Login turns launching at login on and off.

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 Prefs

type Prefs interface {
	Pref(key string) string
	SetPref(key, value string) error
}

Prefs stores the interface's preferences.

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 QuotaDay

type QuotaDay struct {
	Day   time.Time
	Used  float64
	Known bool
}

QuotaDay is one day of credit use.

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.

type Updates

type Updates interface {
	Enabled() bool
	Check()
	Automatic() bool
	SetAutomatic(on bool)
}

Updates checks for new versions of the app. Check shows the updater's own window; Enabled is false for builds that cannot replace themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL