Clicking on 'Test Connection' again cancels previous connection attempt
This commit is contained in:
parent
019a204862
commit
c586ced5bd
@ -43,6 +43,8 @@ namespace Pal.Client.Net
|
|||||||
await _channel.ConnectAsync(cancellationToken);
|
await _channel.ConnectAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
var accountClient = new AccountService.AccountServiceClient(_channel);
|
var accountClient = new AccountService.AccountServiceClient(_channel);
|
||||||
if (AccountId == null)
|
if (AccountId == null)
|
||||||
{
|
{
|
||||||
@ -70,6 +72,8 @@ namespace Pal.Client.Net
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
if (AccountId == null)
|
if (AccountId == null)
|
||||||
{
|
{
|
||||||
PluginLog.Warning("TryConnect: No account id to login with");
|
PluginLog.Warning("TryConnect: No account id to login with");
|
||||||
@ -123,6 +127,7 @@ namespace Pal.Client.Net
|
|||||||
return (false, Localization.ConnectionError_LoginReturnedNoToken);
|
return (false, Localization.ConnectionError_LoginReturnedNoToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
return (true, string.Empty);
|
return (true, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@ namespace Pal.Client.Windows
|
|||||||
private readonly FileDialogManager _importDialog;
|
private readonly FileDialogManager _importDialog;
|
||||||
private readonly FileDialogManager _exportDialog;
|
private readonly FileDialogManager _exportDialog;
|
||||||
|
|
||||||
|
private CancellationTokenSource? _testConnectionCts;
|
||||||
|
|
||||||
public ConfigWindow() : base(WindowId)
|
public ConfigWindow() : base(WindowId)
|
||||||
{
|
{
|
||||||
LanguageChanged();
|
LanguageChanged();
|
||||||
@ -86,6 +88,8 @@ namespace Pal.Client.Windows
|
|||||||
{
|
{
|
||||||
_importDialog.Reset();
|
_importDialog.Reset();
|
||||||
_exportDialog.Reset();
|
_exportDialog.Reset();
|
||||||
|
_testConnectionCts?.Cancel();
|
||||||
|
_testConnectionCts = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
@ -377,8 +381,11 @@ namespace Pal.Client.Windows
|
|||||||
_connectionText = Localization.Config_TestConnection_Connecting;
|
_connectionText = Localization.Config_TestConnection_Connecting;
|
||||||
_switchToCommunityTab = true;
|
_switchToCommunityTab = true;
|
||||||
|
|
||||||
CancellationTokenSource cts = new CancellationTokenSource();
|
_testConnectionCts?.Cancel();
|
||||||
|
|
||||||
|
CancellationTokenSource cts = new();
|
||||||
cts.CancelAfter(TimeSpan.FromSeconds(60));
|
cts.CancelAfter(TimeSpan.FromSeconds(60));
|
||||||
|
_testConnectionCts = cts;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -386,8 +393,13 @@ namespace Pal.Client.Windows
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
PluginLog.Error(e, "Could not establish remote connection");
|
if (cts == _testConnectionCts)
|
||||||
_connectionText = e.ToString();
|
{
|
||||||
|
PluginLog.Error(e, "Could not establish remote connection");
|
||||||
|
_connectionText = e.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
PluginLog.Warning(e, "Could not establish a remote connection, but user also clicked 'test connection' again so not updating UI");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user