playnite

package
v2.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: GPL-3.0 Imports: 26 Imported by: ? 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 playnite integrates the Playnite game library manager. Playnite keeps its library in LiteDB files it holds open exclusively, and only code running inside it sees a game start or stop, so everything except launching goes through the Zaparoo extension: it connects to a pipe Core serves and exchanges newline-delimited JSON. Everything except the Win32 bindings is free of build tags so the behaviour can be tested on any platform.

Index

Constants

View Source
const (
	EventHello           = "Hello"
	EventGames           = "Games"
	EventLaunchResult    = "LaunchResult"
	EventCheckResult     = "CheckResult"
	EventMediaStarted    = "MediaStarted"
	EventMediaStopped    = "MediaStopped"
	EventMediaStopResult = "MediaStopResult"
	EventWrite           = "Write"
	EventError           = "Error"
)

Event names sent by the extension.

View Source
const (
	CommandPing     = "Ping"
	CommandGetGames = "GetGames"
	CommandLaunch   = "Launch"
	CommandCheck    = "Check"
	CommandStop     = "Stop"
)

Command names sent to the extension.

View Source
const (
	StatusCompleted   = "completed"
	StatusFailed      = "failed"
	StatusUnsupported = "unsupported"
)

Result statuses reported by the extension.

View Source
const LauncherID = "Playnite"

LauncherID identifies the Playnite launcher to users and in ActiveMedia.

View Source
const MaxLineSize = 8 * 1024 * 1024

MaxLineSize bounds one message from the extension. A games chunk carrying descriptions is the largest message; the extension sends libraries in chunks so a line stays well inside this.

View Source
const PipeName = `\\.\pipe\zaparoo-playnite-ipc`

PipeName is the named pipe Core serves for the extension.

View Source
const ProtocolVersion = 1

ProtocolVersion is the wire protocol this build of Core speaks. The extension reports its own in Hello.

View Source
const SteamLibraryPluginID = "cb91dfc9-b977-43bf-8e70-55f46e410fab"

SteamLibraryPluginID is the library plugin Playnite imports Steam games with. Core indexes Steam itself, so those games are left to that launcher.

Variables

View Source
var (
	// ErrNotConnected is returned when the extension has no open connection.
	ErrNotConnected = errors.New("the Playnite extension is not connected")
	// ErrStopUnsupported is returned when the extension cannot stop the game
	// because Playnite never told it which process the game is.
	ErrStopUnsupported = errors.New("no process reported by Playnite to stop")
	// ErrGameRejected is returned by Check when Playnite answered that it
	// cannot launch the game.
	ErrGameRejected = errors.New("game rejected by Playnite")
)
View Source
var ErrNoActiveGame = errors.New("no active Playnite game")

ErrNoActiveGame is returned by StopGame when Core is not tracking a running Playnite game.

View Source
var ErrNotInstalled = errors.New("no Playnite install found")

ErrNotInstalled is returned when no Playnite folder can be found.

Functions

func DefaultInstallDirs

func DefaultInstallDirs(localAppData string) []string

DefaultInstallDirs lists where Playnite's installer puts it for a user whose local application data folder is localAppData.

func GamePath

func GamePath(gameID, name string) string

GamePath builds the virtual path indexed for a game and written to tokens. The ID is Playnite's own database ID and survives renames; the name is cosmetic.

func HasSystem

func HasSystem(systemID string) bool

HasSystem reports whether any Playnite game can be indexed under systemID.

func IndexedSystem

func IndexedSystem(game *Game, skipSteam bool) (string, bool)

IndexedSystem returns the system a game is indexed under, or false when Core leaves the game out: hidden and uninstalled entries cannot be played, a game on an unknown platform has no system, and a Steam game is already indexed by the Steam launcher when skipSteam is set.

func NewLauncher

func NewLauncher(i *Integration) platforms.Launcher

NewLauncher builds the Playnite launcher around an integration. It has no system of its own: Playnite holds games for many systems, so the scanner runs for each and returns the games Playnite files under it. The lifecycle is external: Playnite starts and owns the game, and the integration publishes ActiveMedia when the extension reports it running.

