Skip to content

Commit

Permalink
adding update functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tnunnink committed Mar 16, 2023
1 parent 8380bf7 commit 1d6f510
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 33 deletions.
2 changes: 1 addition & 1 deletion releases/RELEASES
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BF8A01C736C91B930B980A3CA948D55FBD372C60 ioList-0.1.0-full.nupkg 69901165
3139E55D9B186246166477D14A0A4B0011C7E6BD ioList-0.1.0-full.nupkg 65203427
Binary file modified releases/Setup.exe
Binary file not shown.
Binary file modified releases/ioList-0.1.0-full.nupkg
Binary file not shown.
6 changes: 6 additions & 0 deletions src/.idea/.idea.ioList/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/ioList/Shell.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="ioList.Views.Shell"
<Window x:Class="ioList.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand Down
7 changes: 5 additions & 2 deletions src/ioList/Shell.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
namespace ioList.Views
using ioList.ViewModels;
using Microsoft.Extensions.DependencyInjection;

namespace ioList
{
public partial class Shell
{
public Shell()
{
InitializeComponent();
DataContext = new ViewModels.ShellViewModel();
DataContext = App.Current.Services.GetService<ShellViewModel>();
}
}
}
28 changes: 11 additions & 17 deletions src/ioList/ViewModels/FooterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace ioList.ViewModels
{
public partial class FooterViewModel : ObservableObject
{
private readonly TaskNotifier _loadTask;

public FooterViewModel(ISnackbarMessageQueue messageQueue)
{
_messageQueue = messageQueue;
Expand All @@ -21,6 +23,7 @@ public FooterViewModel(ISnackbarMessageQueue messageQueue)

[ObservableProperty] private ISnackbarMessageQueue _messageQueue;


#region PropertyRegion

[ObservableProperty] private string _versionText;
Expand All @@ -31,7 +34,6 @@ public FooterViewModel(ISnackbarMessageQueue messageQueue)

#endregion

private readonly TaskNotifier _loadTask;

private Task LoadTask
{
Expand All @@ -44,23 +46,16 @@ private async Task CheckForUpdates()
{
try
{
using var manager = new UpdateManager(new GithubSource("https://github.com/tnunnink/ioList", "", false));
var updateInfo = await manager.CheckForUpdate();

VersionText = $"ioList {updateInfo.CurrentlyInstalledVersion.Version}";

UpdateAvailable = updateInfo.ReleasesToApply.Count > 0;
using var manager = new UpdateManager(new GithubSource(App.RepositoryUrl, string.Empty, false));

if (!UpdateAvailable)
{
MessageQueue.Enqueue(
"You have the latest updates! We will notify when new releases ar published. Enjoy!");
return;
}
if (!manager.IsInstalledApp) return;

var updates = await manager.CheckForUpdate();
UpdateAvailable = updates.ReleasesToApply.Count > 0;

var latest = updateInfo.ReleasesToApply.MaxBy(r => r.Version)?.Version;
var latest = updates.ReleasesToApply.MaxBy(r => r.Version)?.Version;
UpdateText = $"Update to version {latest}";
MessageQueue.Enqueue("New updates are available! Click update to start installing.");
MessageQueue.Enqueue("New updates are available! Click update button to start installing.");
}
catch (Exception e)
{
Expand All @@ -73,10 +68,9 @@ private async Task PerformUpdate()
{
try
{
using var manager = new UpdateManager(new GithubSource("https://github.com/tnunnink/ioList", "", false));
using var manager = new UpdateManager(new GithubSource(App.RepositoryUrl, string.Empty, false));
var release = await manager.UpdateApp();
MessageQueue.Enqueue($"Update complete. You are running version {release.Version}. Enjoy!");
VersionText = $"ioList {release.Version}";
UpdateAvailable = false;
}
catch (Exception e)
Expand Down
38 changes: 32 additions & 6 deletions src/ioList/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@
using CommunityToolkit.Mvvm.Input;
using ioList.Shared;
using Ookii.Dialogs.Wpf;
using Squirrel;
using Squirrel.Sources;

namespace ioList.ViewModels
{
public partial class ShellViewModel : ObservableValidator
{
public ShellViewModel()
{
GetVersion();
}

[ObservableProperty]
private string _version;

[ObservableProperty]
private int _selectedIndex;

Expand All @@ -20,7 +30,7 @@ public partial class ShellViewModel : ObservableValidator
[NotifyDataErrorInfo]
[Required]
private string _sourceFile = string.Empty;

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(GenerateCommand))]
[NotifyDataErrorInfo]
Expand All @@ -36,7 +46,7 @@ public partial class ShellViewModel : ObservableValidator

[ObservableProperty]
private string _errorMessage;

[RelayCommand]
private void SelectSource()
{
Expand Down Expand Up @@ -73,7 +83,7 @@ private void SelectLocation()

DestinationLocation = folder;
}

[RelayCommand]
private void OpenInExplorer()
{
Expand All @@ -84,10 +94,10 @@ private void OpenInExplorer()

SelectedIndex = 0;
}

[RelayCommand]
private void TryAgain() => SelectedIndex = 0;

[RelayCommand]
private void ReportIssue()
{
Expand Down Expand Up @@ -120,7 +130,7 @@ private bool CanGenerate() => !string.IsNullOrWhiteSpace(SourceFile)
&& !string.IsNullOrWhiteSpace(DestinationName)
&& !string.IsNullOrWhiteSpace(DestinationLocation)
&& !HasErrors;

public static ValidationResult ValidateName(string value, ValidationContext context)
{
var vm = (ShellViewModel)context.ObjectInstance;
Expand All @@ -134,5 +144,21 @@ public static ValidationResult ValidateName(string value, ValidationContext cont
? new ValidationResult($"The file name {value} already exists in the specified folder.")
: ValidationResult.Success;
}

private void GetVersion()
{
try
{
using var manager = new UpdateManager(new GithubSource(App.RepositoryUrl, string.Empty, false));
var installedVersion = manager.CurrentlyInstalledVersion();
Version = installedVersion is not null ? installedVersion.Version.ToString() : string.Empty;

}
catch (Exception e)
{
//todo log
Console.WriteLine(e);
}
}
}
}
2 changes: 1 addition & 1 deletion src/ioList/Views/StartupView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
FontWeight="SemiBold"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
<TextBlock Text="0.1.2"
<TextBlock Text="{Binding Version}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Foreground="#7186A1" />
Expand Down
6 changes: 2 additions & 4 deletions src/ioList/ioList.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<AssemblyVersion>0.1.1</AssemblyVersion>
<FileVersion>0.1.1</FileVersion>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<AssemblyVersion>0.1.0</AssemblyVersion>
<FileVersion>0.1.0</FileVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

Expand All @@ -26,7 +25,6 @@

<PropertyGroup>
<NugetTools>$(PkgNuGet_CommandLine)\tools</NugetTools>
<!--<SquirrelTools>$(Pkgsquirrel_windows)\tools</SquirrelTools>-->
<NuspecFile>$(SolutionDir)ioList\ioList.nuspec</NuspecFile>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/ioList/ioList.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>ioList</id>
<version>0.1.0.0</version>
<version>0.1.1.0</version>
<title>ioList</title>
<authors>Timothy Nunnink</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down

0 comments on commit 1d6f510

Please sign in to comment.