-
-
Notifications
You must be signed in to change notification settings - Fork 4
Getting started
Touch Portal has several resources available:
Before you do anything, you would need to create a entry.tp
file, and pick a unique id for your plugin.
- Create a folder under
%appdata%\TouchPortal\plugins\
, ex.%appdata%\TouchPortal\plugins\SamplePlugin\
- Create or copy the
entry.tp
file here. With the required properties.
(example: an absolute minimum required on the time of writing)
{
"sdk": 3,
"version": 1,
"name": "Sample Plugin",
"id": "Plugin.Id",
"categories": []
}
Categories must be filled inn at some point. But may not be required for simple a hello world example.
Plugin.Id
should be changed to some unique id.
- Restart TouchPortal and Trust the plugin.
It should now show under the plugins dropdown in
settings > plug-ins
.
No code should be required yet. Actions, events, etc. you must add to categories.
To start the SDK you need to do tree things:
- Implement the interface
ITouchPortalEventHandler
This needs to have the
pluginId
from theentry.tp
file.
It would also be a good idea to remove allthrow new NotImplementedException();
if this is generated. Or if logging is configured, it can be filled with garbage (debug loglevel).
- Get a client from
TouchPortalFactory.CreateClient
with the interface in step 1. as a parameter.
There are two extra paramteres, one for additional options, and one if you want custom logging. You can use whatever you want, ex. Serilog, but for the SDK, you need to wrap it with the ILogger abstraction interafaces.
-
.Connect();
to the client.
Now you should be good to go, and have received your first (and only of this particular type) info message.
static void Main(string[] args)
{
var samplePlugin = new SamplePlugin();
samplePlugin.Run();
}
public class SamplePlugin : ITouchPortalEventHandler
{
public string PluginId => "Plugin.Id"; //Replace "Plugin.Id" with your unique id.
private readonly ITouchPortalClient _client;
public SamplePlugin()
{
//Static factory method TouchPortalFactory:CreateClient:
//Optionally you can also provide a TouchPortalOptions,
// or a loggerFactory parameter to configure the SDK
_client = TouchPortalFactory.CreateClient(this);
}
public void Run()
{
_client.Connect();
}
...
static void Main(string[] args)
{
//Build configuration:
var configurationRoot = new ConfigurationBuilder()
.SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName)
.AddJsonFile("appsettings.json")
.Build();
//Standard method for build a ServiceProvider in .Net:
var serviceCollection = new ServiceCollection();
serviceCollection.AddLogging(configure =>
{
configure.AddSimpleConsole(options => options.TimestampFormat = "[yyyy.MM.dd HH:mm:ss] ");
configure.AddConfiguration(configurationRoot.GetSection("Logging"));
});
//Registering the Plugin to the IoC container:
serviceCollection.AddTouchPortalSdk(configurationRoot);
serviceCollection.AddSingleton<SamplePlugin>();
var serviceProvider = serviceCollection.BuildServiceProvider(true);
//Use your IoC framework to resolve the plugin with it's dependencies,
// or you can use 'TouchPortalFactory.CreateClient' to get started manually:
var plugin = serviceProvider.GetRequiredService<SamplePlugin>();
plugin.Run();
}
public class SamplePlugin : ITouchPortalEventHandler
{
public string PluginId => "Plugin.Id"; //Replace "Plugin.Id" with your unique id.
private readonly ILogger<SamplePlugin> _logger;
private readonly ITouchPortalClient _client;
public SamplePlugin(ITouchPortalClientFactory clientFactory,
ILogger<SamplePlugin> logger
/* , additional dependencies here */)
{
_logger = logger;
_client = clientFactory.Create(this);
}
public void Run()
{
_client.Connect();
}
...
- Home
- Development
- Getting started
- TODO: Entry.tp
- TODO: Commands
- TODO: Events
- Logging
- Parallelization
- TODO: Graphics / Images
- TODO: Plugins with GUI
- Create a .tpp package
- TODO: Creating a installer
- Troubleshooting
- How the SDK works
- Other SDKs