Fix so plugins properly register commands.
This commit is contained in:
@@ -66,6 +66,11 @@ namespace Torch.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UnregisterPluginCommands(ITorchPlugin plugin)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
public void RegisterPluginCommands(ITorchPlugin plugin)
|
public void RegisterPluginCommands(ITorchPlugin plugin)
|
||||||
{
|
{
|
||||||
var assembly = plugin.GetType().Assembly;
|
var assembly = plugin.GetType().Assembly;
|
||||||
|
@@ -14,6 +14,7 @@ using Octokit;
|
|||||||
using Torch.API;
|
using Torch.API;
|
||||||
using Torch.API.Managers;
|
using Torch.API.Managers;
|
||||||
using Torch.API.Plugins;
|
using Torch.API.Plugins;
|
||||||
|
using Torch.API.Session;
|
||||||
using Torch.Collections;
|
using Torch.Collections;
|
||||||
using Torch.Commands;
|
using Torch.Commands;
|
||||||
|
|
||||||
@@ -27,8 +28,10 @@ namespace Torch.Managers
|
|||||||
private const string MANIFEST_NAME = "manifest.xml";
|
private const string MANIFEST_NAME = "manifest.xml";
|
||||||
public readonly string PluginDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins");
|
public readonly string PluginDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins");
|
||||||
private readonly ObservableDictionary<Guid, ITorchPlugin> _plugins = new ObservableDictionary<Guid, ITorchPlugin>();
|
private readonly ObservableDictionary<Guid, ITorchPlugin> _plugins = new ObservableDictionary<Guid, ITorchPlugin>();
|
||||||
|
#pragma warning disable 649
|
||||||
[Dependency]
|
[Dependency]
|
||||||
private CommandManager _commandManager;
|
private ITorchSessionManager _sessionManager;
|
||||||
|
#pragma warning restore 649
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IReadOnlyDictionary<Guid, ITorchPlugin> Plugins => _plugins.AsReadOnly();
|
public IReadOnlyDictionary<Guid, ITorchPlugin> Plugins => _plugins.AsReadOnly();
|
||||||
@@ -50,11 +53,41 @@ namespace Torch.Managers
|
|||||||
plugin.Update();
|
plugin.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override void Attach()
|
||||||
|
{
|
||||||
|
base.Attach();
|
||||||
|
_sessionManager.SessionStateChanged += SessionManagerOnSessionStateChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SessionManagerOnSessionStateChanged(ITorchSession session, TorchSessionState newState)
|
||||||
|
{
|
||||||
|
var mgr = session.Managers.GetManager<CommandManager>();
|
||||||
|
if (mgr == null)
|
||||||
|
return;
|
||||||
|
switch (newState)
|
||||||
|
{
|
||||||
|
case TorchSessionState.Loaded:
|
||||||
|
foreach (ITorchPlugin plugin in _plugins.Values)
|
||||||
|
mgr.RegisterPluginCommands(plugin);
|
||||||
|
return;
|
||||||
|
case TorchSessionState.Unloading:
|
||||||
|
foreach (ITorchPlugin plugin in _plugins.Values)
|
||||||
|
mgr.UnregisterPluginCommands(plugin);
|
||||||
|
return;
|
||||||
|
case TorchSessionState.Loading:
|
||||||
|
case TorchSessionState.Unloaded:
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unloads all plugins.
|
/// Unloads all plugins.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Detach()
|
public override void Detach()
|
||||||
{
|
{
|
||||||
|
_sessionManager.SessionStateChanged -= SessionManagerOnSessionStateChanged;
|
||||||
foreach (var plugin in _plugins.Values)
|
foreach (var plugin in _plugins.Values)
|
||||||
plugin.Dispose();
|
plugin.Dispose();
|
||||||
|
|
||||||
@@ -310,7 +343,6 @@ namespace Torch.Managers
|
|||||||
plugin.StoragePath = Torch.Config.InstancePath;
|
plugin.StoragePath = Torch.Config.InstancePath;
|
||||||
plugin.Torch = Torch;
|
plugin.Torch = Torch;
|
||||||
_plugins.Add(manifest.Guid, plugin);
|
_plugins.Add(manifest.Guid, plugin);
|
||||||
_commandManager.RegisterPluginCommands(plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IEnumerable.GetEnumerator"/>
|
/// <inheritdoc cref="IEnumerable.GetEnumerator"/>
|
||||||
|
Reference in New Issue
Block a user