Updated plugin installation and plugin loading
This commit is contained in:
@@ -65,7 +65,7 @@ public class HomeController : Controller
|
||||
{
|
||||
_logger.Log("Loading plugins", this);
|
||||
await _pluginLoader.LoadPlugins();
|
||||
_logger.Log("Plugins loaded", this);
|
||||
//_logger.Log("Plugins loaded", this);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using DiscordBotCore.PluginManagement;
|
||||
using DiscordBotCore.PluginManagement.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WebUI.Models;
|
||||
using ILogger = DiscordBotCore.Logging.ILogger;
|
||||
@@ -32,6 +33,7 @@ public class PluginsController : Controller
|
||||
pluginViewModel.Author = plugin.Author;
|
||||
pluginViewModel.Version = plugin.Version;
|
||||
pluginViewModel.DownloadUrl = plugin.DownloadLink;
|
||||
pluginViewModel.Id = plugin.Id;
|
||||
|
||||
pluginViewModels.Add(pluginViewModel);
|
||||
}
|
||||
@@ -66,4 +68,22 @@ public class PluginsController : Controller
|
||||
//TODO: Implement delete plugin
|
||||
return RedirectToAction("InstalledPlugins");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> InstallPlugin(int pluginId)
|
||||
{
|
||||
var pluginData = await _pluginManager.GetPluginDataById(pluginId);
|
||||
if (pluginData is null)
|
||||
{
|
||||
_logger.Log($"Plugin with ID {pluginId} not found", this);
|
||||
return RedirectToAction("OnlinePlugins");
|
||||
}
|
||||
|
||||
IProgress<float> progress = new Progress<float>(f => _logger.Log($"Installing: {f}"));
|
||||
|
||||
await _pluginManager.InstallPlugin(pluginData, progress);
|
||||
|
||||
_logger.Log($"Plugin {pluginData.Name} installed", this);
|
||||
return RedirectToAction("OnlinePlugins");
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@ namespace WebUI.Models;
|
||||
|
||||
public class OnlinePluginViewModel
|
||||
{
|
||||
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; }
|
||||
|
||||
public string DownloadUrl { get; set; }
|
||||
}
|
||||
@@ -73,6 +73,7 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
string defaultLogFormat = "{ThrowTime} {SenderName} {Message}";
|
||||
string defaultLogFolder = "./Data/Logs";
|
||||
string defaultResourcesFolder = "./Data/Resources";
|
||||
string defaultConfigFile = "./Data/Resources/config.json";
|
||||
string defaultPluginFolder = "./Data/Plugins";
|
||||
string defaultPluginDatabaseFile = "./Data/Resources/plugins.json";
|
||||
@@ -135,7 +136,12 @@ builder.Services.AddSingleton<IPluginManager>(sp =>
|
||||
ILogger logger = sp.GetRequiredService<ILogger>();
|
||||
IConfiguration configuration = sp.GetRequiredService<IConfiguration>();
|
||||
|
||||
Directory.CreateDirectory(configuration.Get<string>("PluginFolder", defaultPluginFolder));
|
||||
string pluginFolder = configuration.Get<string>("PluginFolder", defaultPluginFolder);
|
||||
Directory.CreateDirectory(pluginFolder);
|
||||
|
||||
string resourcesFolder = configuration.Get<string>("ResourcesFolder", defaultResourcesFolder);
|
||||
Directory.CreateDirectory(resourcesFolder);
|
||||
|
||||
string pluginDatabaseFile = configuration.Get<string>("PluginDatabase", defaultPluginDatabaseFile);
|
||||
Directory.CreateDirectory(new FileInfo(pluginDatabaseFile).DirectoryName);
|
||||
|
||||
@@ -159,8 +165,6 @@ builder.Services.AddSingleton<IDiscordBotApplication>(sp =>
|
||||
return new DiscordBotApplication(logger, configuration, pluginLoader);
|
||||
});
|
||||
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
@@ -182,4 +186,23 @@ app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
// Force eager creation of all required services
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var provider = scope.ServiceProvider;
|
||||
|
||||
// Manually resolve all your singletons here
|
||||
provider.GetRequiredService<ILogger>();
|
||||
IConfiguration config = provider.GetRequiredService<IConfiguration>();
|
||||
provider.GetRequiredService<IPluginRepositoryConfiguration>();
|
||||
provider.GetRequiredService<IPluginRepository>();
|
||||
provider.GetRequiredService<IPluginManager>();
|
||||
provider.GetRequiredService<IPluginLoader>();
|
||||
provider.GetRequiredService<IDiscordBotApplication>();
|
||||
|
||||
// Optional: Log that all services were initialized
|
||||
provider.GetRequiredService<ILogger>().Log("All core services have been initialized at startup.");
|
||||
}
|
||||
|
||||
|
||||
app.Run();
|
||||
@@ -25,7 +25,9 @@
|
||||
<td>@plugin.Author</td>
|
||||
<td>@plugin.Version</td>
|
||||
<td>
|
||||
<a href="@plugin.DownloadUrl" class="btn btn-primary" target="_blank">Download</a>
|
||||
<form method="post" asp-action="InstallPlugin" asp-route-pluginId="@plugin.Id">
|
||||
<button type="submit" class="btn btn-primary">Download</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user