Documentation
¶
Overview ¶
Package launch starts games and follows them while they run: the hooks before launch and after exit, the game's processes, and playtime.
One game session runs at a time. It moves through phases:
preparing → starting → running → finishing → ended
with failed and cancelled as other ways to end. Processes are only polled while a session is active, so an idle launcher costs nothing.
Index ¶
- Constants
- Variables
- func UsableDirs(dirs []string) []string
- type Manager
- func (m *Manager) Active() bool
- func (m *Manager) Answer(questionID int, option string)
- func (m *Manager) Cancel()
- func (m *Manager) Close()
- func (m *Manager) Current() Session
- func (m *Manager) IsGame(pid uint32) bool
- func (m *Manager) Launch(ctx context.Context, p Plan) error
- func (m *Manager) Quit() error
- func (m *Manager) Skip(stepID string)
- type Option
- type Phase
- type Plan
- type Question
- type Session
- type Step
- type StepContext
- type StepState
Constants ¶
const ( StepPending = "pending" StepRunning = "running" StepDone = "done" StepSkipped = "skipped" StepFailed = "failed" )
Step statuses.
Variables ¶
var ErrBusy = errors.New("a game is already running")
ErrBusy means a game is already being played.
var ErrCancel = errors.New("launch cancelled")
ErrCancel ends the launch from a step (the user chose not to play).
var ErrClosed = errors.New("Seaglass is closing")
ErrClosed means Seaglass is quitting and starts no more games.
Functions ¶
func UsableDirs ¶
UsableDirs drops folders too broad to say a process belongs to the game (a drive root, Program Files, the user's profile, …).
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager runs sessions.
func NewManager ¶
NewManager makes a manager; onChange gets every session change.
func (*Manager) Cancel ¶
func (m *Manager) Cancel()
Cancel stops a launch that hasn't reached the game yet.
func (*Manager) Close ¶
func (m *Manager) Close()
Close stops following the game (Seaglass is quitting). It waits a moment for the playtime counted so far to be handed to Played, so it's in the library before that is saved.
type Plan ¶
type Plan struct {
GameID int64
Title string
From string // where it was started (Session.From)
Dirs []string // folders the game's processes run from
Before []Step
// Start starts the game. It runs after the Before steps, which may
// change what it does (the route). pid is 0 when the game was handed
// to a store or Steam.
Start func() (pid uint32, route string, err error)
After []Step
Played func(seconds int64) // adds playtime; called every minute and at the end
OnRun func() // the game was seen running
// OnGone and OnBack follow the game's processes after that: gone is the
// first look without any (it may have exited, or be handing over from a
// launcher), back is when they're seen again before the session ends.
OnGone, OnBack func()
// How long to wait for the game to show up: stores and Steam can take
// a while (updates, shader caches, sign-in).
DetectTimeout time.Duration
}
Plan describes one launch.
type Question ¶
type Question struct {
ID int `json:"id"`
Text string `json:"text"`
Options []Option `json:"options"`
}
Question is a step asking the user to decide something.
type Session ¶
type Session struct {
ID int64 `json:"id"`
GameID int64 `json:"gameId"`
Title string `json:"title"`
Phase Phase `json:"phase"`
Route string `json:"route"` // how it starts: "direct", "store", "steamInput"
Before []StepState `json:"before"`
After []StepState `json:"after"`
Question *Question `json:"question,omitempty"`
StartedAt int64 `json:"startedAt,omitempty"` // unix seconds; when the game was seen running
Seconds int64 `json:"seconds"` // played this session
Error string `json:"error,omitempty"`
Note string `json:"note,omitempty"`
// Shown: the game's own window has come to the front (until then it's
// still loading, as far as anyone can see).
Shown bool `json:"shown,omitempty"`
// Crash is the exit code, as 0xC0000005, when the game crashed.
Crash string `json:"crash,omitempty"`
// From is where it was started: "bigpicture" or "desktop" for the
// interface's modes, "" from outside it (a shortcut, a game noticed).
From string `json:"from,omitempty"`
}
Session is the game being launched or played.
type Step ¶
type Step struct {
ID, Label string
Timeout time.Duration
Run func(ctx context.Context, s *StepContext) error
}
Step is one hook.
type StepContext ¶
type StepContext struct {
// contains filtered or unexported fields
}
StepContext lets a step report progress and ask the user.
func (*StepContext) Progress ¶
func (c *StepContext) Progress(detail string)
Progress shows a line of detail under the step.