Skip to content

Commit

Permalink
Merge pull request #370 from Fooxboy/369-вернуть-обратно-кнопку-прове…
Browse files Browse the repository at this point in the history
…рки-обновлений

#369 вернуть обратно кнопку проверки обновлений
  • Loading branch information
Fooxboy authored Apr 26, 2024
2 parents b018898 + 2e2e1f4 commit d8e0e3b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 37 deletions.
26 changes: 3 additions & 23 deletions MusicX/RootWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,30 +440,10 @@ private async Task CheckUpdatesInStart()
try
{
await Task.Delay(2000);
/*var github = StaticService.Container.GetRequiredService<GithubService>();
var release = await github.GetLastRelease();
if (release.TagName != StaticService.Version)
navigationService.OpenModal<AvalibleNewUpdateModal>(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<AvailableNewUpdateModal>(viewModel);
var updateService = StaticService.Container.GetRequiredService<UpdateService>();

await updateService.CheckForUpdates();
}catch(Exception ex)
{
var properties = new Dictionary<string, string>
Expand Down
40 changes: 40 additions & 0 deletions MusicX/Services/UpdateService.cs
Original file line number Diff line number Diff line change
@@ -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<bool> 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<AvailableNewUpdateModal>(viewModel);

return true;
}
}
9 changes: 9 additions & 0 deletions MusicX/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,15 @@
Opacity="0.6"
Text="26 марта 2022" />
</StackPanel>

<wpfui:Button
x:Name="CheckUpdates"
Width="250"
Margin="0,10,0,0"
Appearance="Secondary"
Click="CheckUpdates_Click"
Content="Проверить обновления"
Icon="ArrowSync12" />

<TextBlock
Margin="0,20,0,0"
Expand Down
21 changes: 7 additions & 14 deletions MusicX/Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,32 +213,25 @@ private async void CheckUpdates_Click(object sender, RoutedEventArgs e)
{
var snackbarService = StaticService.Container.GetRequiredService<ISnackbarService>();

#if !DEBUG
try
{
var navigation = StaticService.Container.GetRequiredService<NavigationService>();
var github = StaticService.Container.GetRequiredService<GithubService>();

var release = await github.GetLastRelease();



if (release.TagName == StaticService.Version)
var updateService = StaticService.Container.GetRequiredService<UpdateService>();

if (!await updateService.CheckForUpdates())
{
snackbarService.Show("Уже обновлено!",
"У Вас установлена последняя версия MusicX! Обновлений пока что нет");

}
else
{
navigation.OpenModal<AvailableNewUpdateModal>(release);
}
}
catch (Exception ex)
{
snackbarService.Show("Ошибка", "Произошла ошибка при проверке обновлений");

}

#else
snackbarService.Show("В режиме отладки", "Сервис обновлений отключен");
#endif
}

private void TelegramButton_Click(object sender, RoutedEventArgs e)
Expand Down
1 change: 1 addition & 0 deletions MusicX/Views/StartingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ await Task.Run(async () =>
collection.AddSingleton<WindowsAudioMixerService>();
collection.AddSingleton<ICustomSectionsService, CustomSectionsService>();
collection.AddSingleton<ISnackbarService, MusicXSnackbarService>();
collection.AddSingleton<UpdateService>();

var container = StaticService.Container = collection.BuildServiceProvider();

Expand Down

0 comments on commit d8e0e3b

Please sign in to comment.