func NormalizeGameID

func NormalizeGameID(id string) (string, error)

NormalizeGameID validates a game ID and returns its canonical form. Only the hyphenated form is accepted: the ID goes onto Playnite's command line.

func ParseGamePath

func ParseGamePath(path string) (string, error)

ParseGamePath extracts the Playnite game ID from a playnite:// virtual path, in the lowercase hyphenated form Playnite prints.

func ScanResults

func ScanResults(games []Game, systemID string, skipSteam bool) []platforms.ScanResult

ScanResults converts the games that belong to systemID into indexable media. Every game becomes a playnite:// virtual path keyed by its ID.

func SystemForGame

func SystemForGame(game *Game) (string, bool)

SystemForGame returns the Zaparoo system a game belongs to. A game with no platform at all is a PC game: that is how Playnite leaves a manually added program. Otherwise the first platform with a known specification decides, and a game whose platforms are all unknown has no system.

func Systems

func Systems() []string

Systems returns every system a Playnite game can be indexed under, sorted.

Types

type Command

type Command struct {
	Command   string `json:"Command"`
	ID        string `json:"Id,omitempty"`
	RequestID string `json:"RequestId,omitempty"`
	Details   bool   `json:"Details,omitempty"`
}

Command is a message from Core to the extension.

type Deps

type Deps struct {
	ActiveMedia    func() *models.ActiveMedia
	SetActiveMedia func(*models.ActiveMedia)
	// TrackProcess hands the platform the process Playnite started for the
	// running game, so the platform can end its tree if the extension cannot.
	// exe is the process image the extension saw, for the platform to check
	// the PID still names that program.
	TrackProcess func(pid int, exe string)
	// UntrackProcess tells the platform the game's process has gone.
	UntrackProcess func(pid int)
	// WriteTag asks Core to write a game's path to a token.
	WriteTag func(cfg *config.Instance, path string)
	// SteamIndexed reports whether Core indexes Steam games itself.
	SteamIndexed func(cfg *config.Instance) bool
	Frontend     Frontend
	Clock        clockwork.Clock
	Locator      Locator
	Timeouts     Timeouts
}

Deps are the platform hooks and external boundaries the integration uses. Every boundary is an interface or function so tests can script Playnite and the clock.

type Event

type Event struct {
	// Game describes the game a MediaStarted event is for.
	Game *Game `json:"Game,omitempty"`
	// Event names the message.
	Event string `json:"Event"`
	// ID is the game a lifecycle or result event concerns.
	ID string `json:"Id,omitempty"`
	// Name is the game's name on a Write event.
	Name string `json:"Name,omitempty"`
	// RequestID echoes the GetGames request a Games chunk answers.
	RequestID string `json:"RequestId,omitempty"`
	// Status is the outcome on LaunchResult and MediaStopResult.
	Status string `json:"Status,omitempty"`
	// Error explains a failed result, a failed games request or an Error.
	Error string `json:"Error,omitempty"`
	// Command names the command an Error event rejects.
	Command string `json:"Command,omitempty"`
	// Exe is the image path of the started process, when Pid is set.
	Exe string `json:"Exe,omitempty"`
	// PluginVersion, PlayniteVersion and Mode describe the extension in Hello.
	PluginVersion   string `json:"PluginVersion,omitempty"`
	PlayniteVersion string `json:"PlayniteVersion,omitempty"`
	Mode            string `json:"Mode,omitempty"`
	// Games is one chunk of the library on a Games event.
	Games []Game `json:"Games,omitempty"`
	// ProtocolVersion is the extension's wire protocol, in Hello.
	ProtocolVersion int `json:"ProtocolVersion,omitempty"`
	// Pid is the process Playnite started for the game; zero when Playnite
	// did not report one.
	Pid int `json:"Pid,omitempty"`
	// Session numbers one run of a game inside the extension. MediaStarted
	// and the MediaStopped that ends the same run carry the same value.
	Session int `json:"Session,omitempty"`
	// Final marks the last Games chunk of a request.
	Final bool `json:"Final,omitempty"`
}

