diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-07-15 08:26:37 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-07-15 08:26:37 -0500 |
| commit | 6376d1ed6f4bbae46e1dc4aecec36bfe5de044e8 (patch) | |
| tree | ae0538c083e530617241b2bfa021a2636de20c13 /src/slskd | |
| parent | 3f5ebfde9be34a80a28dc8c08efaa4c9417184dc (diff) | |
| download | slskd-6376d1ed6f4bbae46e1dc4aecec36bfe5de044e8.tar.gz | |
update PushbulletService for options changes, implement IDisposable
Diffstat (limited to 'src/slskd')
| -rw-r--r-- | src/slskd/Integrations/Pushbullet/IPushbulletService.cs | 3 | ||||
| -rw-r--r-- | src/slskd/Integrations/Pushbullet/PushbulletService.cs | 36 |
2 files changed, 34 insertions, 5 deletions
diff --git a/src/slskd/Integrations/Pushbullet/IPushbulletService.cs b/src/slskd/Integrations/Pushbullet/IPushbulletService.cs index 6da42326..bad33903 100644 --- a/src/slskd/Integrations/Pushbullet/IPushbulletService.cs +++ b/src/slskd/Integrations/Pushbullet/IPushbulletService.cs @@ -17,12 +17,13 @@ namespace slskd.Integrations.Pushbullet { + using System; using System.Threading.Tasks; /// <summary> /// Pushbullet integration service. /// </summary> - public interface IPushbulletService + public interface IPushbulletService : IDisposable { /// <summary> /// Sends a push notification to Pushbullet. diff --git a/src/slskd/Integrations/Pushbullet/PushbulletService.cs b/src/slskd/Integrations/Pushbullet/PushbulletService.cs index 04994d92..1a224321 100644 --- a/src/slskd/Integrations/Pushbullet/PushbulletService.cs +++ b/src/slskd/Integrations/Pushbullet/PushbulletService.cs @@ -47,19 +47,29 @@ namespace slskd.Integrations.Pushbullet ILogger<PushbulletService> log) { HttpClientFactory = httpClientFactory; - Options = optionsMonitor.CurrentValue; + OptionsMonitor = optionsMonitor; Log = log; RecentlySent = new MemoryCache(new MemoryCacheOptions()); } + private bool Disposed { get; set; } private IHttpClientFactory HttpClientFactory { get; } - private Options Options { get; } private ILogger<PushbulletService> Log { get; } - private PushbulletOptions PushbulletOptions => Options.Integration.Pushbullet; + private IOptionsMonitor<Options> OptionsMonitor { get; } + private PushbulletOptions PushbulletOptions => OptionsMonitor.CurrentValue.Integration.Pushbullet; private IMemoryCache RecentlySent { get; } /// <summary> + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// </summary> + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + /// <summary> /// Sends a push notification to Pushbullet. /// </summary> /// <param name="title">The notification title.</param> @@ -68,6 +78,11 @@ namespace slskd.Integrations.Pushbullet /// <returns>The operation context.</returns> public Task PushAsync(string title, string cacheKey, string body) { + if (!PushbulletOptions.Enabled) + { + return Task.CompletedTask; + } + if (string.IsNullOrWhiteSpace(title)) { throw new ArgumentException("A notification title must be supplied", nameof(title)); @@ -93,6 +108,19 @@ namespace slskd.Integrations.Pushbullet return PushInternalAsync(title, body); } + protected virtual void Dispose(bool disposing) + { + if (!Disposed) + { + if (disposing) + { + RecentlySent.Dispose(); + } + + Disposed = true; + } + } + private async Task PushInternalAsync(string title, string body) { try @@ -135,4 +163,4 @@ namespace slskd.Integrations.Pushbullet } } } -} +}
\ No newline at end of file |
