From cec8409ac4c8d58a95b8a914d36f3cdaf152e93b Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Fri, 3 Jan 2020 21:44:30 +0200 Subject: [PATCH] Check if auto-update is enabled in UpdateService --- .../Services/UpdateService.cs | 24 +++++++++++++++---- .../ViewModels/RootViewModel.cs | 4 ---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/DiscordChatExporter.Gui/Services/UpdateService.cs b/DiscordChatExporter.Gui/Services/UpdateService.cs index b66bb13..881e7a1 100644 --- a/DiscordChatExporter.Gui/Services/UpdateService.cs +++ b/DiscordChatExporter.Gui/Services/UpdateService.cs @@ -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 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) diff --git a/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs b/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs index 3fced2a..d46608c 100644 --- a/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs @@ -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)