mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Check for updates on reconnect. Lock around update check.
This commit is contained in:
parent
1179c63dc7
commit
50d48e4e1d
@ -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)
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user