Playing with Snackbar
This commit is contained in:
parent
ad14691479
commit
d39ffa2cb2
@ -132,6 +132,10 @@
|
||||
<Project>{07e2de31-80a0-43da-b307-1ca47cd930a1}</Project>
|
||||
<Name>Katteker.UserInterface</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Katteker\Katteker.csproj">
|
||||
<Project>{a45e1c59-ba9e-452c-a5e2-50de49d53e92}</Project>
|
||||
<Name>Katteker</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="nsis3-install.ico" />
|
||||
|
@ -31,8 +31,7 @@
|
||||
Margin="10,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
DockPanel.Dock="Bottom"
|
||||
IsActive="True"
|
||||
Message="Hello World" />
|
||||
MessageQueue="{Binding MessageQueue}" />
|
||||
<StackPanel>
|
||||
<Button
|
||||
Height="45"
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user