Event is a message from the extension. One struct carries every event's fields; which are set depends on Event.

func ParseEvent

func ParseEvent(line []byte) (Event, error)

ParseEvent decodes one line from the extension. The line is untrusted: anything that is not a JSON object naming an event is rejected.

type Frontend

type Frontend interface {
	// StartGame runs Playnite with its --start argument. A running Playnite
	// receives the request from the new process, which then exits; otherwise
	// Playnite starts and launches the game once it has loaded.
	StartGame(ctx context.Context, inst *Install, gameID string) error
}

Frontend starts Playnite. It is an interface so tests can observe the command without running anything.

type Game

type Game struct {
	ID              string     `json:"Id"`
	Name            string     `json:"Name"`
	LibraryPluginID string     `json:"LibraryPluginId,omitempty"`
	RomPath         string     `json:"RomPath,omitempty"`
	Description     string     `json:"Description,omitempty"`
	Cover           string     `json:"Cover,omitempty"`
	Background      string     `json:"Background,omitempty"`
	Icon            string     `json:"Icon,omitempty"`
	Platforms       []Platform `json:"Platforms,omitempty"`
	Developers      []string   `json:"Developers,omitempty"`
	Publishers      []string   `json:"Publishers,omitempty"`
	Genres          []string   `json:"Genres,omitempty"`
	ReleaseYear     int        `json:"ReleaseYear,omitempty"`
	IsInstalled     bool       `json:"IsInstalled,omitempty"`
	Hidden          bool       `json:"Hidden,omitempty"`
}

Game is one Playnite library entry as the extension reports it. The metadata and image fields are only filled when details were requested. Image fields are absolute paths to files in Playnite's library folder.

type Handlers

type Handlers struct {
	Started      func(event *Event)
	Stopped      func(event *Event)
	Write        func(id, name string)
	Disconnected func()
}

Handlers receive the extension's unsolicited events. They run on the connection's reader, so they must not wait on another message from it.

type Install

type Install struct {
	Dir           string
	DesktopExe    string
	FullscreenExe string
}

Install is a located Playnite folder. FullscreenExe is empty when the install does not ship Fullscreen mode.

type Integration

type Integration struct {
	// contains filtered or unexported fields
}

Integration indexes and launches games through Playnite and follows the games Playnite reports running. It owns ActiveMedia for Playnite launches, as the launcher has an external lifecycle.

func NewIntegration

func NewIntegration(deps *Deps) *Integration

NewIntegration wires the integration; a nil clock and zero timeouts get real ones.

func (*Integration) Available

func (i *Integration) Available(cfg *config.Instance) error

Available reports whether Playnite can be reached: either its extension is connected, which also covers a portable copy Core cannot find on disk, or an install exists for Core to start.

func (*Integration) Connected

func (i *Integration) Connected() bool

Connected reports whether the Playnite extension is connected.

func (*Integration) GameRunning

func (i *Integration) GameRunning() bool

GameRunning reports whether the extension has reported a game running and not yet stopped. It lets the platform refuse to report a stop it cannot confirm.

func (*Integration) Launch

func (i *Integration) Launch(cfg *config.Instance, path string) error

Launch asks Playnite to start a game. With the extension connected the request goes over the pipe; otherwise Playnite itself is run with the game to start. Either way ActiveMedia is published only when the extension reports the game running.

func (*Integration) LibraryDetails

func (i *Integration) LibraryDetails(ctx context.Context) ([]Game, error)

LibraryDetails reads the whole library with metadata and image paths.

func (*Integration) Locate

func (i *Integration) Locate(cfg *config.Instance) (Install, error)

Locate resolves the install from config, registry and default paths.

func (*Integration) Preflight

func (i *Integration) Preflight(path string) error

Preflight rejects a launch Playnite would refuse, before Core stops the media that is running. It can only ask a connected extension; without one the launch goes ahead and Playnite reports the problem itself.

func (*Integration) Scan

func (i *Integration) Scan(ctx context.Context, cfg *config.Instance, systemID string) ([]platforms.ScanResult, error)

