mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-23 03:06:53 -04:00
Check if auto-update is enabled in UpdateService
This commit is contained in:
parent
3af9421304
commit
cec8409ac4
2 changed files with 20 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Services;
|
||||
using Onova;
|
||||
using Onova.Exceptions;
|
||||
using Onova.Services;
|
||||
|
@ -12,17 +13,30 @@ namespace DiscordChatExporter.Gui.Services
|
|||
new GithubPackageResolver("Tyrrrz", "DiscordChatExporter", "DiscordChatExporter.zip"),
|
||||
new ZipPackageExtractor());
|
||||
|
||||
private readonly SettingsService _settingsService;
|
||||
|
||||
private Version? _updateVersion;
|
||||
private bool _updaterLaunched;
|
||||
|
||||
public UpdateService(SettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
}
|
||||
|
||||
public async Task<Version?> CheckForUpdatesAsync()
|
||||
{
|
||||
if (!_settingsService.IsAutoUpdateEnabled)
|
||||
return null;
|
||||
|
||||
var check = await _updateManager.CheckForUpdatesAsync();
|
||||
return check.CanUpdate ? check.LastVersion : null;
|
||||
}
|
||||
|
||||
public async Task PrepareUpdateAsync(Version version)
|
||||
{
|
||||
if (!_settingsService.IsAutoUpdateEnabled)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await _updateManager.PrepareUpdateAsync(_updateVersion = version);
|
||||
|
@ -39,13 +53,15 @@ namespace DiscordChatExporter.Gui.Services
|
|||
|
||||
public void FinalizeUpdate(bool needRestart)
|
||||
{
|
||||
if (!_settingsService.IsAutoUpdateEnabled)
|
||||
return;
|
||||
|
||||
if (_updateVersion == null || _updaterLaunched)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (_updateVersion == null || _updaterLaunched)
|
||||
return;
|
||||
|
||||
_updateManager.LaunchUpdater(_updateVersion, needRestart);
|
||||
|
||||
_updaterLaunched = true;
|
||||
}
|
||||
catch (UpdaterAlreadyLaunchedException)
|
||||
|
|
|
@ -69,10 +69,6 @@ namespace DiscordChatExporter.Gui.ViewModels
|
|||
{
|
||||
try
|
||||
{
|
||||
// Don't check for updates if auto-update is disabled
|
||||
if (!_settingsService.IsAutoUpdateEnabled)
|
||||
return;
|
||||
|
||||
// Check for updates
|
||||
var updateVersion = await _updateService.CheckForUpdatesAsync();
|
||||
if (updateVersion == null)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue