@page "/plugins/online" @rendermode InteractiveServer @using DiscordBotCore.Logging @using DiscordBotCore.PluginManagement @using WebUI.Models @using WebUI.Services @inject NotificationService NotificationService

Available Plugins

@if (_onlinePlugins.Any()) { @foreach (var plugin in _onlinePlugins) { }
Name Description Author Version Download
@plugin.Name @plugin.Description @plugin.Author @plugin.Version
} else {

Loading...

} @if (_showInstallPercentage) { } @code { [Inject] public IPluginManager PluginManager { get; set; } [Inject] public ILogger Logger { get; set; } private bool _showInstallPercentage; private float _installPercentage = 0f; private readonly List _onlinePlugins = new(); protected override async Task OnInitializedAsync() { Logger.Log("Getting online plugins...", this); var plugins = await PluginManager.GetPluginsList(); if (!plugins.Any()) { Logger.Log("No online plugins found.", this); return; } _onlinePlugins.Clear(); foreach (var plugin in plugins) { var onlinePlugin = new OnlinePluginModel { Id = plugin.Id, Name = plugin.Name, Description = plugin.Description, Author = plugin.Author, Version = plugin.Version, }; _onlinePlugins.Add(onlinePlugin); } Logger.Log($"Found {_onlinePlugins.Count} online plugins.", this); StateHasChanged(); } private async Task InstallPlugin(int pluginId) { var response = await PluginManager.GetPluginDataById(pluginId); if (!response.IsSuccess) { Logger.Log(response.Message, this); return; } var pluginData = response.Data; if (pluginData is null) { Logger.Log("Plugin data is null.", this, LogType.Error); NotificationService.Notify("Plugin data is null.", NotificationType.Error); return; } Logger.Log($"Installing plugin {pluginData.Name}...", this); _showInstallPercentage = true; IProgress progress = new Progress(percent => { _installPercentage = percent; StateHasChanged(); }); await PluginManager.InstallPlugin(pluginData, progress); Logger.Log($"Plugin {pluginData.Name} installed successfully.", this); NotificationService.Notify($"Plugin {pluginData.Name} installed successfully!", NotificationType.Success); CloseInstallPercentageModal(); StateHasChanged(); } private void CloseInstallPercentageModal() { Logger.Log("Closing install percentage modal", this); _showInstallPercentage = false; _installPercentage = 0f; } private class OnlinePluginModel { public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } public string Author { get; set; } public string Version { get; set; } } }