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 |
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 |
Example - Handling start/stop events
Game Starting
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");
}