Scan returns the indexable games that belong to systemID. An absent install contributes nothing. An install whose extension is not connected cannot be read, which is reported as an unavailable source so the games already indexed are kept. An unavailable source leaves the whole system's scan incomplete, so that is only reported for systems Playnite games can belong to.

func (*Integration) Serve

func (i *Integration) Serve(cfg *config.Instance, listener net.Listener)

Serve starts accepting the extension on listener, which the integration then owns. cfg is used for work the extension starts, such as tag writes.

func (*Integration) Stop

func (i *Integration) Stop()

Stop closes the connection and forgets the game it followed.

func (*Integration) StopGame

func (i *Integration) StopGame() error

StopGame asks the extension to end the running game and waits for it to confirm. It never clears ActiveMedia itself: the platform does that once the stop is confirmed.

type Locator

type Locator struct {
	FS         afero.Fs
	Registry   func() (string, error)
	Candidates []string
}

Locator finds the Playnite folder. Registry, when set, resolves the folder the installer registered; Candidates are the default install locations tried last.

func (Locator) Locate

func (l Locator) Locate(configDir string) (Install, error)

Locate resolves the install. An explicitly configured directory is authoritative: when it is set but does not hold Playnite, the error says so rather than silently falling back to another install.

type Platform

type Platform struct {
	SpecificationID string `json:"SpecificationId,omitempty"`
	Name            string `json:"Name,omitempty"`
}

Platform is one of a game's Playnite platforms.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server talks to the Playnite extension over one connection at a time. The extension is the client: it reconnects whenever Playnite restarts, and a new connection replaces the previous one.

func NewServer

func NewServer(clock clockwork.Clock, handlers Handlers) *Server

NewServer builds a server; a nil clock means the real one.

func (*Server) Check

func (s *Server) Check(ctx context.Context, gameID string, timeout time.Duration) error

Check asks the extension whether Playnite would accept a launch of the game, without starting it. Only a refusal from the extension returns ErrGameRejected; a lost or silent connection returns another error, as it says nothing about the game.

func (*Server) Close

func (s *Server) Close()

Close stops accepting, drops the connection and waits for the readers.

func (*Server) Connected

func (s *Server) Connected() bool

Connected reports whether the extension has an open connection.

func (*Server) Games

func (s *Server) Games(ctx context.Context, details bool, timeout time.Duration) ([]Game, error)

Games asks the extension for the whole library and waits for every chunk. With details set, each game carries its metadata and image paths.

func (*Server) Hello

func (s *Server) Hello() Event

Hello returns what the connected extension announced about itself.

func (*Server) Launch

func (s *Server) Launch(ctx context.Context, gameID string, timeout time.Duration) error

Launch asks the extension to start a game and waits for it to say whether Playnite accepted the request. The game starting is reported separately.

func (*Server) Serve

func (s *Server) Serve(listener net.Listener)

Serve accepts extension connections on listener until Close. It takes ownership of the listener.

func (*Server) Session

func (s *Server) Session() uint64

Session identifies the current connection: it changes each time the extension connects, including when a new connection replaces one that had not been seen to close.

func (*Server) StopGame

func (s *Server) StopGame(ctx context.Context, gameID string, timeout time.Duration) error

StopGame asks the extension to end a running game and waits for the result.

type Timeouts

type Timeouts struct {
	// Library is how long the extension may take to send the whole library.
	Library time.Duration
	// LaunchAccept is how long the extension may take to say whether
	// Playnite accepted a launch. The game starting is reported separately.
	LaunchAccept time.Duration
	// Check is how long the extension may take to say whether Playnite
	// would launch a game. A launch waits on it before stopping the running
	// media, and goes ahead when it runs out.
	Check time.Duration
	// Stop is how long the extension may take to end a game. It has to fit
	// inside the platform's stop budget with room for the fallback.
	Stop time.Duration
	// LibraryCache is how long a library snapshot serves later scans. An
	// index asks once per system, and the answer is the same every time.
	LibraryCache time.Duration
}

Timeouts bound every wait the integration performs.

func DefaultTimeouts

func DefaultTimeouts() Timeouts

DefaultTimeouts returns the production waits.

Jump to

Keyboard shortcuts

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