-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated org and added footer view and code for getting updates
- Loading branch information
Showing
16 changed files
with
258 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Windows; | ||
using System.Windows.Data; | ||
using LambdaConverters; | ||
|
||
namespace ioList.Shared | ||
{ | ||
public static class Converters | ||
{ | ||
public static readonly IValueConverter VisibleIfTrue = | ||
ValueConverter.Create<bool, Visibility>(e => e.Value ? Visibility.Visible : Visibility.Collapsed); | ||
|
||
public static readonly IValueConverter VisibleIfFalse = | ||
ValueConverter.Create<bool, Visibility>(e => e.Value ? Visibility.Collapsed : Visibility.Visible); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
namespace ioList | ||
namespace ioList.Views | ||
{ | ||
public partial class Shell | ||
{ | ||
public Shell() | ||
{ | ||
InitializeComponent(); | ||
DataContext = new ShellViewModel(); | ||
DataContext = new ViewModels.ShellViewModel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using MaterialDesignThemes.Wpf; | ||
using Squirrel; | ||
using Squirrel.Sources; | ||
|
||
namespace ioList.ViewModels | ||
{ | ||
public partial class FooterViewModel : ObservableObject | ||
{ | ||
public FooterViewModel(ISnackbarMessageQueue messageQueue) | ||
{ | ||
_messageQueue = messageQueue; | ||
UpdateAvailable = false; | ||
LoadTask = CheckForUpdates(); | ||
} | ||
|
||
[ObservableProperty] private ISnackbarMessageQueue _messageQueue; | ||
|
||
#region PropertyRegion | ||
|
||
[ObservableProperty] private string _versionText; | ||
|
||
[ObservableProperty] private string _updateText; | ||
|
||
[ObservableProperty] private bool _updateAvailable; | ||
|
||
#endregion | ||
|
||
private readonly TaskNotifier _loadTask; | ||
|
||
private Task LoadTask | ||
{ | ||
get => _loadTask; | ||
init => SetPropertyAndNotifyOnCompletion(ref _loadTask, value); | ||
} | ||
|
||
[RelayCommand] | ||
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; | ||
|
||
if (!UpdateAvailable) | ||
{ | ||
MessageQueue.Enqueue( | ||
"You have the latest updates! We will notify when new releases ar published. Enjoy!"); | ||
return; | ||
} | ||
|
||
var latest = updateInfo.ReleasesToApply.MaxBy(r => r.Version)?.Version; | ||
UpdateText = $"Update to version {latest}"; | ||
MessageQueue.Enqueue("New updates are available! Click update to start installing."); | ||
} | ||
catch (Exception e) | ||
{ | ||
MessageQueue.Enqueue("Unable to contact Github to find new updates..."); | ||
} | ||
} | ||
|
||
[RelayCommand(CanExecute = nameof(CanExecuteUpdateCommand))] | ||
private async Task PerformUpdate() | ||
{ | ||
try | ||
{ | ||
using var manager = new UpdateManager(new GithubSource("https://github.com/tnunnink/ioList", "", 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) | ||
{ | ||
MessageQueue.Enqueue("Failed performing application update. You hate to see it..."); | ||
} | ||
} | ||
|
||
private bool CanExecuteUpdateCommand() => UpdateAvailable; | ||
|
||
[RelayCommand] | ||
private void LaunchSite(string url) | ||
{ | ||
try | ||
{ | ||
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true }); | ||
} | ||
catch (Exception e) | ||
{ | ||
MessageQueue.Enqueue($"Unable to open site {url}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<UserControl x:Class="ioList.Views.FooterView" | ||
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" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes" | ||
xmlns:ioList="clr-namespace:ioList" | ||
xmlns:shared="clr-namespace:ioList.Shared" | ||
xmlns:viewModels="clr-namespace:ioList.ViewModels" | ||
TextElement.Foreground="{DynamicResource MaterialDesignBody}" | ||
Background="{DynamicResource MaterialDesignPaper}" | ||
TextElement.FontWeight="Medium" | ||
TextElement.FontSize="14" | ||
FontFamily="{md:MaterialDesignFont}" | ||
d:DataContext="{d:DesignInstance viewModels:FooterViewModel, IsDesignTimeCreatable=True}" | ||
mc:Ignorable="d" | ||
d:DesignWidth="1000"> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="30" /> | ||
</Grid.RowDefinitions> | ||
|
||
<md:Snackbar Grid.Row="0" MessageQueue="{Binding MessageQueue}" /> | ||
|
||
<StackPanel Grid.Row="1" | ||
Orientation="Horizontal" | ||
HorizontalAlignment="Left" | ||
VerticalAlignment="Center" | ||
Margin="10 0"> | ||
<Button Style="{StaticResource MaterialDesignToolButton}" | ||
Command="{Binding PerformUpdateCommand}" | ||
Visibility="{Binding UpdateAvailable, Converter={x:Static shared:Converters.VisibleIfTrue}}"> | ||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"> | ||
<md:PackIcon Kind="ArrowUpCircleOutline" | ||
Height="20" Width="20" | ||
Foreground="{DynamicResource PrimaryHueLightBrush}"/> | ||
<TextBlock Text="{Binding UpdateText}" | ||
VerticalAlignment="Center" | ||
Foreground="{DynamicResource PrimaryHueLightBrush}" | ||
FontWeight="Regular" FontSize="12" | ||
Margin="5 0 0 0"/> | ||
</StackPanel> | ||
|
||
</Button> | ||
</StackPanel> | ||
|
||
<StackPanel Grid.Row="1" | ||
Orientation="Horizontal" | ||
HorizontalAlignment="Right" | ||
VerticalAlignment="Center" | ||
Margin="10 0"> | ||
<Button Style="{StaticResource MaterialDesignToolButton}"> | ||
<md:PackIcon Kind="Cog" | ||
Height="20" Width="20"/> | ||
</Button> | ||
</StackPanel> | ||
</Grid> | ||
</UserControl> |
Oops, something went wrong.