Fun with MaterialDesignInXAML
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Katteker;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Prism.Commands;
|
||||
using Prism.Mvvm;
|
||||
@ -11,20 +12,41 @@ namespace Example
|
||||
[JetBrains.Annotations.UsedImplicitly]
|
||||
public class MainWindowViewModel : BindableBase, IDisposable
|
||||
{
|
||||
private bool _showRestartAppDialog;
|
||||
private UpdateManager _updateManager;
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
_updateManager = UpdateManager.Create();
|
||||
UpdateCommand = new DelegateCommand<string>(async x => await UpdateAsync(x).ConfigureAwait(false));
|
||||
RestartAppDialogCommand = new DelegateCommand<object>(RestartApp);
|
||||
}
|
||||
|
||||
private void RestartApp(object obj)
|
||||
{
|
||||
if (obj is bool restart && restart)
|
||||
{
|
||||
_updateManager.RestartApp();
|
||||
}
|
||||
|
||||
ShowRestartAppDialog = false;
|
||||
}
|
||||
|
||||
|
||||
private async Task UpdateAsync(string startup)
|
||||
{
|
||||
var silent = !bool.Parse(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);
|
||||
|
||||
var releases = (await _updateManager.CheckForUpdateAsync()).ToList();
|
||||
if (releases.Any())
|
||||
{
|
||||
MessageQueue.Enqueue("Update available", "Update now", ActionHandler);
|
||||
}
|
||||
else if (!silent)
|
||||
{
|
||||
MessageQueue.Enqueue("No Update available.", true);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -35,10 +57,27 @@ namespace Example
|
||||
}
|
||||
}
|
||||
|
||||
private async void ActionHandler()
|
||||
{
|
||||
if (await _updateManager.UpdateAppAsync().ConfigureAwait(false))
|
||||
{
|
||||
ShowRestartAppDialog = true;
|
||||
//manager.RestartApp();
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand UpdateCommand { get; }
|
||||
|
||||
public SnackbarMessageQueue MessageQueue { get; } = new SnackbarMessageQueue();
|
||||
|
||||
public bool ShowRestartAppDialog
|
||||
{
|
||||
get => _showRestartAppDialog;
|
||||
set => SetProperty(ref _showRestartAppDialog, value);
|
||||
}
|
||||
|
||||
public ICommand RestartAppDialogCommand { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
MessageQueue?.Dispose();
|
||||
|
Reference in New Issue
Block a user