diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-02-14 17:55:58 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-14 17:55:58 -0600 |
| commit | 7f0312a1ea28e611a126ddb07117aa1072f1c36a (patch) | |
| tree | c78c5372d6bb23464480a509e3aee1789b5b78a1 /src/slskd/Events | |
| parent | 8d30845f59d693aa6909c9fe8291493422dc10aa (diff) | |
| parent | 9f3b7217dd4554482c904becc101a4cf3074544e (diff) | |
| download | slskd-7f0312a1ea28e611a126ddb07117aa1072f1c36a.tar.gz | |
Merge pull request #1632 from slskd/gluetun
Add VPN integration and gluetun client
Diffstat (limited to 'src/slskd/Events')
| -rw-r--r-- | src/slskd/Events/EventBus.cs | 18 | ||||
| -rw-r--r-- | src/slskd/Events/Types/Events.cs | 18 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/slskd/Events/EventBus.cs b/src/slskd/Events/EventBus.cs index ae3350f0..2ddf9b1f 100644 --- a/src/slskd/Events/EventBus.cs +++ b/src/slskd/Events/EventBus.cs @@ -119,6 +119,24 @@ public class EventBus /// <typeparam name="T">The Type of the event.</typeparam> /// <exception cref="ArgumentException">Thrown if the specified <paramref name="subscriber"/> is null or whitespace.</exception> /// <exception cref="ArgumentNullException">Thrown if the specified <paramref name="callback"/> is null.</exception> + public virtual void Subscribe<T>(string subscriber, Action<T> callback) + where T : Event + { + Subscribe<T>(subscriber, e => + { + callback(e); + return Task.CompletedTask; + }); + } + + /// <summary> + /// Subscribes a <paramref name="subscriber"/>'s <paramref name="callback"/> to an event. + /// </summary> + /// <param name="subscriber">The unique name of the subscriber.</param> + /// <param name="callback">The callback function to execute when an event is raised.</param> + /// <typeparam name="T">The Type of the event.</typeparam> + /// <exception cref="ArgumentException">Thrown if the specified <paramref name="subscriber"/> is null or whitespace.</exception> + /// <exception cref="ArgumentNullException">Thrown if the specified <paramref name="callback"/> is null.</exception> public virtual void Subscribe<T>(string subscriber, Func<T, Task> callback) where T : Event { diff --git a/src/slskd/Events/Types/Events.cs b/src/slskd/Events/Types/Events.cs index 577e41e3..d67396dc 100644 --- a/src/slskd/Events/Types/Events.cs +++ b/src/slskd/Events/Types/Events.cs @@ -32,6 +32,10 @@ public enum EventType // UploadDirectoryComplete = 5, PrivateMessageReceived = 6, RoomMessageReceived = 7, + + SoulseekClientConnected = 50, + SoulseekClientDisconnected = 51, + Noop = int.MaxValue, } @@ -43,6 +47,20 @@ public abstract record Event public abstract int Version { get; } } +public sealed record SoulseekClientConnectedEvent : Event +{ + public override EventType Type => EventType.SoulseekClientConnected; + public override int Version { get; } = 0; +} + +public sealed record SoulseekClientDisconnectedEvent : Event +{ + public override EventType Type => EventType.SoulseekClientDisconnected; + public override int Version { get; } = 0; + public required string Message { get; init; } + public required Exception Exception { get; init; } +} + public sealed record DownloadFileCompleteEvent : Event { public override EventType Type => EventType.DownloadFileComplete; |
