launch

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

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

View Source
const (
	StepPending = "pending"
	StepRunning = "running"
	StepDone    = "done"
	StepSkipped = "skipped"
	StepFailed  = "failed"
)

Step statuses.

Variables

View Source
var ErrBusy = errors.New("a game is already running")

ErrBusy means a game is already being played.

View Source
var ErrCancel = errors.New("launch cancelled")

ErrCancel ends the launch from a step (the user chose not to play).

View Source
var ErrClosed = errors.New("Seaglass is closing")

ErrClosed means Seaglass is quitting and starts no more games.

Functions

func UsableDirs

func UsableDirs(dirs []string) []string

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

func NewManager(onChange func(Session)) *Manager

NewManager makes a manager; onChange gets every session change.

func (*Manager) Active

func (m *Manager) Active() bool

Active reports whether a session is under way.

func (*Manager) Answer

func (m *Manager) Answer(questionID int, option string)

Answer answers the open question.

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.

func (*Manager) Current

func (m *Manager) Current() Session

Current returns the session (the last one when none is active).

func (*Manager) IsGame

func (m *Manager) IsGame(pid uint32) bool

IsGame reports whether a process belongs to the game being played.

func (*Manager) Launch

func (m *Manager) Launch(ctx context.Context, p Plan) error

Launch starts a session in the background.

func (*Manager) Quit

func (m *Manager) Quit() error

Quit ends the game's processes right away.

func (*Manager) Skip

func (m *Manager) Skip(stepID string)

Skip stops a running step and moves on.

type Option

type Option struct {
	ID    string `json:"id"`
	Label string `json:"label"`
}

Option is one answer to a question.

type Phase

type Phase string

Phase is where a session is.

const (
	Preparing Phase = "preparing" // hooks before launch
	Starting  Phase = "starting"  // started; waiting to see the game run
	Running   Phase = "running"
	Finishing Phase = "finishing" // hooks after exit
	Ended     Phase = "ended"
	Failed    Phase = "failed"
	Cancelled Phase = "cancelled"
)

func (Phase) Done

func (p Phase) Done() bool

Done reports whether the session is over.

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) Ask

func (c *StepContext) Ask(ctx context.Context, text string, opts []Option) (string, error)

Ask shows a question and waits for the answer (an option id).

func (*StepContext) Progress

func (c *StepContext) Progress(detail string)

Progress shows a line of detail under the step.

type StepState

type StepState struct {
	ID     string `json:"id"`
	Label  string `json:"label"`
	Status string `json:"status"`
	Detail string `json:"detail,omitempty"`
}

StepState is a hook step as the interface shows it.

Jump to

Keyboard shortcuts

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