Table of Contents

Reacting to events

Introduction

Playnite's API allows extensions to react to various events, like when a game is started or installed.

Available Events

Name Event Passed Arguments
OnGameStarting Before game is started. OnGameStartingEventArgs
OnGameStarted Game started running. OnGameStartedEventArgs
OnGameStopped Game stopped running. OnGameStoppedEventArgs
OnGameStartupCancelled Game startup was cancelled. OnGameStartupCancelledEventArgs
OnGameInstalled Game is installed. OnGameInstalledEventArgs
OnGameUninstalled Game is uninstalled. OnGameUninstalledEventArgs
OnGameSelected Game selection changed. OnGameSelectedEventArgs
OnApplicationStarted Playnite was started. OnApplicationStartedEventArgs
OnApplicationStopped Playnite is shutting down. OnApplicationStoppedEventArgs
OnLibraryUpdated Library was updated. OnLibraryUpdatedEventArgs

Cancelling game startup

If you want to cancel game startup from OnGameStarting event, set CancelStartup property of OnGameStartingEventArgs to true.

Example - Handling start/stop events

Game Starting

Starting event is executed before a game is actually started. Game startup procedure can be cancelled by setting CancelStartup property of OnGameStartingEventArgs object (passed to an event method) to true.

Game Started

Following example writes name of currently playing game into a text file.

// To have a code executed on a specific event, override selected event method in your plugin.
public override void OnGameStarted(OnGameStartedEventArgs args)
{
    logger.Info($"Game started: {args.Game.Name}");
}

Game Stopped

This example writes name of game that stopped running and the time game was running for into a text file.

public override void OnGameStopped(OnGameStoppedEventArgs args)
{
    logger.Info($"{args.Game.Name} was running for {args.ElapsedSeconds} seconds");
}