diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-07-11 17:47:30 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-07-11 17:47:30 -0500 |
| commit | bab00cb022cc8d50e84e4e8bec40b92b7f60983a (patch) | |
| tree | 15f6efe6ae4ccc340ff7cff1aeb26c4e84e3a15f /src/slskd/Core | |
| parent | 50f76dc8541dedac6ad9dff055cab809e2f33543 (diff) | |
| download | slskd-bab00cb022cc8d50e84e4e8bec40b92b7f60983a.tar.gz | |
reset on option changes
Diffstat (limited to 'src/slskd/Core')
| -rw-r--r-- | src/slskd/Core/ConnectionWatchdog.cs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/slskd/Core/ConnectionWatchdog.cs b/src/slskd/Core/ConnectionWatchdog.cs index f8461033..a598ff7a 100644 --- a/src/slskd/Core/ConnectionWatchdog.cs +++ b/src/slskd/Core/ConnectionWatchdog.cs @@ -48,7 +48,7 @@ namespace slskd IStateMonitor<State> state) { Client = soulseekClient; - Options = optionsMonitor; + OptionsMonitor = optionsMonitor; State = state; WatchdogTimer = new System.Timers.Timer() @@ -59,6 +59,8 @@ namespace slskd }; WatchdogTimer.Elapsed += (sender, args) => _ = AttemptReconnect(); + + OptionsMonitor.OnChange(options => OptionsChanged(options)); } /// <summary> @@ -69,7 +71,7 @@ namespace slskd private ISoulseekClient Client { get; } private bool Disposed { get; set; } private ILogger Log { get; } = Serilog.Log.ForContext<Application>(); - private IOptionsMonitor<Options> Options { get; set; } + private IOptionsMonitor<Options> OptionsMonitor { get; set; } private IStateMonitor<State> State { get; } private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1, 1); private System.Timers.Timer WatchdogTimer { get; } @@ -141,6 +143,17 @@ namespace slskd } } + private void OptionsChanged(Options options) + { + // it's possible that a user begins changing connection settings in an attempt to get the client to connect + // if they edit the options _at all_, assume this is the case and restart the retry loop from the beginning + if (IsEnabled) + { + Log.Information("Options changed, restarting (re)connection process..."); + Restart(); + } + } + private async Task AttemptReconnect(int attempts = 1) { // semaphore is obtained here and released only when the reconnect attempt is complete, so |
