Skip to content

Commit

Permalink
Updated org and added footer view and code for getting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tnunnink committed Mar 15, 2023
1 parent 8944fe9 commit 8380bf7
Show file tree
Hide file tree
Showing 16 changed files with 258 additions and 46 deletions.
48 changes: 44 additions & 4 deletions src/ioList/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using System.Windows;
using System;
using System.IO;
using System.Windows;
using ioList.ViewModels;
using MaterialDesignThemes.Wpf;
using Microsoft.Extensions.DependencyInjection;
using Squirrel;

namespace ioList
{
public partial class App : Application
public partial class App
{
public App()
{
Services = ConfigureServices();
InitializeComponent();
}

Expand All @@ -17,15 +23,49 @@ protected override void OnStartup(StartupEventArgs e)
onAppUninstall: OnAppUninstall,
onEveryRun: OnAppRun);
}

/// <summary>
/// Gets the current <see cref="App"/> instance in use
/// </summary>
public new static App Current => (App)Application.Current;

/// <summary>
/// Gets the <see cref="IServiceProvider"/> instance to resolve application services.
/// </summary>
public IServiceProvider Services { get; }

public readonly string InstallDirectory =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"ioList");

public const string RepositoryUrl = @"https://github.com/tnunnink/ioList";

public const string IssuesUrl = @"https://github.com/tnunnink/ioList/issues";

public const string PagesUrl = @"https://github.com/tnunnink/ioList/issues";

/// <summary>
/// Configures the services for the application.
/// </summary>
private static IServiceProvider ConfigureServices()
{
var services = new ServiceCollection();

services.AddSingleton<ISnackbarMessageQueue, SnackbarMessageQueue>();

services.AddTransient<ShellViewModel>();
services.AddTransient<FooterViewModel>();

return services.BuildServiceProvider();
}

private static void OnAppInstall(SemanticVersion version, IAppTools tools)
{
tools.CreateShortcutForThisExe(ShortcutLocation.StartMenu | ShortcutLocation.Desktop);
tools.CreateShortcutForThisExe(ShortcutLocation.StartMenu);
}

private static void OnAppUninstall(SemanticVersion version, IAppTools tools)
{
tools.RemoveShortcutForThisExe(ShortcutLocation.StartMenu | ShortcutLocation.Desktop);
tools.RemoveShortcutForThisExe(ShortcutLocation.StartMenu);
}

private static void OnAppRun(SemanticVersion version, IAppTools tools, bool firstRun)
Expand Down
15 changes: 15 additions & 0 deletions src/ioList/Shared/Converters.cs
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);
}
}
2 changes: 1 addition & 1 deletion src/ioList/Generator.cs → src/ioList/Shared/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using L5Sharp.Enums;
using L5Sharp.Extensions;

namespace ioList;
namespace ioList.Shared;

public class Generator
{
Expand Down
37 changes: 4 additions & 33 deletions src/ioList/Shell.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Window x:Class="ioList.Shell"
<Window x:Class="ioList.Views.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"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ioList="clr-namespace:ioList"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:views="clr-namespace:ioList.Views"
xmlns:viewModels="clr-namespace:ioList.ViewModels"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
Background="{DynamicResource MaterialDesignPaper}"
TextElement.FontWeight="Medium"
Expand All @@ -15,7 +15,7 @@
WindowStartupLocation="CenterOwner"
Style="{DynamicResource ShellStyle}"
Height="600" Width="640"
d:DataContext="{d:DesignInstance ioList:ShellViewModel, IsDesignTimeCreatable=True}"
d:DataContext="{d:DesignInstance viewModels:ShellViewModel, IsDesignTimeCreatable=True}"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
Expand Down Expand Up @@ -43,35 +43,6 @@
</md:TransitioningContent>
</md:Transitioner>

<StackPanel Grid.Row="1"
Orientation="Horizontal"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="10 0">
<Button Style="{StaticResource MaterialDesignToolButton}">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<md:PackIcon Kind="ArrowUpCircleOutline"
Height="20" Width="20"
Foreground="{DynamicResource PrimaryHueLightBrush}"/>
<TextBlock Text="Update to version 0.2.0"
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>
<views:FooterView Grid.Row="1"/>
</Grid>
</Window>
4 changes: 2 additions & 2 deletions src/ioList/Shell.xaml.cs
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();
}
}
}
103 changes: 103 additions & 0 deletions src/ioList/ViewModels/FooterViewModel.cs
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}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ioList.Shared;
using Ookii.Dialogs.Wpf;

namespace ioList
namespace ioList.ViewModels
{
public partial class ShellViewModel : ObservableValidator
{
Expand Down
3 changes: 2 additions & 1 deletion src/ioList/Views/CompleteView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:ioList="clr-namespace:ioList"
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 ioList:ShellViewModel, IsDesignTimeCreatable=True}"
d:DataContext="{d:DesignInstance viewModels:ShellViewModel, IsDesignTimeCreatable=True}"
mc:Ignorable="d">

<Border>
Expand Down
3 changes: 2 additions & 1 deletion src/ioList/Views/EntryView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:ioList="clr-namespace:ioList"
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 ioList:ShellViewModel, IsDesignTimeCreatable=True}"
d:DataContext="{d:DesignInstance viewModels:ShellViewModel, IsDesignTimeCreatable=True}"
mc:Ignorable="d">
<Border>
<Grid Margin="10">
Expand Down
3 changes: 2 additions & 1 deletion src/ioList/Views/ErrorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:ioList="clr-namespace:ioList"
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 ioList:ShellViewModel, IsDesignTimeCreatable=True}"
d:DataContext="{d:DesignInstance viewModels:ShellViewModel, IsDesignTimeCreatable=True}"
mc:Ignorable="d">

<Border>
Expand Down
60 changes: 60 additions & 0 deletions src/ioList/Views/FooterView.xaml
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>
Loading

0 comments on commit 8380bf7

Please sign in to comment.