Skip to content

Commit

Permalink
Check for updates every 10 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
haefele committed Oct 15, 2023
1 parent c10ca81 commit ffaccde
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/ChatPrisma/HostedServices/UpdaterHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

namespace ChatPrisma.HostedServices;

public class UpdaterHostedService(IUpdateManager updateManager, Application app) : IHostedService
public class UpdaterHostedService(IUpdateManager updateManager, Application app) : BackgroundService
{
public async Task StartAsync(CancellationToken cancellationToken)
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var result = await updateManager.CheckForUpdatesAsync(cancellationToken);
if (result is { CanUpdate: true, LastVersion: not null })
while (stoppingToken.IsCancellationRequested is false)
{
await updateManager.PrepareUpdateAsync(result.LastVersion, cancellationToken: cancellationToken);

var updateResult = MessageBox.Show("Update available!, Wanna update now?", "Title", MessageBoxButton.YesNo);
if (updateResult == MessageBoxResult.Yes)
var result = await updateManager.CheckForUpdatesAsync(stoppingToken);
if (result is { CanUpdate: true, LastVersion: not null })
{
updateManager.LaunchUpdater(result.LastVersion);
app.Shutdown();
var updateResult = MessageBox.Show($"Update available {result.LastVersion}!, Wanna update now?", "Title", MessageBoxButton.YesNo);
if (updateResult == MessageBoxResult.Yes)
{
await updateManager.PrepareUpdateAsync(result.LastVersion, cancellationToken: stoppingToken);
updateManager.LaunchUpdater(result.LastVersion);

app.Shutdown();
}
}
}
}

public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
await Task.Delay(TimeSpan.FromMinutes(10), stoppingToken);
}
}
}

0 comments on commit ffaccde

Please sign in to comment.