Files
velopack/samples/CSharpUno/UnoSample/MainViewModel.cs
Steve Bilogan 4d1388fb5f chore: update uno sample app with latest (#584)
* chore: update uno sample app with latest

* Cleaning up UnoSample to use SampleHelper

Updated the top level Directory.Build.targets to support samples with solutions and nested directories.
Added build scripts.

* Adding Uno sample to GHA

* Remove framework bootstrap

* Fixing mainExe name on non-windows

---------

Co-authored-by: Kevin Bost <kitokeboo@gmail.com>
2025-03-26 07:29:19 -07:00

66 lines
1.6 KiB
C#

using Velopack;
namespace UnoSample;
public partial class MainViewModel : ObservableObject
{
private readonly UpdateManager _updateManager;
public bool IsInstalled => _updateManager.IsInstalled;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(HasUpdate))]
private UpdateInfo? _latestUpdate;
public bool HasUpdate => LatestUpdate != null;
public string CurrentVersion => _updateManager.CurrentVersion?.ToFullString() ?? "";
[ObservableProperty]
private string? _status;
public MainViewModel()
{
var updateUrl = SampleHelper.GetReleasesDir(); // replace with your update path/url
_updateManager = new UpdateManager(updateUrl!);
}
[RelayCommand(CanExecute = nameof(IsInstalled))]
private async Task CheckForUpdates()
{
if (_updateManager.IsInstalled)
{
try
{
Status = "Checking for updates...";
LatestUpdate = await _updateManager.CheckForUpdatesAsync();
Status = LatestUpdate is null ? "No updates available" : $"{LatestUpdate.TargetFullRelease.Version} - Update available";
}
catch (Exception ex)
{
Status = ex.Message;
}
}
}
[RelayCommand(CanExecute = nameof(IsInstalled))]
private async Task DownloadUpdates()
{
if (_updateManager.IsInstalled && LatestUpdate is { } latestUpdate)
{
try
{
Status = $"Downloading {0:p}";
await _updateManager.DownloadUpdatesAsync(latestUpdate, progress => Status = $"Downloading {progress / 100.0:p}");
Status = "Restarting...";
_updateManager.ApplyUpdatesAndRestart(latestUpdate.TargetFullRelease);
}
catch (Exception ex)
{
Status = ex.Message;
}
}
}
}