settings_re8

This commit is contained in:
lincube
2026-03-14 22:45:09 +08:00
parent 91f9f3d6fb
commit 689be7b585
54 changed files with 5356 additions and 30 deletions

View File

@@ -23,6 +23,7 @@ public sealed class LoadedPlugin : IDisposable, IAsyncDisposable
IServiceProvider services,
IReadOnlyList<PluginSettingsSectionRegistration> settingsSections,
IReadOnlyList<PluginDesktopComponentRegistration> desktopComponents,
IReadOnlyList<PluginDesktopComponentEditorRegistration> desktopComponentEditors,
IReadOnlyList<PluginServiceExportDescriptor> exportedServices,
IReadOnlyList<IHostedService> hostedServices,
PluginLoadContext loadContext)
@@ -36,6 +37,7 @@ public sealed class LoadedPlugin : IDisposable, IAsyncDisposable
Services = services;
SettingsSections = settingsSections;
DesktopComponents = desktopComponents;
DesktopComponentEditors = desktopComponentEditors;
ExportedServices = exportedServices;
HostedServices = hostedServices;
LoadContext = loadContext;
@@ -61,6 +63,8 @@ public sealed class LoadedPlugin : IDisposable, IAsyncDisposable
public IReadOnlyList<PluginDesktopComponentRegistration> DesktopComponents { get; }
public IReadOnlyList<PluginDesktopComponentEditorRegistration> DesktopComponentEditors { get; }
public IReadOnlyList<PluginServiceExportDescriptor> ExportedServices { get; }
public PluginLoadContext LoadContext { get; }

View File

@@ -10,3 +10,7 @@ public sealed record PluginSettingsSectionContribution(
public sealed record PluginDesktopComponentContribution(
LoadedPlugin Plugin,
PluginDesktopComponentRegistration Registration);
public sealed record PluginDesktopComponentEditorContribution(
LoadedPlugin Plugin,
PluginDesktopComponentEditorRegistration Registration);

View File

@@ -181,10 +181,14 @@ public sealed class PluginLoader
.OrderBy(component => component.Category, StringComparer.OrdinalIgnoreCase)
.ThenBy(component => component.DisplayName, StringComparer.OrdinalIgnoreCase)
.ToArray();
var desktopComponentEditors = pluginServices
.GetServices<PluginDesktopComponentEditorRegistration>()
.OrderBy(editor => editor.ComponentId, StringComparer.OrdinalIgnoreCase)
.ToArray();
var exportedServices = ResolveExports(manifest, pluginServices);
AppLogger.Info(
"PluginLoader",
$"Plugin contributions resolved. PluginId='{manifest.Id}'; SettingsSections={settingsSections.Length}; Widgets={desktopComponents.Length}; Exports={exportedServices.Count}.");
$"Plugin contributions resolved. PluginId='{manifest.Id}'; SettingsSections={settingsSections.Length}; Widgets={desktopComponents.Length}; Editors={desktopComponentEditors.Length}; Exports={exportedServices.Count}.");
hostedServices = pluginServices.GetServices<IHostedService>().ToArray();
StartHostedServices(hostedServices);
AppLogger.Info("PluginLoader", $"Hosted services started. PluginId='{manifest.Id}'; HostedServices={hostedServices.Count}.");
@@ -199,6 +203,7 @@ public sealed class PluginLoader
pluginServices,
settingsSections,
desktopComponents,
desktopComponentEditors,
exportedServices,
hostedServices,
loadContext);

View File

@@ -36,6 +36,7 @@ public sealed class PluginRuntimeService : IDisposable
private readonly List<PluginCatalogEntry> _catalog = [];
private readonly List<PluginSettingsSectionContribution> _settingsSections = [];
private readonly List<PluginDesktopComponentContribution> _desktopComponents = [];
private readonly List<PluginDesktopComponentEditorContribution> _desktopComponentEditors = [];
private readonly object _packageMutationGate = new();
public PluginRuntimeService(ISettingsFacadeService? settingsFacade = null)
@@ -73,6 +74,7 @@ public sealed class PluginRuntimeService : IDisposable
public IReadOnlyList<PluginSettingsSectionContribution> SettingsSections => _settingsSections;
public IReadOnlyList<PluginDesktopComponentContribution> DesktopComponents => _desktopComponents;
public IReadOnlyList<PluginDesktopComponentEditorContribution> DesktopComponentEditors => _desktopComponentEditors;
public IPluginExportRegistry ExportRegistry => _exportRegistry;
@@ -193,7 +195,7 @@ public sealed class PluginRuntimeService : IDisposable
loadResult.LoadedPlugin.DesktopComponents.Count));
AppLogger.Info(
"PluginRuntime",
$"Plugin loaded. PluginId='{loadResult.LoadedPlugin.Manifest.Id}'; SourcePath='{loadResult.SourcePath}'; ManifestVersion='{loadResult.LoadedPlugin.Manifest.Version ?? "<unknown>"}'; ApiVersion='{loadResult.LoadedPlugin.Manifest.ApiVersion ?? "<unknown>"}'; SourceKind='{candidate.SourceKind}'; SettingsSections={loadResult.LoadedPlugin.SettingsSections.Count}; Widgets={loadResult.LoadedPlugin.DesktopComponents.Count}.");
$"Plugin loaded. PluginId='{loadResult.LoadedPlugin.Manifest.Id}'; SourcePath='{loadResult.SourcePath}'; ManifestVersion='{loadResult.LoadedPlugin.Manifest.Version ?? "<unknown>"}'; ApiVersion='{loadResult.LoadedPlugin.Manifest.ApiVersion ?? "<unknown>"}'; SourceKind='{candidate.SourceKind}'; SettingsSections={loadResult.LoadedPlugin.SettingsSections.Count}; Widgets={loadResult.LoadedPlugin.DesktopComponents.Count}; Editors={loadResult.LoadedPlugin.DesktopComponentEditors.Count}.");
Debug.WriteLine($"[PluginRuntime] Loaded '{loadResult.Manifest?.Id}' from '{loadResult.SourcePath}'.");
continue;
}
@@ -622,6 +624,10 @@ public sealed class PluginRuntimeService : IDisposable
entry.Plugin.Manifest.Id,
loadedPlugin.Manifest.Id,
StringComparison.OrdinalIgnoreCase));
_desktopComponentEditors.RemoveAll(entry => string.Equals(
entry.Plugin.Manifest.Id,
loadedPlugin.Manifest.Id,
StringComparison.OrdinalIgnoreCase));
foreach (var settingsSection in loadedPlugin.SettingsSections)
{
@@ -632,6 +638,11 @@ public sealed class PluginRuntimeService : IDisposable
{
_desktopComponents.Add(new PluginDesktopComponentContribution(loadedPlugin, desktopComponent));
}
foreach (var desktopComponentEditor in loadedPlugin.DesktopComponentEditors)
{
_desktopComponentEditors.Add(new PluginDesktopComponentEditorContribution(loadedPlugin, desktopComponentEditor));
}
}
private void RegisterSharedContractsForLoad(PluginManifest manifest)