Check for updates on reconnect. Lock around update check.

This commit is contained in:
Jared Goodwin 2020-03-17 21:39:38 -07:00
parent 1179c63dc7
commit 50d48e4e1d
3 changed files with 9 additions and 14 deletions

View File

@ -88,6 +88,7 @@ namespace Remotely.Agent
Logger.Write($"Websocket closed. Reconnecting in {waitTime / 1000} seconds...");
await Task.Delay(waitTime);
await Services.GetRequiredService<DeviceSocket>().Connect();
await Services.GetRequiredService<Updater>().CheckForUpdates();
}
}
catch (Exception ex)

View File

@ -21,6 +21,7 @@ namespace Remotely.Agent.Services
}
private ConfigService ConfigService { get; }
private SemaphoreSlim UpdateLock { get; } = new SemaphoreSlim(1);
private System.Timers.Timer UpdateTimer { get; } = new System.Timers.Timer(TimeSpan.FromHours(6).TotalMilliseconds);
@ -40,18 +41,13 @@ namespace Remotely.Agent.Services
{
try
{
await UpdateLock.WaitAsync();
var hc = new HttpClient();
var wc = new WebClient();
var connectionInfo = ConfigService.GetConnectionInfo();
var response = await hc.GetAsync(connectionInfo.Host + $"/API/AgentUpdate/ServerVerificationToken/{connectionInfo.DeviceID}");
if (await response.Content.ReadAsStringAsync() != connectionInfo.ServerVerificationToken)
{
Logger.Write("Server responded with incorrect verification token. Skipping update.");
return;
}
response = await hc.GetAsync(connectionInfo.Host + $"/API/AgentUpdate/CurrentVersion");
var response = await hc.GetAsync(connectionInfo.Host + $"/API/AgentUpdate/CurrentVersion");
var latestVersion = response.Content.ReadAsStringAsync().Result;
var thisVersion = FileVersionInfo.GetVersionInfo("Remotely_Agent.dll").FileVersion.ToString().Trim();
if (thisVersion != latestVersion)
@ -97,6 +93,10 @@ namespace Remotely.Agent.Services
{
Logger.Write(ex);
}
finally
{
UpdateLock.Release();
}
}
}
}

View File

@ -32,12 +32,6 @@ namespace Remotely.Server.API
return System.IO.File.ReadAllText(filePath).Trim();
}
[HttpGet("[action]/{deviceID}")]
public string ServerVerificationToken(string deviceID)
{
return DataService.GetDevice(deviceID)?.ServerVerificationToken;
}
[HttpGet("[action]")]
public int UpdateWindow()
{