Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for updates every 10 minutes #6

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}