diff --git a/MusicX/RootWindow.xaml.cs b/MusicX/RootWindow.xaml.cs index c5f9ca6f..4ac8db06 100644 --- a/MusicX/RootWindow.xaml.cs +++ b/MusicX/RootWindow.xaml.cs @@ -440,30 +440,10 @@ private async Task CheckUpdatesInStart() try { await Task.Delay(2000); - /*var github = StaticService.Container.GetRequiredService(); - - var release = await github.GetLastRelease(); - - if (release.TagName != StaticService.Version) - navigationService.OpenModal(release);*/ - - var config = await configService.GetConfig(); - - var getBetaUpdates = config.GetBetaUpdates.GetValueOrDefault(false); - var manager = new UpdateManager(new GithubSource("https://github.com/Fooxboy/MusicX-WPF", - string.Empty, getBetaUpdates, new HttpClientFileDownloader()), new() - { - ExplicitChannel = getBetaUpdates ? "win-beta" : "win" - }); - - var updateInfo = await manager.CheckForUpdatesAsync(); - if (updateInfo is null) - return; - - var viewModel = new AvailableNewUpdateModalViewModel(manager, updateInfo); - - navigationService.OpenModal(viewModel); + var updateService = StaticService.Container.GetRequiredService(); + + await updateService.CheckForUpdates(); }catch(Exception ex) { var properties = new Dictionary diff --git a/MusicX/Services/UpdateService.cs b/MusicX/Services/UpdateService.cs new file mode 100644 index 00000000..9b44462c --- /dev/null +++ b/MusicX/Services/UpdateService.cs @@ -0,0 +1,40 @@ +using System.Threading.Tasks; +using MusicX.ViewModels.Modals; +using MusicX.Views.Modals; +using Velopack; +using Velopack.Sources; + +namespace MusicX.Services; + +public class UpdateService +{ + private readonly ConfigService _configService; + private readonly NavigationService _navigationService; + + public UpdateService(ConfigService configService, NavigationService navigationService) + { + _configService = configService; + _navigationService = navigationService; + } + + public async Task CheckForUpdates() + { + var getBetaUpdates = _configService.Config.GetBetaUpdates.GetValueOrDefault(); + var manager = new UpdateManager(new GithubSource("https://github.com/Fooxboy/MusicX-WPF", + string.Empty, getBetaUpdates, new HttpClientFileDownloader()), new() + { + ExplicitChannel = getBetaUpdates ? "win-beta" : "win" + }); + + var updateInfo = await manager.CheckForUpdatesAsync(); + + if (updateInfo is null) + return false; + + var viewModel = new AvailableNewUpdateModalViewModel(manager, updateInfo); + + _navigationService.OpenModal(viewModel); + + return true; + } +} \ No newline at end of file diff --git a/MusicX/Views/SettingsView.xaml b/MusicX/Views/SettingsView.xaml index 65de18a0..72d0fdd2 100644 --- a/MusicX/Views/SettingsView.xaml +++ b/MusicX/Views/SettingsView.xaml @@ -334,6 +334,15 @@ Opacity="0.6" Text="26 марта 2022" /> + + (); +#if !DEBUG try { - var navigation = StaticService.Container.GetRequiredService(); - var github = StaticService.Container.GetRequiredService(); - - var release = await github.GetLastRelease(); - - - - if (release.TagName == StaticService.Version) + var updateService = StaticService.Container.GetRequiredService(); + + if (!await updateService.CheckForUpdates()) { snackbarService.Show("Уже обновлено!", "У Вас установлена последняя версия MusicX! Обновлений пока что нет"); - - } - else - { - navigation.OpenModal(release); } } catch (Exception ex) @@ -238,7 +229,9 @@ private async void CheckUpdates_Click(object sender, RoutedEventArgs e) snackbarService.Show("Ошибка", "Произошла ошибка при проверке обновлений"); } - +#else + snackbarService.Show("В режиме отладки", "Сервис обновлений отключен"); +#endif } private void TelegramButton_Click(object sender, RoutedEventArgs e) diff --git a/MusicX/Views/StartingWindow.xaml.cs b/MusicX/Views/StartingWindow.xaml.cs index a0c5deaa..41aa0f8d 100644 --- a/MusicX/Views/StartingWindow.xaml.cs +++ b/MusicX/Views/StartingWindow.xaml.cs @@ -112,6 +112,7 @@ await Task.Run(async () => collection.AddSingleton(); collection.AddSingleton(); collection.AddSingleton(); + collection.AddSingleton(); var container = StaticService.Container = collection.BuildServiceProvider();