Playing with Snackbar
This commit is contained in:
@ -1,23 +1,47 @@
|
||||
using System.Threading.Tasks;
|
||||
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
|
||||
public class MainWindowViewModel : BindableBase, IDisposable
|
||||
{
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
UpdateCommand = new DelegateCommand<string>(async x => await UpdateAsync(x).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
private Task UpdateAsync(string startup) =>
|
||||
bool.TryParse(startup, out var isStartup)
|
||||
? Katteker.UserInterface.CheckForUpdateAsync(isStartup)
|
||||
: Task.FromResult(true);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user