Skip to content

Commit

Permalink
Added timeout settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaulino committed Mar 9, 2024
1 parent 2cf8ffe commit 287492b
Show file tree
Hide file tree
Showing 4 changed files with 328 additions and 251 deletions.
31 changes: 22 additions & 9 deletions src/Nightingale.Core/Client/NightingaleClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Nightingale.Core.Interfaces;
using Nightingale.Core.Logging;
using Nightingale.Core.Models;
using Nightingale.Core.Settings;
using Nightingale.Core.Workspaces.Extensions;
using Nightingale.Core.Workspaces.Models;
using System;
Expand Down Expand Up @@ -41,7 +42,8 @@ public NightingaleClient(
ICookieJar cookieJar,
ISslValidator validator,
IBodyBuilder bodyBuilder,
IHeaderBuilder headerBuilder)
IHeaderBuilder headerBuilder,
IUserSettings userSettings)
{
var handler = new HttpClientHandler
{
Expand All @@ -57,17 +59,28 @@ public NightingaleClient(
};

_client = new HttpClient(handler);
_varRes = variableResolver
?? throw new ArgumentNullException(nameof(variableResolver));
_cookieJar = cookieJar
?? throw new ArgumentNullException(nameof(cookieJar));
_bodyBuilder = bodyBuilder
?? throw new ArgumentNullException(nameof(bodyBuilder));
_headerBuilder = headerBuilder
?? throw new ArgumentNullException(nameof(headerBuilder));
ApplyTimeoutSettings(userSettings, _client);
_varRes = variableResolver;
_cookieJar = cookieJar;
_bodyBuilder = bodyBuilder;
_headerBuilder = headerBuilder;
_digestAuthenticator = new DigestAuthenticator();
}

private static void ApplyTimeoutSettings(IUserSettings userSettings, HttpClient client)
{
if (userSettings.Get<bool>(SettingsConstants.InfiniteTimeoutKey) is true)
{
client.Timeout = Timeout.InfiniteTimeSpan;
}
else if (userSettings.Get<double>(SettingsConstants.TimeoutSecondsKey) is double timeoutSeconds &&
timeoutSeconds > 0 &&
timeoutSeconds != 100d)
{
client.Timeout = TimeSpan.FromSeconds(timeoutSeconds);
}
}

/// <inheritdoc/>
public async Task<WorkspaceResponse> SendAsync(
Item request,
Expand Down
6 changes: 5 additions & 1 deletion src/Nightingale.Core/Settings/SettingsConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public sealed class SettingsConstants
public const string BackgroundImage = "BackgroundImage";
public const string AlwaysWrapURL = "AlwaysWrapURL";
public const string WordWrapEditor = "WordWrapEditor";
public const string TimeoutSecondsKey = "TimeOutSeconds";
public const string InfiniteTimeoutKey = "InfiniteTimeout";

/// <summary>
/// Settings defaults.
Expand Down Expand Up @@ -69,7 +71,9 @@ public sealed class SettingsConstants
{ AlwaysWrapURL, false },
{ WordWrapEditor, false },
{ BackgroundImage, "" },
{ AutoSaveInterval, true }
{ AutoSaveInterval, true },
{ TimeoutSecondsKey, 100d },
{ InfiniteTimeoutKey, false },
};
}
}
22 changes: 22 additions & 0 deletions src/Nightingale/UserControls/SettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,28 @@
FontFamily="Segoe MDL2 Assets"
Text="&#xE10B;" />
</StackPanel>

<TextBlock
Margin="0,12,0,4"
Style="{StaticResource BaseTextblock}"
Text="Request timeout in seconds (Requires restart)" />
<Grid Margin="0,4,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox
Height="28"
VerticalContentAlignment="Center"
IsEnabled="{x:Bind ViewModel.TimeoutTextEnabled, Mode=OneWay}"
MaxLength="4"
Text="{x:Bind ViewModel.TimeoutText, Mode=TwoWay}" />
<CheckBox
Grid.Column="1"
Margin="12,0,0,0"
Content="Infinite timeout"
IsChecked="{x:Bind ViewModel.InfiniteTimeoutEnabled, Mode=TwoWay}" />
</Grid>
</StackPanel>
</ScrollViewer>
</PivotItem>
Expand Down
Loading

0 comments on commit 287492b

Please sign in to comment.