private async ValueTask HandleAutoUpdateAsync() { try { var updateVersion = await _updateService.CheckForUpdatesAsync(); if (updateVersion == null) { return; } Notifications.Enqueue($"Downloading update to {App.Name} v{updateVersion}..."); await _updateService.PrepareUpdateAsync(updateVersion); Notifications.Enqueue( "Update has been downloaded and will be installed when you exit", "INSTALL NOW", () => { _updateService.FinalizeUpdate(true); RequestClose(); }); } catch { // Failure to update shouldn't crash the application Notifications.Enqueue("Failed to perform application update"); } }
private async Task HandleAutoUpdateAsync() { try { // Check for updates var updateVersion = await _updateService.CheckForUpdatesAsync(); if (updateVersion == null) { return; } // Notify user of an update and prepare it Notifications.Enqueue($"Downloading update to YoutubeDownloader v{updateVersion}..."); await _updateService.PrepareUpdateAsync(updateVersion); // Prompt user to install update (otherwise install it when application exits) Notifications.Enqueue( "Update has been downloaded and will be installed when you exit", "INSTALL NOW", () => { _updateService.FinalizeUpdate(true); RequestClose(); }); } catch { // Failure to update shouldn't crash the application Notifications.Enqueue("Failed to perform application update"); } }
public RootViewModel(IEventAggregator eventAggregator, IViewModelFactory viewModelFactory, SettingsService settingsService, UpdateService updateService, CalculationService calculationService, LocationService locationService, WinApiService winApiService) { _settingsService = settingsService; _calculationService = calculationService; _winApiService = winApiService; // Handle messages eventAggregator.Subscribe(this); // Initialize view models GeneralSettings = viewModelFactory.CreateGeneralSettingsViewModel(); LocationSettings = viewModelFactory.CreateLocationSettingsViewModel(); AdvancedSettings = viewModelFactory.CreateAdvancedSettingsViewModel(); // When IsEnabled switches to 'true' - cancel 'disable temporarily' this.Bind(o => o.IsEnabled, (sender, args) => { if (IsEnabled) { _enableAfterDelayTimer.Stop(); } }); // Initialize timers _updateTimer = new AutoResetTimer(() => { UpdateIsPaused(); UpdateInstant(); UpdateGamma(); }); _settingsAutoSaveTimer = new AutoResetTimer(() => _settingsService.SaveIfNeeded()); _internetSyncTimer = new AutoResetTimer(async() => { if (!_settingsService.IsInternetSyncEnabled) { return; } // TODO: rework later var location = await locationService.GetLocationAsync(); if (_settingsService.IsInternetSyncEnabled) { _settingsService.Location = location; var date = DateTimeOffset.Now; _settingsService.SunriseTime = _calculationService.CalculateSunrise(location, date).TimeOfDay; _settingsService.SunsetTime = _calculationService.CalculateSunset(location, date).TimeOfDay; } }); _checkForUpdatesTimer = new AutoResetTimer(async() => { IsUpdateAvailable = await updateService.CheckForUpdatesAsync(); }); _enableAfterDelayTimer = new ManualResetTimer(Enable); }