fix(plugins): close LA5 host lifecycle review
This commit is contained in:
parent
95f4be94db
commit
fbe9c8a288
25 changed files with 1043 additions and 120 deletions
|
|
@ -14,10 +14,24 @@ namespace AcDream.App.Plugins;
|
|||
internal sealed class GraphicalPluginSession : IDisposable
|
||||
{
|
||||
private readonly PluginSession _plugins;
|
||||
private readonly string[] _roots;
|
||||
private readonly IReadOnlyList<string>? _allowList;
|
||||
private readonly string _sessionId;
|
||||
private readonly SessionStatusWriter _statusWriter;
|
||||
private bool _started;
|
||||
|
||||
private GraphicalPluginSession(PluginSession plugins)
|
||||
private GraphicalPluginSession(
|
||||
PluginSession plugins,
|
||||
string[] roots,
|
||||
IReadOnlyList<string>? allowList,
|
||||
string sessionId,
|
||||
SessionStatusWriter statusWriter)
|
||||
{
|
||||
_plugins = plugins;
|
||||
_roots = roots;
|
||||
_allowList = allowList;
|
||||
_sessionId = sessionId;
|
||||
_statusWriter = statusWriter;
|
||||
}
|
||||
|
||||
internal int LoadedCount => _plugins.LoadedCount;
|
||||
|
|
@ -25,7 +39,7 @@ internal sealed class GraphicalPluginSession : IDisposable
|
|||
internal IReadOnlyList<WeakReference> CaptureLoadContextWeakReferences() =>
|
||||
_plugins.CaptureLoadContextWeakReferences();
|
||||
|
||||
internal static GraphicalPluginSession Start(
|
||||
internal static GraphicalPluginSession Create(
|
||||
ApplicationPathSet paths,
|
||||
IReadOnlyList<string>? allowList,
|
||||
string sessionId,
|
||||
|
|
@ -40,21 +54,28 @@ internal sealed class GraphicalPluginSession : IDisposable
|
|||
var plugins = new PluginSession(
|
||||
host,
|
||||
status => Report(statusWriter, sessionId, status));
|
||||
try
|
||||
{
|
||||
plugins.Start(
|
||||
return new GraphicalPluginSession(
|
||||
plugins,
|
||||
[
|
||||
Path.Combine(AppContext.BaseDirectory, "plugins"),
|
||||
paths.PluginsDirectory,
|
||||
],
|
||||
allowList);
|
||||
return new GraphicalPluginSession(plugins);
|
||||
}
|
||||
catch
|
||||
{
|
||||
plugins.Dispose();
|
||||
throw;
|
||||
}
|
||||
allowList,
|
||||
sessionId,
|
||||
statusWriter);
|
||||
}
|
||||
|
||||
internal void Start()
|
||||
{
|
||||
if (_started)
|
||||
throw new InvalidOperationException(
|
||||
"The graphical plugin session has already started.");
|
||||
_started = true;
|
||||
|
||||
// Both real hosts publish the same startup prefix: started first,
|
||||
// then one outcome for each configured plugin, then connection work.
|
||||
_statusWriter.Started(_sessionId);
|
||||
_plugins.Start(_roots, _allowList);
|
||||
}
|
||||
|
||||
public void Dispose() => _plugins.Dispose();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue