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,18 +381,26 @@ 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
|
||||||
{
|
{
|
||||||
_connectionText = await Service.RemoteApi.VerifyConnection(cts.Token);
|
_connectionText = await Service.RemoteApi.VerifyConnection(cts.Token);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (cts == _testConnectionCts)
|
||||||
{
|
{
|
||||||
PluginLog.Error(e, "Could not establish remote connection");
|
PluginLog.Error(e, "Could not establish remote connection");
|
||||||
_connectionText = e.ToString();
|
_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