mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 05:04:15 +01:00
Fix2?
This commit is contained in:
parent
e4f9150c9f
commit
d5ed4a38e4
2 changed files with 30 additions and 15 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit cd56068aac3762c7b011d13a04637a3c3f09775f
|
||||
Subproject commit a8e2fe0219b8fd1f787171f11e33571317e531c1
|
||||
|
|
@ -5,26 +5,41 @@ using Penumbra.Services;
|
|||
|
||||
namespace Penumbra.Api.Api;
|
||||
|
||||
public class PluginStateApi(Configuration config, CommunicatorService communicator) : IPenumbraApiPluginState, IApiService
|
||||
public sealed class PluginStateApi : IPenumbraApiPluginState, IApiService, IDisposable
|
||||
{
|
||||
private readonly Configuration _config;
|
||||
private readonly CommunicatorService _communicator;
|
||||
|
||||
public PluginStateApi(Configuration config, CommunicatorService communicator)
|
||||
{
|
||||
_config = config;
|
||||
_communicator = communicator;
|
||||
_communicator.ModDirectoryChanged.Subscribe(OnModDirectoryChanged, Communication.ModDirectoryChanged.Priority.Api);
|
||||
_communicator.EnabledChanged.Subscribe(OnEnabledChanged, EnabledChanged.Priority.Api);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_communicator.ModDirectoryChanged.Unsubscribe(OnModDirectoryChanged);
|
||||
_communicator.EnabledChanged.Unsubscribe(OnEnabledChanged);
|
||||
}
|
||||
|
||||
public string GetModDirectory()
|
||||
=> config.ModDirectory;
|
||||
=> _config.ModDirectory;
|
||||
|
||||
public string GetConfiguration()
|
||||
=> JsonConvert.SerializeObject(config, Formatting.Indented);
|
||||
=> JsonConvert.SerializeObject(_config, Formatting.Indented);
|
||||
|
||||
public event Action<string, bool> ModDirectoryChanged
|
||||
{
|
||||
add => communicator.ModDirectoryChanged.Subscribe(value, Communication.ModDirectoryChanged.Priority.Api);
|
||||
remove => communicator.ModDirectoryChanged.Unsubscribe(value);
|
||||
}
|
||||
public event Action<string, bool>? ModDirectoryChanged;
|
||||
|
||||
public bool GetEnabledState()
|
||||
=> config.EnableMods;
|
||||
=> _config.EnableMods;
|
||||
|
||||
public event Action<bool> EnabledChange
|
||||
{
|
||||
add => communicator.EnabledChanged.Subscribe(value!, EnabledChanged.Priority.Api);
|
||||
remove => communicator.EnabledChanged.Unsubscribe(value!);
|
||||
}
|
||||
public event Action<bool>? EnabledChange;
|
||||
|
||||
private void OnModDirectoryChanged(string modDirectory, bool valid)
|
||||
=> ModDirectoryChanged?.Invoke(modDirectory, valid);
|
||||
|
||||
private void OnEnabledChanged(bool value)
|
||||
=> EnabledChange?.Invoke(value);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue