2026-07-28 19:06:33 -05:00
|
|
|
using LANCommander.Launcher.Plugins.Extensions;
|
2026-07-23 19:47:22 -05:00
|
|
|
using LANCommander.SamplePlugin;
|
|
|
|
|
using LANCommander.SDK.Plugins;
|
|
|
|
|
using LANCommander.SDK.Plugins.Events;
|
|
|
|
|
using LANCommander.Server.Services.Providers.Metadata;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
[assembly: LANCommanderPlugin(typeof(SamplePlugin), Id = "com.lancommander.sampleplugin",
|
|
|
|
|
Hosts = PluginHost.Server | PluginHost.Launcher)]
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.SamplePlugin;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-07-28 19:06:33 -05:00
|
|
|
/// Reference plugin exercising the framework's extension points: a server metadata provider, a
|
2026-07-23 19:47:22 -05:00
|
|
|
/// launcher settings section, a PowerShell cmdlet, and a lifecycle event subscription. Used as the
|
|
|
|
|
/// end-to-end smoke test for the plugin framework.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class SamplePlugin : IPlugin
|
|
|
|
|
{
|
|
|
|
|
public string Id => "com.lancommander.sampleplugin";
|
|
|
|
|
public string Name => "LANCommander Sample Plugin";
|
|
|
|
|
public string Version => "1.0.0";
|
|
|
|
|
public string Author => "LANCommander";
|
|
|
|
|
|
|
|
|
|
private IDisposable? _launchSubscription;
|
|
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
2026-07-28 19:06:33 -05:00
|
|
|
// Server: add an additional metadata provider that appears in the host's enumeration.
|
2026-07-23 19:47:22 -05:00
|
|
|
services.AddSingleton<IMetadataProvider, SampleMetadataProvider>();
|
|
|
|
|
|
2026-07-28 19:06:33 -05:00
|
|
|
// Launcher: add a settings section rendered by a code-built control.
|
|
|
|
|
services.AddSingleton<ISettingsPageExtension, SampleSettingsExtension>();
|
2026-07-23 19:47:22 -05:00
|
|
|
|
2026-07-28 19:06:33 -05:00
|
|
|
// Both hosts: add a PowerShell cmdlet callable from any script.
|
|
|
|
|
services.AddSingleton<IPluginPowerShellExtension, SamplePowerShellExtension>();
|
2026-07-23 19:47:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task InitializeAsync(PluginContext context, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
// Subscribe to a lifecycle event; logs whenever a game is about to launch.
|
|
|
|
|
var eventBus = context.Services.GetRequiredService<IPluginEventBus>();
|
|
|
|
|
|
|
|
|
|
_launchSubscription = eventBus.Subscribe<GameBeforeLaunchEvent>((evt, ct) =>
|
|
|
|
|
{
|
|
|
|
|
context.Logger.LogInformation(
|
|
|
|
|
"[SamplePlugin] Game {GameId} is about to launch (action: {Action})", evt.GameId, evt.Action);
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.Logger.LogInformation("[SamplePlugin] Initialized on host {Host}", context.Host);
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|