From afd7cab94035090116df2b58ea0542ff03c5648b Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Tue, 17 Oct 2023 18:43:30 +0200 Subject: [PATCH] Add IPC --- Deliveroo/Deliveroo.csproj | 2 +- Deliveroo/External/DeliverooIpc.cs | 46 +++++++++++++++++++++ Deliveroo/External/ExternalPluginHandler.cs | 4 ++ LLib | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 Deliveroo/External/DeliverooIpc.cs diff --git a/Deliveroo/Deliveroo.csproj b/Deliveroo/Deliveroo.csproj index 664720b..6e8bca2 100644 --- a/Deliveroo/Deliveroo.csproj +++ b/Deliveroo/Deliveroo.csproj @@ -1,7 +1,7 @@ net7.0-windows - 2.10 + 2.11 11.0 enable true diff --git a/Deliveroo/External/DeliverooIpc.cs b/Deliveroo/External/DeliverooIpc.cs new file mode 100644 index 0000000..bcba033 --- /dev/null +++ b/Deliveroo/External/DeliverooIpc.cs @@ -0,0 +1,46 @@ +using System; +using Dalamud.Plugin; +using Dalamud.Plugin.Ipc; + +namespace Deliveroo.External; + +internal sealed class DeliverooIpc : IDisposable +{ + private const string TurnInStarted = "Deliveroo.TurnInStarted"; + private const string TurnInStopped = "Deliveroo.TurnInStopped"; + private const string IsTurnInRunning = "Deliveroo.IsTurnInRunning"; + + private readonly ICallGateProvider _isTurnInRunning; + private readonly ICallGateProvider _turnInStarted; + private readonly ICallGateProvider _turnInStopped; + + private bool _running; + + public DeliverooIpc(DalamudPluginInterface pluginInterface) + { + _isTurnInRunning = pluginInterface.GetIpcProvider(IsTurnInRunning); + _turnInStarted = pluginInterface.GetIpcProvider(TurnInStarted); + _turnInStopped = pluginInterface.GetIpcProvider(TurnInStopped); + + _isTurnInRunning.RegisterFunc(CheckIsTurnInRunning); + } + + public void StartTurnIn() + { + _running = true; + _turnInStarted.SendMessage(); + } + + public void StopTurnIn() + { + _running = false; + _turnInStopped.SendMessage(); + } + + private bool CheckIsTurnInRunning() => _running; + + public void Dispose() + { + _isTurnInRunning.UnregisterFunc(); + } +} diff --git a/Deliveroo/External/ExternalPluginHandler.cs b/Deliveroo/External/ExternalPluginHandler.cs index 51a6d8d..8551c1d 100644 --- a/Deliveroo/External/ExternalPluginHandler.cs +++ b/Deliveroo/External/ExternalPluginHandler.cs @@ -7,6 +7,7 @@ namespace Deliveroo.External; internal sealed class ExternalPluginHandler { private readonly IPluginLog _pluginLog; + private readonly DeliverooIpc _deliverooIpc; private readonly YesAlreadyIpc _yesAlreadyIpc; private readonly PandoraIpc _pandoraIpc; @@ -16,6 +17,7 @@ internal sealed class ExternalPluginHandler public ExternalPluginHandler(DalamudPluginInterface pluginInterface, IFramework framework, IPluginLog pluginLog) { _pluginLog = pluginLog; + _deliverooIpc = new DeliverooIpc(pluginInterface); var dalamudReflector = new DalamudReflector(pluginInterface, framework, pluginLog); _yesAlreadyIpc = new YesAlreadyIpc(dalamudReflector); @@ -33,6 +35,7 @@ internal sealed class ExternalPluginHandler } _pluginLog.Information("Saving external plugin state..."); + _deliverooIpc.StartTurnIn(); SaveYesAlreadyState(); SavePandoraState(); Saved = true; @@ -61,6 +64,7 @@ internal sealed class ExternalPluginHandler Saved = false; _yesAlreadyState = null; _pandoraState = null; + _deliverooIpc.StopTurnIn(); } private void RestoreYesAlready() diff --git a/LLib b/LLib index e59d291..2f6ef35 160000 --- a/LLib +++ b/LLib @@ -1 +1 @@ -Subproject commit e59d291f04473eae0b76712397733e2e25349953 +Subproject commit 2f6ef354c401a9f1bb9b807327acad7e98662a2e