47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
using MaterialDesignThemes.Wpf;
|
|
using Prism.Commands;
|
|
using Prism.Mvvm;
|
|
|
|
namespace Example
|
|
{
|
|
[JetBrains.Annotations.UsedImplicitly]
|
|
public class MainWindowViewModel : BindableBase, IDisposable
|
|
{
|
|
public MainWindowViewModel()
|
|
{
|
|
UpdateCommand = new DelegateCommand<string>(async x => await UpdateAsync(x).ConfigureAwait(false));
|
|
}
|
|
|
|
private async Task UpdateAsync(string startup)
|
|
{
|
|
var silent = !bool.Parse(startup);
|
|
try
|
|
{
|
|
var manager = Katteker.UpdateManager.Create();
|
|
var releases = await manager.CheckForUpdateAsync();
|
|
MessageQueue.Enqueue(releases.Any() ? "Update available" : "No Update available.", true);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
if (silent)
|
|
{
|
|
MessageQueue.Enqueue(e.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
public ICommand UpdateCommand { get; }
|
|
|
|
public SnackbarMessageQueue MessageQueue { get; } = new SnackbarMessageQueue();
|
|
|
|
public void Dispose()
|
|
{
|
|
MessageQueue?.Dispose();
|
|
}
|
|
}
|
|
} |