Reacting to events
Basics
Playnite's API allows extensions to react to various events like when game is started or installed.
Available Events
PowerShell Name / Plugin name | Python Name | Event | Passed Arguments |
---|---|---|---|
OnGameStarting | on_game_starting | Before game is started. | Game |
OnGameStarted | on_game_started | Game started running. | Game |
OnGameStopped | on_game_stopped | Game stopped running. | Game and session length in seconds |
OnGameInstalled | on_game_installed | Game is installed. | Game |
OnGameUninstalled | on_game_uninstalled | Game is uninstalled. | Game |
OnGameSelected | on_game_selected | Game selection changed. | GameSelectionEventArgs |
OnApplicationStarted | on_application_started | Playnite was started. | None |
OnApplicationStopped | on_application_stopped | Playnite is shutting down. | None |
OnLibraryUpdated | on_library_updated | Library was updated. | None |
Scripts
Plugins
Example - Handling start/stop events
To have a code executed on selected event define function with specific name in your script.
Game Starting
Following example writes name of currently playing game into a text file.
public override void OnGameStarted(Game game)
{
logger.Info($"Game started: {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(Game game, double elapsedSeconds)
{
logger.Info($"{game.Name} was running for {elapsedSeconds} seconds");
}