diff --git a/Dalamud/Game/GameLifecycle.cs b/Dalamud/Game/GameLifecycle.cs index 3a6733512..5c1acc989 100644 --- a/Dalamud/Game/GameLifecycle.cs +++ b/Dalamud/Game/GameLifecycle.cs @@ -2,6 +2,7 @@ using Dalamud.IoC; using Dalamud.IoC.Internal; +using Dalamud.Plugin.Services; namespace Dalamud.Game; @@ -11,7 +12,10 @@ namespace Dalamud.Game; [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.BlockingEarlyLoadedService] -public class GameLifecycle : IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +public class GameLifecycle : IServiceType, IGameLifecycle { private readonly CancellationTokenSource dalamudUnloadCts = new(); private readonly CancellationTokenSource gameShutdownCts = new(); @@ -26,19 +30,13 @@ public class GameLifecycle : IServiceType { } - /// - /// Gets a token that is cancelled when Dalamud is unloading. - /// + /// public CancellationToken DalamudUnloadingToken => this.dalamudUnloadCts.Token; - /// - /// Gets a token that is cancelled when the game is shutting down. - /// + /// public CancellationToken GameShuttingDownToken => this.gameShutdownCts.Token; - /// - /// Gets a token that is cancelled when a character is logging out. - /// + /// public CancellationToken LogoutToken => this.logoutCts.Token; /// diff --git a/Dalamud/Plugin/Services/IGameLifecycle.cs b/Dalamud/Plugin/Services/IGameLifecycle.cs new file mode 100644 index 000000000..caa64ed23 --- /dev/null +++ b/Dalamud/Plugin/Services/IGameLifecycle.cs @@ -0,0 +1,24 @@ +using System.Threading; + +namespace Dalamud.Plugin.Services; + +/// +/// Class offering cancellation tokens for common gameplay events. +/// +public interface IGameLifecycle +{ + /// + /// Gets a token that is cancelled when Dalamud is unloading. + /// + public CancellationToken DalamudUnloadingToken { get; } + + /// + /// Gets a token that is cancelled when the game is shutting down. + /// + public CancellationToken GameShuttingDownToken { get; } + + /// + /// Gets a token that is cancelled when a character is logging out. + /// + public CancellationToken LogoutToken { get; } +}